{"id":15381362,"url":"https://github.com/pshihn/proxly","last_synced_at":"2025-04-15T19:09:36.093Z","repository":{"id":38324628,"uuid":"126242790","full_name":"pshihn/proxly","owner":"pshihn","description":"Easiest way to proxy a list of objects/functions in Javascript","archived":false,"fork":false,"pushed_at":"2018-03-23T08:36:08.000Z","size":37,"stargazers_count":23,"open_issues_count":0,"forks_count":0,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-04-15T19:09:26.752Z","etag":null,"topics":["convenience","javascript","javascript-proxy","proxy"],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/pshihn.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2018-03-21T21:28:52.000Z","updated_at":"2025-02-11T15:50:20.000Z","dependencies_parsed_at":"2022-08-25T02:20:13.896Z","dependency_job_id":null,"html_url":"https://github.com/pshihn/proxly","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pshihn%2Fproxly","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pshihn%2Fproxly/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pshihn%2Fproxly/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pshihn%2Fproxly/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/pshihn","download_url":"https://codeload.github.com/pshihn/proxly/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":249135809,"owners_count":21218365,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["convenience","javascript","javascript-proxy","proxy"],"created_at":"2024-10-01T14:26:54.826Z","updated_at":"2025-04-15T19:09:36.075Z","avatar_url":"https://github.com/pshihn.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"![Proxly](https://i.imgur.com/kqGg1MN.png)\n\n**Proxy any list of objects or functions to a single entity.**\u003cbr\u003e\n**All common properties and methods are automatically reflected.**\n\n* Objects can be heterogeneous with a shared interface\n* Can proxy a set of functions (sync/async) to a single call\n* Works with Arrays\n* Supports callbacks as arguments\n* Excellent with async/await\n* Tiny in size. **Only _444 bytes_ gzipped**\n\n## Install\nDownload the latest from [dist folder](https://github.com/pshihn/proxly/tree/master/dist)\u003cbr\u003e\nor from npm:\n```\nnpm install --save proxly\n```\n\n## Usage/Examples\n#### Proxy Functions\n```javascript\nfunction add(a, b) { return a + b; }\nfunction subtract(a, b) { return a - b; }\nasync function multiply(a, b) { return a * b; }\n\n(async () =\u003e {\n  let proxy = proxly(add, subtract, multiply);\n  let result = await proxy(4, 2);\n  console.log(result); // [6, 2, 8]\n})();\n```\n#### Proxy Objects\nObjects could be instances of the same class or just any two objects with a common interface.\n```javascript\nclass Operation {\n  constructor(name) {\n    this.name = name;\n    this.count = 0;\n  }\n  run(a, b) {\n    this.count++;\n    if (this.name === 'add') return a + b;\n    if (this.name === 'subtract') return a - b;\n  }\n}\nlet adder = new Operation('add');\nlet subtractor = new Operation('subtract');\n\n(async () =\u003e {\n  let proxy = proxly(adder, subtractor);\n  console.log(await proxy.name); // [\"add\", \"subtract\"]\n  console.log(await proxy.count); // [0, 0]\n  console.log(await proxy.run(10, 4)); // [14, 6]\n  console.log(await proxy.count); // [1, 1]\n})();\n```\n#### Proxy Arrays\nOf course it works with arrays\n```javascript\nlet fruits = [\"apple\", \"banana\", \"grape\"];\nlet colors = [\"red\", \"yellow\", \"green\"];\n(async () =\u003e {\n  let proxy = proxly(fruits, colors);\n  console.log(await proxy[1]); // [\"banana\", \"yellow\"]\n  console.log(await proxy.length); // [3, 3]\n  proxy.push('orange');\n  console.log(await proxy.length); // [4, 4]\n  console.log(fruits); // [\"apple\", \"banana\", \"grape\", \"orange\"]\n  console.log(colors); // [\"red\", \"yellow\", \"green\", \"orange\"]\n})();\n```\n\n#### Callbacks\nIf a callback is passed into a proxied set of functions (or a method in a proxied set of objects), it is called back sequentially in the order the proxy was defined.\n```javascript\nfunction add(a, b, cb) {\n  cb(a + b);\n}\nfunction sub(a, b, cb) {\n  setTimeout(() =\u003e {\n    cb(a - b);\n  }, 1000);\n}\n(async () =\u003e {\n  let cb = (result) =\u003e {\n    console.log(\"result\", result);\n  };\n  let proxy = proxly(add, sub);\n  proxy(6, 4, cb);\n})();\n```\nOutput:\n```\nresult 10\nresult 2\n```\n\n### Examples\nSee the [examples folder](https://github.com/pshihn/proxly/tree/master/examples)\n\n### License\n[MIT License](https://github.com/pshihn/proxly/blob/master/LICENSE) (c) [Preet Shihn](https://twitter.com/preetster)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpshihn%2Fproxly","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fpshihn%2Fproxly","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpshihn%2Fproxly/lists"}