本文整理匯總了TypeScript中deepmerge類的典型用法代碼示例。如果您正苦於以下問題:TypeScript deepmerge類的具體用法?TypeScript deepmerge怎麽用?TypeScript deepmerge使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
在下文中一共展示了deepmerge類的6個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。
示例1: loadTsconfig
export function loadTsconfig(
configFilePath: string,
existsSync: (path: string) => boolean = fs.existsSync,
readFileSync: (filename: string) => string = (filename: string) =>
fs.readFileSync(filename, "utf8")
): Tsconfig | undefined {
if (!existsSync(configFilePath)) {
return undefined;
}
const configString = readFileSync(configFilePath);
const cleanedJson = StripBom(StripJsonComments(configString));
const config: Tsconfig = JSON.parse(cleanedJson);
let extendedConfig = config.extends;
if (extendedConfig) {
if (
typeof extendedConfig === "string" &&
extendedConfig.indexOf(".json") === -1
) {
extendedConfig += ".json";
}
const currentDir = path.dirname(configFilePath);
const base =
loadTsconfig(
path.join(currentDir, extendedConfig),
existsSync,
readFileSync
) || {};
// baseUrl should be interpreted as relative to the base tsconfig,
// but we need to update it so it is relative to the original tsconfig being loaded
if (base && base.compilerOptions && base.compilerOptions.baseUrl) {
const extendsDir = path.dirname(extendedConfig);
base.compilerOptions.baseUrl = path.join(
extendsDir,
base.compilerOptions.baseUrl
);
}
return deepmerge(base, config);
}
return config;
}
示例2:
import * as deepmerge from "deepmerge";
const x = { foo: { bar: 3 },
array: [ { does: 'work', too: [ 1, 2, 3 ] } ] };
const y = { foo: { baz: 4 },
quux: 5,
array: [ { does: 'work', too: [ 4, 5, 6 ] }, { really: 'yes' } ] };
const expected = { foo: { bar: 3, baz: 4 },
array: [ { does: 'work', too: [ 1, 2, 3, 4, 5, 6 ] }, { really: 'yes' } ],
quux: 5 };
const result = deepmerge<any>(x, y);
示例3: deepmerge
import * as deepmerge from "deepmerge";
const x = {
foo: { bar: 3 },
array: [{ does: 'work', too: [1, 2, 3] }]
};
const y = {
foo: { baz: 4 },
quux: 5,
array: [{ does: 'work', too: [4, 5, 6] }, { really: 'yes' }]
};
const expected = {
foo: { bar: 3, baz: 4 },
array: [{ does: 'work', too: [1, 2, 3, 4, 5, 6] }, { really: 'yes' }],
quux: 5
};
const result = deepmerge(x, y);
const anyResult = deepmerge<any>(x, y);
function reverseConcat(dest: number[], src: number[]) {
return src.concat(dest);
}
const withOptions = deepmerge(x, y, {
clone: false,
arrayMerge: reverseConcat
});
示例4:
import * as deepmerge from "deepmerge";
const x = { foo: { bar: 3 },
array: [ { does: 'work', too: [ 1, 2, 3 ] } ] }
const y = { foo: { baz: 4 },
quux: 5,
array: [ { does: 'work', too: [ 4, 5, 6 ] }, { really: 'yes' } ] }
const expected = { foo: { bar: 3, baz: 4 },
array: [ { does: 'work', too: [ 1, 2, 3, 4, 5, 6 ] }, { really: 'yes' } ],
quux: 5 }
const result = deepmerge<Object>(x, y);
示例5: expect
.then((dataStr) => {
// Inflate to real object and re-use previous test assertions.
const data = JSON.parse(dataStr);
expect(data).to.have.keys("meta", "assets");
expect(data).to.have.property("meta").that.eql(merge(BASE_SCOPED_DATA.meta, {
depended: {
num: 5,
},
files: {
num: 7,
},
installed: {
num: 4,
},
packages: {
num: 2,
},
resolved: {
num: 4,
},
}));
let expectProp;
expectProp = expect(data).to.have.nested.property(
"assets.bundle\\.js.packages.@scope/foo.1\\.1\\.1.node_modules/@scope/foo",
);
expectProp.to.have.property("skews").that.has.length(2);
expectProp.to.have.property("modules").that.has.length(2);
expectProp = expect(data).to.have.nested.property(
"assets.bundle\\.js.packages.@scope/foo.2\\.2\\.2.node_modules/uses-foo/node_modules/@scope/foo",
);
expectProp.to.have.property("skews").that.has.length(1);
expectProp.to.have.property("modules").that.has.length(1);
expectProp = expect(data).to.have.nested.property(
"assets.bundle\\.js.packages.foo.3\\.3\\.3.node_modules/unscoped-foo/node_modules/foo",
);
expectProp.to.have.property("skews").that.has.length(1);
expectProp.to.have.property("modules").that.has.length(2);
expectProp = expect(data).to.have.nested.property(
"assets.bundle\\.js.packages.foo.4\\.3\\.3.node_modules/unscoped-foo/" +
"node_modules/deeper-unscoped/node_modules/foo",
);
expectProp.to.have.property("skews").that.has.length(1);
expectProp.to.have.property("modules").that.has.length(2);
});
示例6: merge
num: 0,
},
};
export const EMPTY_VERSIONS_DATA: IVersionsData = {
assets: {},
meta: {
...EMPTY_VERSIONS_META,
commonRoot: null,
packageRoots: [],
},
};
const BASE_DUPS_CJS_DATA = merge(EMPTY_VERSIONS_DATA, {
meta: {
commonRoot: resolve(__dirname, "../../fixtures/duplicates-cjs"),
packageRoots: [resolve(__dirname, "../../fixtures/duplicates-cjs")],
},
});
const BASE_SCOPED_DATA = merge(EMPTY_VERSIONS_DATA, {
meta: {
commonRoot: resolve(__dirname, "../../fixtures/scoped"),
packageRoots: [resolve(__dirname, "../../fixtures/scoped")],
},
});
// Keyed off `scenario`. Remap chunk names.
const PATCHED_ASSETS = {
"multiple-chunks": {
"0.js": "bar.js",
"1.js": "different-foo.js",