26 lines
502 B
TypeScript
26 lines
502 B
TypeScript
|
|
export function createEmptyRecord<T>(): Record<string, T> {
|
||
|
|
return {};
|
||
|
|
}
|
||
|
|
|
||
|
|
export function getOwnRecordValue<T>(
|
||
|
|
record: Record<string, T>,
|
||
|
|
key: string,
|
||
|
|
): T | undefined {
|
||
|
|
return Object.prototype.hasOwnProperty.call(record, key)
|
||
|
|
? record[key]
|
||
|
|
: undefined;
|
||
|
|
}
|
||
|
|
|
||
|
|
export function setOwnRecordValue<T>(
|
||
|
|
record: Record<string, T>,
|
||
|
|
key: string,
|
||
|
|
value: T,
|
||
|
|
): void {
|
||
|
|
Object.defineProperty(record, key, {
|
||
|
|
configurable: true,
|
||
|
|
enumerable: true,
|
||
|
|
value,
|
||
|
|
writable: true,
|
||
|
|
});
|
||
|
|
}
|