Removed old unused utils functions

This commit is contained in:
Alexander Cerutti
2021-10-10 02:33:31 +02:00
parent 21e041e9cc
commit 99d3c1566a

View File

@@ -86,104 +86,3 @@ function padMeTwo(original: string | number) {
export function removeHidden(from: Array<string>): Array<string> {
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<PartitionedBundleElements>(
([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],
);
}