From 99d3c1566ab0e5712e9866ae91d488d6c4c4ad32 Mon Sep 17 00:00:00 2001 From: Alexander Cerutti Date: Sun, 10 Oct 2021 02:33:31 +0200 Subject: [PATCH] Removed old unused utils functions --- src/utils.ts | 101 --------------------------------------------------- 1 file changed, 101 deletions(-) diff --git a/src/utils.ts b/src/utils.ts index 7cced28..cb1a1bc 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -86,104 +86,3 @@ function padMeTwo(original: string | number) { export function removeHidden(from: Array): Array { return from.filter((e) => e.charAt(0) !== "."); } - -/** - * Creates a buffer of translations in Apple .strings format - * - * @function generateStringFile - * @params {Object} lang - structure containing related to ISO 3166 alpha-2 code for the language - * @returns {Buffer} Buffer to be written in pass.strings for language in lang - * @see https://apple.co/2M9LWVu - String Resources - */ - -export function generateStringFile(lang: { [index: string]: string }): Buffer { - if (!Object.keys(lang).length) { - return Buffer.from("", "utf8"); - } - - // Pass.strings format is the following one for each row: - // "key" = "value"; - - const strings = Object.keys(lang).map( - (key) => `"${key}" = "${lang[key].replace(/"/g, '"')}";`, - ); - - return Buffer.from(strings.join(EOL), "utf8"); -} - -/** - * Applies a partition to split one bundle - * to two - * @param origin - */ - -type PartitionedBundleElements = [ - Schemas.PartitionedBundle["l10nBundle"], - Schemas.PartitionedBundle["bundle"], -]; - -export function splitBufferBundle( - origin: Schemas.BundleUnit, -): PartitionedBundleElements { - const initialValue: PartitionedBundleElements = [{}, {}]; - - if (!origin) { - return initialValue; - } - - return Object.entries(origin).reduce( - ([l10n, bundle], [key, buffer]) => { - if (!key.includes(".lproj")) { - return [ - l10n, - { - ...bundle, - [key]: buffer, - }, - ]; - } - - const pathComponents = key.split(sep); - const lang = pathComponents[0]; - const file = pathComponents.slice(1).join("/"); - - (l10n[lang] || (l10n[lang] = {}))[file] = buffer; - - return [l10n, bundle]; - }, - initialValue, - ); -} - -type StringSearchMode = "includes" | "startsWith" | "endsWith"; - -export function getAllFilesWithName( - name: string, - source: string[], - mode: StringSearchMode = "includes", - forceLowerCase: boolean = false, -): string[] { - return source.filter((file) => - ((forceLowerCase && file.toLowerCase()) || file)[mode](name), - ); -} - -export function hasFilesWithName( - name: string, - source: string[], - mode: StringSearchMode = "includes", - forceLowerCase: boolean = false, -): boolean { - return source.some((file) => - ((forceLowerCase && file.toLowerCase()) || file)[mode](name), - ); -} - -export function deletePersonalization( - source: Schemas.BundleUnit, - logosNames: string[] = [], -): void { - [...logosNames, "personalization.json"].forEach( - (file) => delete source[file], - ); -}