UNPKG

@rustable/utils

Version:

Essential utilities for object cloning, string manipulation, and value comparison in TypeScript, inspired by Rust's standard library.

27 lines (25 loc) 570 B
"use strict"; const symbol = Symbol("ptr.ptr"); function Ptr({ get, set }) { return new Proxy({}, { get(_, prop) { const current = get(); if (prop === symbol) { return current; } const target = current; return typeof target[prop] === "function" ? target[prop].bind(target) : target[prop]; }, set(_, prop, value) { const current = get(); if (prop === symbol) { set(value); return true; } current[prop] = value; return true; } }); } Ptr.ptr = symbol; export { Ptr };