From f642ddc4443c1365985b27bb0b79f375ec33a176 Mon Sep 17 00:00:00 2001 From: Alexander Cerutti Date: Tue, 10 Dec 2019 22:10:45 +0100 Subject: [PATCH] Improved splitBufferBundle with early return --- src/utils.ts | 21 ++++++++++----------- 1 file changed, 10 insertions(+), 11 deletions(-) diff --git a/src/utils.ts b/src/utils.ts index 610d3e2..1e42384 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -90,19 +90,18 @@ export function generateStringFile(lang: { [index: string]: string }): Buffer { */ export function splitBufferBundle(origin: Object): [PartitionedBundle["l10nBundle"], PartitionedBundle["bundle"]] { - const keys = Object.keys(origin); - return keys.reduce(([ l10n, bundle ], current) => { - 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 Object.keys(origin).reduce(([ l10n, bundle ], current) => { + if (!current.includes(".lproj")) { 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 ]; }, [{},{}]); }