Added more utils functions

This commit is contained in:
Alexander Cerutti
2019-07-27 00:40:28 +02:00
parent ced3caf0ac
commit d650dbb31f

View File

@@ -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]);
}