@rustable/utils
Version:
Essential utilities for object cloning, string manipulation, and value comparison in TypeScript, inspired by Rust's standard library.
29 lines (26 loc) • 588 B
JavaScript
;
;
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;
exports.Ptr = Ptr;