From d650dbb31fe09dba52bf3896bc2e8e8e0af088b8 Mon Sep 17 00:00:00 2001 From: Alexander Cerutti Date: Sat, 27 Jul 2019 00:40:28 +0200 Subject: [PATCH] Added more utils functions --- src/utils.ts | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/src/utils.ts b/src/utils.ts index 9f3f528..610d3e2 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -1,6 +1,6 @@ import moment from "moment"; import { EOL } from "os"; -import { PartitionedBundle } from "./schema"; +import { PartitionedBundle, BundleUnit } from "./schema"; import { sep } from "path"; /** @@ -105,3 +105,18 @@ export function splitBufferBundle(origin: Object): [PartitionedBundle["l10nBundl } }, [{},{}]); } + +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: BundleUnit, logosNames: string[] = []): void { + [...logosNames, "personalization.json"] + .forEach(file => delete source[file]); +}