package
A wrap/unwrap Proxy utility
npm install proxy-targetGitHub-flavored package documentation.
Across all versions.
Download trend unavailable.
Runtime metadata.
Tagged topics.
Estimated unpacked size across 1 packages.
28.9 kB
Includes dependencies.
A wrap/unwrap Proxy utility as answer to these weird limitations.
This module allows any primitive to complex value to be proxied in a way that any handler can understand once the unwrap(target) operation is performed among actions:
proxy-target/array is used{type: actualType, value: actualValue} once wrapped| type | value | wrap |
|---|---|---|
"array" | [1, 2] | [1, 2] or [[1,2]] w/array |
"bigint" | 1n | {type: "bigint", value: 1n} |
"boolean" | false | {type: "boolean", value: false} |
"function" | (a, b) => {} | (a, b) => {} or Ctx.bind(fn) w/all |
"null" | null | {type: "null", value: null} |
"number" | 1.2 | {type: "number", value: 1.2} |
import {
bound, // return a function that returns its bound context
unbound,// if function, invokes it to return the context
target, // create a `{type, value}` pair to proxy as target
wrap, // returns array, function, or a pair
unwrap // returns the wrapped value
} from 'proxy-target';
let proxied;
proxied = wrap([1, 2, 3]);
// remains [1, 2, 3]
unwrap(proxied);
// still [1, 2, 3]
// both wrap and unwrap accept an optional callback
// the returned value will the one returned by wrap
proxied = wrap({a: 1}, (type, value) => target(type, value));
// {type: "object", value: {a: 1}}
"object"{a: 0} |
{type: "object", value: {a: 0}} |
"string" | "" | {type: "string", value: ""} |
"symbol" | Symbol() | {type: "symbol", value: Symbol()} |
"undefined" | void 0 | {type: "undefined", value: undefined} |
"custom" | notArrOrFunc | {type: "custom", value: notArrOrFunc} |