Files
headroom/frontend/node_modules/@ark/util/out/clone.js
Santhosh Janardhanan de2d83092e feat: Reinitialize frontend with SvelteKit and TypeScript
- Delete old Vite+Svelte frontend
- Initialize new SvelteKit project with TypeScript
- Configure Tailwind CSS v4 + DaisyUI
- Implement JWT authentication with auto-refresh
- Create login page with form validation (Zod)
- Add protected route guards
- Update Docker configuration for single-stage build
- Add E2E tests with Playwright (6/11 passing)
- Fix Svelte 5 reactivity with $state() runes

Known issues:
- 5 E2E tests failing (timing/async issues)
- Token refresh implementation needs debugging
- Validation error display timing
2026-02-17 16:19:59 -05:00

34 lines
1.5 KiB
JavaScript

import { getBuiltinNameOfConstructor } from "./objectKinds.js";
/** Shallowly copy the properties of the object. */
export const shallowClone = input => _clone(input, null);
/** Deeply copy the properties of the a non-subclassed Object, Array or Date.*/
export const deepClone = (input) => _clone(input, new Map());
const _clone = (input, seen) => {
if (typeof input !== "object" || input === null)
return input;
if (seen?.has(input))
return seen.get(input);
const builtinConstructorName = getBuiltinNameOfConstructor(input.constructor);
if (builtinConstructorName === "Date")
return new Date(input.getTime());
// we don't try and clone other prototypes here since this we can't guarantee arrow functions attached to the object
// are rebound in case they reference `this` (see https://x.com/colinhacks/status/1818422039210049985)
if (builtinConstructorName && builtinConstructorName !== "Array")
return input;
const cloned = Array.isArray(input) ?
input.slice()
: Object.create(Object.getPrototypeOf(input));
const propertyDescriptors = Object.getOwnPropertyDescriptors(input);
if (seen) {
seen.set(input, cloned);
for (const k in propertyDescriptors) {
const desc = propertyDescriptors[k];
if ("get" in desc || "set" in desc)
continue;
desc.value = _clone(desc.value, seen);
}
}
Object.defineProperties(cloned, propertyDescriptors);
return cloned;
};