25 lines
1.1 KiB
TypeScript
25 lines
1.1 KiB
TypeScript
// export const createDefaultBooleanValue = <T extends PropertyKey>(keys_list: PropertyKey[]): Record<T, boolean> =>
|
|
// keys_list.reduce((acc, mod) => {
|
|
// acc[mod] = false;
|
|
// return acc;
|
|
// }, {} as Record<T, boolean>);
|
|
|
|
|
|
// export const toBooleanFromKeys = <T extends PropertyKey>(keys_list: PropertyKey[], arr?: readonly PropertyKey[] | null): Record<T, boolean> => {
|
|
// const result = createDefaultBooleanValue(keys_list);
|
|
// if (!arr || !Array.isArray(arr)) return result;
|
|
// for (const item of arr) {
|
|
// if (typeof item !== 'string') continue;
|
|
// const trimmed = item.trim();
|
|
// if ((keys_list as readonly PropertyKey[]).includes(trimmed)) {
|
|
// result[trimmed as T] = true;
|
|
// }
|
|
// }
|
|
// return result;
|
|
// }
|
|
|
|
export const toKeysFromBoolean = <T extends PropertyKey>(boolean_values: Record<T, boolean>): T[] => {
|
|
const values_array = Object.entries(boolean_values);
|
|
const values = values_array.filter(([_key, value]) => value === true);
|
|
return values.map(([key]) => key as T);
|
|
}
|