本文整理汇总了TypeScript中flat.unflatten函数的典型用法代码示例。如果您正苦于以下问题:TypeScript unflatten函数的具体用法?TypeScript unflatten怎么用?TypeScript unflatten使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了unflatten函数的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: createConfig
/**
* @description Create configuration
*
* @param {string[]} argv command-line arguments
* @returns {object} configuration object
*/
function createConfig(rawArgv: string[]) {
const config = new nconf.Provider(),
parsedArgv = flat.unflatten(minimist(rawArgv), {delimiter: ':'}),
envWhitelist = _(process.env)
.keys()
.filter(function(key: string) {
return ENV_DELIMITER_REGEX.test(key) && !/^npm_config/.test(key);
})
.valueOf()
.concat(['loglevel']);
config.add('argv', {type: 'literal', store: parsedArgv});
config.env({
separator: ENV_DELIMITER,
whitelist: envWhitelist
});
return function get(key: string, defaultValue?: any): any {
var result = coerceValues(config.get(key));
if (_.isUndefined(result)) {
result = defaultValue;
}
return result;
};
}
示例2: writeTranslations
async function writeTranslations(
flatMissingTranslations: TranslationCache,
basePath: string = '../src/Translation/locales'
) {
const mainTranslations = await new Translation().fetch(DEFAULT_LOCALE)
const availableLocales = await getAvailableLocales()
const flatMainTranslations = flat.flatten<TranslationData, TranslationData>(
mainTranslations
)
for (const locale of availableLocales) {
const localePath = path.resolve(__dirname, `${basePath}/${locale}.json`)
const flatCurrentTranslations = flatAndRemoveObsoleteKeys(
require(localePath),
flatMainTranslations
)
let updatedTranslations = Object.assign(
{},
flatCurrentTranslations,
flatMissingTranslations[locale]
)
updatedTranslations = flat.unflatten(updatedTranslations)
await utils.promisify(fs.writeFile)(
localePath,
JSON.stringify(updatedTranslations, null, 2),
'utf8'
)
}
}
示例3:
result = flatten<Target, Result>(target);
result = flatten<Target, Result>(target, options);
}
namespace TestUnflatten {
let options: {
delimiter?: string;
object?: boolean;
overwrite?: boolean;
};
type Target = {
'a.b': number;
'c.0.0': boolean;
};
let target: Target;
type Result = {
a: {
b: number;
},
c: boolean[][];
};
let result: Result;
result = unflatten<Target, Result>(target);
result = unflatten<Target, Result>(target, options);
}