本文整理汇总了TypeScript中lodash.mergeWith函数的典型用法代码示例。如果您正苦于以下问题:TypeScript mergeWith函数的具体用法?TypeScript mergeWith怎么用?TypeScript mergeWith使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了mergeWith函数的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: glob
glob(join(config.APP_SRC, '*', 'client', 'angular.json'), {}, (err2: Error, packageFiles: string[]) => {
for (const filename of packageFiles) {
const configuration = JSON.parse(readFileSync(filename, 'utf-8'));
content = mergeWith(content, configuration, merger);
}
writeFileSync('angular.json', JSON.stringify(content, null, 2));
});
示例2: immutableMergeWithConcattingArrays
export function immutableMergeWithConcattingArrays(destObject: object, ...sources: object[]): object {
const clonedDestObject = cloneDeep(destObject);
return mergeWith(clonedDestObject, ...sources, (objValue, srcValue) => {
if (Array.isArray(objValue) && Array.isArray(srcValue)) {
return objValue.concat(srcValue);
}
});
}
示例3: getBabelConfig
export function getBabelConfig (babel) {
if (!babelConfig) {
babelConfig = mergeWith({}, defaultBabelConfig, babel, (objValue, srcValue) => {
if (Array.isArray(objValue)) {
return Array.from(new Set(srcValue.concat(objValue)))
}
})
}
return babelConfig
}
示例4:
function asPlainObjectDeep<T>(origianl: T) {
const removePrototype = (srcVal: any, objVal: any) => {
if (ng1.isObject(objVal) && !ng1.isArray(objVal)) {
return _.toPlainObject(objVal);
} else {
return objVal;
}
};
return _.mergeWith<T>(Object.create(null), origianl, removePrototype);
}
示例5: String
src.forEach((v: webpack.Rule, _i: number) => {
const existingTest = (obj as webpack.Rule[]).find(
rule => String(rule.test) === String(v.test)
);
if (existingTest) {
lodash.mergeWith(existingTest, v, defaultMerger);
} else {
obj.push(v);
}
});
示例6: function
const Config = function(): ConfigType {
let config: ConfigType = {
maxPoolSize: 50,
port: 3000,
dbHost: process.env.DB_HOST || '127.0.0.1',
dbName: process.env.DB_NAME || 'bitcore',
dbPort: process.env.DB_PORT || '27017',
dbUser: process.env.DB_USER || '',
dbPass: process.env.DB_PASS || '',
numWorkers: cpus().length,
chains: {},
services: {
api: {
rateLimiter: {
disabled: false,
whitelist: ['::ffff:127.0.0.1', '::1']
},
wallets: {
allowCreationBeforeCompleteSync: false,
allowUnauthenticatedCalls: true
}
},
event: {
onlyWalletEvents: false
},
p2p: {},
socket: {},
storage: {}
}
};
let foundConfig = findConfig();
const mergeCopyArray = (objVal, srcVal) => (objVal instanceof Array ? srcVal : undefined);
config = _.mergeWith(config, foundConfig, mergeCopyArray);
if (!Object.keys(config.chains).length) {
Object.assign(config.chains, {
BTC: {
mainnet: {
chainSource: 'p2p',
trustedPeers: [{ host: '127.0.0.1', port: 8333 }],
rpc: {
host: '127.0.0.1',
port: 8332,
username: 'bitcoin',
password: 'bitcoin'
}
}
}
});
}
config = setTrustedPeers(config);
return config;
};
示例7: mergeWith
const recursiveMerge = (src, ...args) => {
return mergeWith(src, ...args, (value, srcValue, key, obj, source) => {
const typeValue = typeof value
const typeSrcValue = typeof srcValue
if (typeValue !== typeSrcValue) return
if (Array.isArray(value) && Array.isArray(srcValue)) {
return value.concat(srcValue)
}
if (typeValue === 'object') {
return recursiveMerge(value, srcValue)
}
})
}
示例8: mergeAliases
export function mergeAliases(aliases: ModuleAliases[]): { [moduleCode: string]: ModuleCode[] } {
// Returning undefined causes mergeWith to use the original merge
/* eslint-disable consistent-return */
// @ts-ignore mergeWith allows multiple objects to be merged, but the libdef doesn't
const merged: ModuleAliases = mergeWith(...aliases, (src, dest) => {
if (src && dest) return union(src, dest);
});
/* eslint-enable */
// Convert the set to an array to make it easier to output since JSON doesn't
// encode Sets by default
return mapValues(merged, (set) => Array.from(set));
}
示例9: resolveAllOf
function resolveAllOf(inputSpec: any): any {
if (inputSpec && typeof inputSpec === 'object'
&& Object.keys(inputSpec).length > 0
) {
if (inputSpec.allOf) {
const allOf = inputSpec.allOf;
delete inputSpec.allOf;
const nested = _.mergeWith({}, ...allOf, customizer);
inputSpec = _.defaultsDeep(inputSpec, nested, customizer);
}
Object.keys(inputSpec).forEach((key: string) => {
inputSpec[key] = resolveAllOf(inputSpec[key]);
});
}
return inputSpec;
}
示例10: getAlterationCountsForCancerTypesForAllGenes
export function getAlterationCountsForCancerTypesForAllGenes(alterationsByGeneBySampleKey:{ [geneName:string]: {[sampleId: string]: ExtendedAlteration[]} },
samplesExtendedWithClinicalData:ExtendedSample[],
groupByProperty: keyof ExtendedSample){
const samplesByCancerType = _.groupBy(samplesExtendedWithClinicalData,(sample:ExtendedSample)=>{
return sample[groupByProperty];
});
const flattened = _.flatMap(alterationsByGeneBySampleKey, (map) => map);
// NEED TO FLATTEN and then merge this to get all alteration by sampleId
function customizer(objValue: any, srcValue: any) {
if (_.isArray(objValue)) {
return objValue.concat(srcValue);
}
}
const merged: { [uniqueSampleKey: string]: ExtendedAlteration[] } =
(_.mergeWith({}, ...flattened, customizer) as { [uniqueSampleKey: string]: ExtendedAlteration[] });
return countAlterationOccurences(samplesByCancerType, merged);
}