{"library":"proxy-target","title":"Proxy Target Utility","description":"proxy-target is a JavaScript utility library designed to simplify the use of native Proxies, particularly when dealing with primitive values, `null`, `undefined`, and functions. It addresses common `Proxy` limitations, such as the inability to directly proxy primitives or the 'Array.isArray shenanigans' by wrapping values in an object structure that can be consistently proxied and then unwrapped. The current stable version is 3.0.2. It appears to follow a release cadence driven by feature enhancements and bug fixes, rather than strict time-based intervals. Key differentiators include its ability to uniformly proxy almost any JavaScript value (primitives, objects, functions, etc.) by converting them into a structured `{ type, value }` pair, and its explicit mechanisms (`wrap`, `unwrap`, `bound`, `unbound`) for managing `this` context and value retrieval within a proxy chain. This makes it particularly useful for advanced metaprogramming scenarios where uniform proxy behavior across diverse value types is crucial.","language":"javascript","status":"active","last_verified":"Sun Apr 19","install":{"commands":["npm install proxy-target"],"cli":null},"imports":["import { wrap } from 'proxy-target';","import { unwrap } from 'proxy-target';","import { target } from 'proxy-target';","import { bound } from 'proxy-target';"],"auth":{"required":false,"env_vars":[]},"quickstart":{"code":"import { wrap, unwrap, bound, target, unbound } from 'proxy-target';\n\n// Example 1: Wrapping and unwrapping an object\nlet proxiedObject = wrap({ a: 1, b: 'hello' });\nconsole.log('Wrapped object:', proxiedObject);\nlet unwrappedObject = unwrap(proxiedObject);\nconsole.log('Unwrapped object:', unwrappedObject);\n// Verify identity if not a primitive (proxy-target specific)\nconsole.log('Original vs Unwrapped (object):', unwrappedObject.a === 1, unwrappedObject.b === 'hello');\n\n// Example 2: Wrapping a primitive (number)\nlet proxiedNumber = wrap(123);\nconsole.log('Wrapped number:', proxiedNumber);\n// The wrapper exposes a { type, value } structure for primitives\nconsole.log('Type of wrapped number:', proxiedNumber.type);\nconsole.log('Value of wrapped number:', proxiedNumber.value);\nlet unwrappedNumber = unwrap(proxiedNumber);\nconsole.log('Unwrapped number:', unwrappedNumber);\nconsole.log('Original vs Unwrapped (number):', unwrappedNumber === 123);\n\n// Example 3: Handling functions with `bound` and `unbound`\nconst originalFunction = (val) => `Processed: ${val}`;\nconst callbacks = [\n  (a) => a + 1,\n  (b) => b + 2\n];\n\nlet proxiedFunction = wrap(\n  callbacks[1],\n  (type, value) => bound(\n    target(type, callbacks.indexOf(value))\n  )\n);\n\n// To get the original function back, first unwrap `bound` then use the callback\nconst retrievedIndex = unbound(proxiedFunction);\nconst finalUnwrappedFunction = unwrap(retrievedIndex, (type, value) => {\n  return type === \"function\" ? callbacks[value] : value;\n});\nconsole.log('Retrieved function result:', finalUnwrappedFunction(10));\n","lang":"typescript","description":"Demonstrates wrapping and unwrapping various JavaScript values (objects, primitives, functions) and using `bound`/`unbound` to manage function context within a proxy.","tag":null,"tag_description":null,"last_tested":null,"results":[]},"compatibility":null}