Improved splitBufferBundle with early return

This commit is contained in:
Alexander Cerutti
2019-12-10 22:10:45 +01:00
parent 33e0f43f66
commit f642ddc444

View File

@@ -90,19 +90,18 @@ export function generateStringFile(lang: { [index: string]: string }): Buffer {
*/ */
export function splitBufferBundle(origin: Object): [PartitionedBundle["l10nBundle"], PartitionedBundle["bundle"]] { export function splitBufferBundle(origin: Object): [PartitionedBundle["l10nBundle"], PartitionedBundle["bundle"]] {
const keys = Object.keys(origin); return Object.keys(origin).reduce(([ l10n, bundle ], current) => {
return keys.reduce(([ l10n, bundle ], current) => { if (!current.includes(".lproj")) {
if (current.includes(".lproj")) {
const pathComponents = current.split(sep);
const lang = pathComponents[0];
const file = pathComponents.slice(1).join("/");
(l10n[lang] || (l10n[lang] = {}))[file] = origin[current];
return [ l10n, bundle ];
} else {
return [ l10n, { ...bundle, [current]: origin[current] }]; return [ l10n, { ...bundle, [current]: origin[current] }];
} }
const pathComponents = current.split(sep);
const lang = pathComponents[0];
const file = pathComponents.slice(1).join("/");
(l10n[lang] || (l10n[lang] = {}))[file] = origin[current];
return [ l10n, bundle ];
}, [{},{}]); }, [{},{}]);
} }