Formatting

This commit is contained in:
2026-08-10 02:04:51 +00:00
parent 26602dc156
commit f06ac63d0d
4 changed files with 15 additions and 16 deletions
+7 -10
View File
@@ -1,4 +1,4 @@
import { DeeplyReadonly } from "./types";
import type { DeeplyReadonly } from './types';
/**
* Validate the value is within the bounds, returning true if it is within the bounds, false otherwise
@@ -39,20 +39,17 @@ export const tryAsync = async (fn: () => unknown, onError?: (error: Error) => vo
* @returns The frozen object.
*/
export const deepFreeze = <T>(value: T): DeeplyReadonly<T> => {
if (
value !== null &&
(typeof value === 'object' || typeof value === 'function')
) {
if (value !== null && (typeof value === 'object' || typeof value === 'function')) {
for (const key of Reflect.ownKeys(value)) {
const descriptor = Reflect.getOwnPropertyDescriptor(value, key);
const descriptor = Reflect.getOwnPropertyDescriptor(value, key);
if (descriptor && 'value' in descriptor) {
deepFreeze(descriptor.value);
}
if (descriptor && 'value' in descriptor) {
deepFreeze(descriptor.value);
}
}
Object.freeze(value);
}
return value;
}
};