本文整理汇总了TypeScript中lodash.defaultsDeep函数的典型用法代码示例。如果您正苦于以下问题:TypeScript defaultsDeep函数的具体用法?TypeScript defaultsDeep怎么用?TypeScript defaultsDeep使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了defaultsDeep函数的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: mockRequest
// Exports
export default function mockRequest(
requestProperties?: Partial<Koa.Request & { body: any }>,
responseProperties?: Partial<Koa.Response>,
): { request: Koa.Request & { body?: any }; response: Koa.Response } {
const app = new Koa();
const req = {};
const res = {};
const request = defaultsDeep({ req, res }, requestProperties, {
app,
ctx: {},
header: {
'cache-control': 'no-cache',
},
query: {},
});
const response = defaultsDeep({ req, res }, responseProperties, {
ctx: {},
status: 200,
});
// Add references
Object.defineProperty(request, 'response', { get: () => response });
Object.defineProperty(request.ctx, 'response', { get: () => response });
Object.defineProperty(request.ctx, 'request', { get: () => request });
Object.defineProperty(response, 'request', { get: () => request });
Object.defineProperty(response.ctx, 'request', { get: () => request });
Object.defineProperty(response.ctx, 'response', { get: () => response });
// Return mocked request response
return { request, response };
}
示例2: getSettingsFromFile
async function getSettingsFromFile(log: ToolingLog, path: string, settingOverrides: any) {
const configModule = require(path); // eslint-disable-line @typescript-eslint/no-var-requires
const configProvider = configModule.__esModule ? configModule.default : configModule;
if (!cache.has(configProvider)) {
log.debug('Loading config file from %j', path);
cache.set(
configProvider,
configProvider({
log,
async readConfigFile(p: string, o: any) {
return new Config({
settings: await getSettingsFromFile(log, p, o),
primary: false,
path: p,
});
},
})
);
}
const settingsWithDefaults = defaultsDeep({}, settingOverrides, await cache.get(configProvider)!);
const logDeprecation = (error: string | Error) => log.error(error);
return transformDeprecations(settingsWithDefaults, logDeprecation);
}
示例3: createRootWithSettings
export function createRootWithSettings(
settings: Record<string, any>,
cliArgs: Partial<CliArgs> = {}
) {
const env = Env.createDefault({
configs: [],
cliArgs: {
dev: false,
open: false,
quiet: false,
silent: false,
watch: false,
repl: false,
basePath: false,
optimize: false,
...cliArgs,
},
isDevClusterMaster: false,
});
return new Root(
new BehaviorSubject(
new LegacyObjectToConfigAdapter(defaultsDeep({}, settings, DEFAULTS_SETTINGS))
),
env
);
}
示例4: savePrimitiveValuesToLocalStorage
//////////////////////////////////////////////////////////////////////////////////
// DEPRECATED
// DEPRECATED
// NOT RECOMMENDED TO USE
savePrimitiveValuesToLocalStorage(component: Object, ignores?: Object[]): void {
let obj = {};
let objGlobal = {};
Object.keys(component).forEach(key => {
if (key.includes('_global')) {
objGlobal[key] = component[key];
} else if (typeof component[key] === 'object') {
const ctorName = component[key].constructor.name;
const ignorable = ignores && ignores.length > 0 ? ignores.some(ignore => ctorName === ignore.constructor.name) : false;
if (!ignorable) {
obj[key] = component[key];
}
} else {
obj[key] = component[key];
}
});
try {
const key = LOCAL_STORAGE_KEY + '-' + component.constructor.name;
window.localStorage.setItem(key, JSON.stringify(obj));
} catch (err) {
console.error(err);
}
try {
let ls = window.localStorage.getItem(GLOBAL_LOCAL_STORAGE_KEY);
ls = ls ? JSON.parse(ls) : {};
objGlobal = lodash.defaultsDeep(objGlobal, ls);
window.localStorage.setItem(GLOBAL_LOCAL_STORAGE_KEY, JSON.stringify(objGlobal));
} catch (err) {
console.error(err);
}
}
示例5: constructor
constructor(model) {
this.events = new Emitter();
// copy properties from persisted model
for (const property in model) {
this[property] = model[property];
}
// defaults
_.defaultsDeep(this, _.cloneDeep(defaults));
}
示例6: defaultsDeep
initializationMethod: (command: IRedBlackCommand) => {
defaultsDeep(command, {
rollback: {
onFailure: false,
},
maxRemainingAsgs: !command.strategy ? 2 : command.maxRemainingAsgs,
delayBeforeDisableSec: 0,
delayBeforeScaleDownSec: 0,
scaleDown: false,
});
},
示例7: setRouteDefaults
export function setRouteDefaults(route: RouteConfig, specific?: Partial<RouteConfig>) {
route = _.defaultsDeep(specific, defaultConfig, route);
if (!route.title) {
route.title = typeof route.route === "string"
? _.startCase(route.route)
: _.startCase(route.route[1]);
}
return route;
}
示例8: constructor
constructor(model) {
this.events = new Emitter();
// copy properties from persisted model
for (const property in model) {
this[property] = model[property];
}
// defaults
_.defaultsDeep(this, _.cloneDeep(defaults));
// queries must have refId
this.ensureQueryIds();
}
示例9: constructor
constructor(model: any) {
this.events = new Emitter();
// copy properties from persisted model
for (const property in model) {
(this as any)[property] = model[property];
}
// defaults
_.defaultsDeep(this, _.cloneDeep(defaults));
// queries must have refId
this.ensureQueryIds();
this.restoreInfintyForThresholds();
}
示例10: 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;
}