From 46f39fa93fa99eef2691d6dc905b9d083eb170cb Mon Sep 17 00:00:00 2001 From: Joris Date: Tue, 21 Jun 2022 07:59:57 +0200 Subject: Add more drum sounds --- src/lib/dict.ts | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 src/lib/dict.ts (limited to 'src/lib/dict.ts') diff --git a/src/lib/dict.ts b/src/lib/dict.ts new file mode 100644 index 0000000..43b9f02 --- /dev/null +++ b/src/lib/dict.ts @@ -0,0 +1,21 @@ +type Key = string | number | symbol + +export function fromList(xs: Array<{key: Key, value: V}>): Record { + let res: any = {} + xs.forEach(o => res[o.key] = o.value) + return res as Record +} + +export function toList(record: Record): Array<{key: Key, value: V}> { + return Object.keys(record) + .map(key => ({ key: key, value: record[key] })) +} + +type EnumObject = {[key: string]: number | string}; +type EnumObjectEnum = E extends {[key: string]: infer ET | string} ? ET : never; + +export function values(enumObject: E): EnumObjectEnum[] { + return Object.keys(enumObject) + .filter(key => Number.isNaN(Number(key))) + .map(key => enumObject[key] as EnumObjectEnum) +} -- cgit v1.2.3