Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
raw = locales.reduce((a: string[], e: string): string[] => {
const tmp = e.split(TAG_SEP);
return a.concat(tmp);
}, []);
}
const result: Entry[] = [];
const len = raw.length;
for (let i = 0; i < len; i++) {
const id = raw[i].trim();
const tag = parseLanguageTag(id);
// Preserve 'und' undefined locale. If we resolve it, adding
// likely subtags will expand it to 'en-Latn-US'.
if (tag.hasLanguage() || tag.hasScript() || tag.hasRegion()) {
result.push(new Entry(id, LanguageResolver.resolve(tag)));
} else {
// Preserve undefined core fields, but include input's extensions
result.push(new Entry(id, new LanguageTag(
undefined, undefined, undefined, undefined, tag.extensions(), tag.privateUse()
)));
}
}
return result;
};
export const languageBundle = (tag: string, config?: SchemaConfig): Bundle => {
const locale = LanguageResolver.resolve(tag);
const language = locale.language();
let spec: PackSpec | undefined;
let key = tag;
if (config !== undefined) {
const raw = JSON.stringify(config);
const hash = createHash('sha256').update(raw).update(VERSION).digest('hex');
spec = { hash, config: raw };
key = `${hash}-${pkg.version}-${tag}`;
}
let bundle = bundleCache.get(key);
if (bundle === undefined) {
const pack = loadPack(language, spec);
bundle = pack.get(locale);
bundleCache.set(key, bundle);
}
export const customPack = (tag: string, config: SchemaConfig): string => {
const locale = LanguageResolver.resolve(tag);
const language = locale.language();
const json = JSON.stringify(config);
const hash = createHash('sha256').update(json).update(VERSION).digest('hex');
return buildPack(language, { hash, config: json });
};
allLocales = availableLocalesRaw.split('|').map(id => {
const tag = LanguageResolver.resolve(id);
return { id, tag } as Locale;
});
}
paradigmLocaleMap = paradigmLocales.reduce((o: ParadigmMap, k: string, i: number) => {
const c = LanguageResolver.resolve(k).compact();
o[c] = i;
return o;
}, {});
};