本文整理汇总了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;
}
开发者ID:christoffer,项目名称:tsconfig-paths,代码行数:45,代码来源:tsconfig-loader.ts
示例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);
开发者ID:EmmaRamirez,项目名称:DefinitelyTyped,代码行数:13,代码来源:deepmerge-tests.ts
示例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
});
开发者ID:AbraaoAlves,项目名称:DefinitelyTyped,代码行数:29,代码来源:deepmerge-tests.ts
示例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);
开发者ID:ArtemZag,项目名称:DefinitelyTyped,代码行数:13,代码来源:deepmerge-tests.ts
示例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);
});
开发者ID:FormidableLabs,项目名称:inspectpack,代码行数:50,代码来源:versions.spec.ts
示例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",
开发者ID:FormidableLabs,项目名称:inspectpack,代码行数:32,代码来源:versions.spec.ts
注:本文中的deepmerge类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论