mirror of
https://github.com/Unleash/unleash.git
synced 2025-01-06 00:07:44 +01:00
5a3bb1ffc3
Lots of work here, mostly because I didn't want to turn off the `noImplicitAnyLet` lint. This PR tries its best to type all the untyped lets biome complained about (Don't ask me how many hours that took or how many lints that was >200...), which in the future will force test authors to actually type their global variables setup in `beforeAll`. --------- Co-authored-by: Gastón Fournier <gaston@getunleash.io>
39 lines
1.1 KiB
TypeScript
39 lines
1.1 KiB
TypeScript
import * as fs from 'fs';
|
|
import * as mime from 'mime';
|
|
import * as YAML from 'js-yaml';
|
|
|
|
export const readFile: (file: string) => Promise<string> = (file) =>
|
|
new Promise((resolve, reject) =>
|
|
fs.readFile(file, (err, v) =>
|
|
err ? reject(err) : resolve(v.toString('utf-8')),
|
|
),
|
|
);
|
|
|
|
export const parseFile: (file: string, data: string) => any = (
|
|
file: string,
|
|
data: string,
|
|
) => (mime.getType(file) === 'text/yaml' ? YAML.load(data) : JSON.parse(data));
|
|
|
|
export const filterExisting: (
|
|
keepExisting: boolean,
|
|
existingArray: any[],
|
|
) => (item: any) => boolean =
|
|
(keepExisting, existingArray = []) =>
|
|
(item) => {
|
|
if (keepExisting) {
|
|
const found = existingArray.find((t) => t.name === item.name);
|
|
return !found;
|
|
}
|
|
return true;
|
|
};
|
|
|
|
export const filterEqual: (existingArray: any[]) => (item: any) => boolean =
|
|
(existingArray = []) =>
|
|
(item) => {
|
|
const toggle = existingArray.find((t) => t.name === item.name);
|
|
if (toggle) {
|
|
return JSON.stringify(toggle) !== JSON.stringify(item);
|
|
}
|
|
return true;
|
|
};
|