diff options
author | Joris | 2022-06-21 07:59:57 +0200 |
---|---|---|
committer | Joris | 2022-06-21 07:59:57 +0200 |
commit | 46f39fa93fa99eef2691d6dc905b9d083eb170cb (patch) | |
tree | 1d39b1b358a49a4c194dbf852cf80b5f07629361 /src/lib | |
parent | 5944be94dfd221f41cfb5e60e007c159b617f5dc (diff) |
Add more drum sounds
Diffstat (limited to 'src/lib')
-rw-r--r-- | src/lib/dict.ts | 21 |
1 files changed, 21 insertions, 0 deletions
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<V>(xs: Array<{key: Key, value: V}>): Record<Key, V> { + let res: any = {} + xs.forEach(o => res[o.key] = o.value) + return res as Record<Key, V> +} + +export function toList<V>(record: Record<Key, V>): 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 EnumObject> = E extends {[key: string]: infer ET | string} ? ET : never; + +export function values<E extends EnumObject>(enumObject: E): EnumObjectEnum<E>[] { + return Object.keys(enumObject) + .filter(key => Number.isNaN(Number(key))) + .map(key => enumObject[key] as EnumObjectEnum<E>) +} |