@scalar/api-reference
Version:
Generate beautiful API references from OpenAPI documents
25 lines (24 loc) • 862 B
JavaScript
import { deepClone } from "@scalar/workspace-store/helpers/deep-clone";
//#region src/helpers/safe-deep-clone.ts
/**
* Deep-clones plain data for use where mutation must not affect the source.
*
* In the browser we use `structuredClone`, which preserves `Date`, `Map`, `Set`,
* typed arrays, and other structured types. During SSR there is no `window`, so
* we fall back to `JSON.parse(JSON.stringify(...))`, which only supports JSON
* values (functions, `undefined` in objects, symbols, etc. are dropped or altered).
*
* @example
* ```ts
* const copy = safeDeepClone(spec)
* copy.info.title = 'Draft'
* // original spec is unchanged
* ```
*/
var safeDeepClone = (value) => {
if (typeof window === "undefined") return deepClone(value);
return window.structuredClone(value);
};
//#endregion
export { safeDeepClone };
//# sourceMappingURL=safe-deep-clone.js.map