-
-
Notifications
You must be signed in to change notification settings - Fork 14
Expand file tree
/
Copy pathutils.ts
More file actions
13 lines (12 loc) · 565 Bytes
/
Copy pathutils.ts
File metadata and controls
13 lines (12 loc) · 565 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
import { isBytes } from '@noble/hashes/utils.js';
export const deepClone = <T>(value: T): T => {
// Bun 1.3.12 structuredClone throws on decoded packet/cert objects; tests need only data clones.
if (isBytes(value)) return Uint8Array.from(value) as T;
if (value === null || typeof value !== 'object') return value;
if (Array.isArray(value)) return value.map(deepClone) as T;
const out: Record<string, unknown> = {};
for (const k in value) {
if (Object.prototype.hasOwnProperty.call(value, k)) out[k] = deepClone(value[k]);
}
return out as T;
};