12 lines
466 B
TypeScript
12 lines
466 B
TypeScript
import {clone,freeze} from './values.ts';
|
|
|
|
// Private provenance for a fresh, recursively frozen JSON clone. A caller can
|
|
// request a detached copy, but cannot grant this fact to an existing object.
|
|
const detached=new WeakSet<object>();
|
|
export function detachJsonData<T>(input:T):T {
|
|
const value=freeze(clone(input));
|
|
if(value&&typeof value==='object')detached.add(value);
|
|
return value;
|
|
}
|
|
export const hasDetachedJsonData=(value:object)=>detached.has(value);
|