All Projects → pshihn → Proxly

pshihn / Proxly

Licence: mit
Easiest way to proxy a list of objects/functions in Javascript

Programming Languages

javascript
184084 projects - #8 most used programming language

Labels

Projects that are alternatives of or similar to Proxly

Proxy Hot Reload
Node.js application hot reload with `Proxy`.
Stars: ✭ 19 (+26.67%)
Mutual labels:  proxy
Danby
A webserver that's also a grpc proxy for browsers
Stars: ✭ 26 (+73.33%)
Mutual labels:  proxy
Hacking With Golang
Golang安全资源合集
Stars: ✭ 876 (+5740%)
Mutual labels:  proxy
Observer Util
Transparent reactivity with 100% language coverage. Made with ❤️ and ES6 Proxies.
Stars: ✭ 905 (+5933.33%)
Mutual labels:  proxy
Thinningcoordinator
The UITableView/UICollectionView dataSource/delegate thinning coordinator, help thinning your UIViewController!
Stars: ✭ 25 (+66.67%)
Mutual labels:  proxy
Nginx Tutorial
这是一个 Nginx 极简教程,目的在于帮助新手快速入门 Nginx。
Stars: ✭ 845 (+5533.33%)
Mutual labels:  proxy
Osu Hope
osu!HOPE: HoLLy's osu! Packet Editor
Stars: ✭ 18 (+20%)
Mutual labels:  proxy
Concent
State management that tailored for react, it is simple, predictable, progressive and efficient.
Stars: ✭ 882 (+5780%)
Mutual labels:  proxy
Proxadd
A tool that adds proxy entries to Proxychains config
Stars: ✭ 26 (+73.33%)
Mutual labels:  proxy
Shadowsocks Php
A php port of shadowsocks based on workerman. A socks5 proxy written in PHP.
Stars: ✭ 869 (+5693.33%)
Mutual labels:  proxy
Swaddle
Automagically create API clients/wrappers in JavaScript
Stars: ✭ 23 (+53.33%)
Mutual labels:  proxy
Louketo Proxy
A OpenID / Proxy service
Stars: ✭ 926 (+6073.33%)
Mutual labels:  proxy
Docker Apache Proxy
Apache web server like proxy to Docker
Stars: ✭ 9 (-40%)
Mutual labels:  proxy
Jsocksproxy
SOCKS proxy written in Java
Stars: ✭ 19 (+26.67%)
Mutual labels:  proxy
Switcher
Run SSH and HTTP(S) on the same port
Stars: ✭ 877 (+5746.67%)
Mutual labels:  proxy
Gotit
Help You Got It (golang dependencies)
Stars: ✭ 19 (+26.67%)
Mutual labels:  proxy
Cloak
A censorship circumvention tool to evade detection against state adversaries
Stars: ✭ 942 (+6180%)
Mutual labels:  proxy
Grpc Tools
A suite of gRPC debugging tools. Like Fiddler/Charles but for gRPC.
Stars: ✭ 881 (+5773.33%)
Mutual labels:  proxy
Proxychains Ng
proxychains ng (new generation) - a preloader which hooks calls to sockets in dynamically linked programs and redirects it through one or more socks/http proxies. continuation of the unmaintained proxychains project. the sf.net page is currently not updated, use releases from github release page instead.
Stars: ✭ 7,553 (+50253.33%)
Mutual labels:  proxy
Bbc Rss
BBC iPlayer programmes / Nitro API to RSS adaptor app
Stars: ✭ 10 (-33.33%)
Mutual labels:  proxy

Proxly

Proxy any list of objects or functions to a single entity.
All common properties and methods are automatically reflected.

  • Objects can be heterogeneous with a shared interface
  • Can proxy a set of functions (sync/async) to a single call
  • Works with Arrays
  • Supports callbacks as arguments
  • Excellent with async/await
  • Tiny in size. Only 444 bytes gzipped

Install

Download the latest from dist folder
or from npm:

npm install --save proxly

Usage/Examples

Proxy Functions

function add(a, b) { return a + b; }
function subtract(a, b) { return a - b; }
async function multiply(a, b) { return a * b; }

(async () => {
  let proxy = proxly(add, subtract, multiply);
  let result = await proxy(4, 2);
  console.log(result); // [6, 2, 8]
})();

Proxy Objects

Objects could be instances of the same class or just any two objects with a common interface.

class Operation {
  constructor(name) {
    this.name = name;
    this.count = 0;
  }
  run(a, b) {
    this.count++;
    if (this.name === 'add') return a + b;
    if (this.name === 'subtract') return a - b;
  }
}
let adder = new Operation('add');
let subtractor = new Operation('subtract');

(async () => {
  let proxy = proxly(adder, subtractor);
  console.log(await proxy.name); // ["add", "subtract"]
  console.log(await proxy.count); // [0, 0]
  console.log(await proxy.run(10, 4)); // [14, 6]
  console.log(await proxy.count); // [1, 1]
})();

Proxy Arrays

Of course it works with arrays

let fruits = ["apple", "banana", "grape"];
let colors = ["red", "yellow", "green"];
(async () => {
  let proxy = proxly(fruits, colors);
  console.log(await proxy[1]); // ["banana", "yellow"]
  console.log(await proxy.length); // [3, 3]
  proxy.push('orange');
  console.log(await proxy.length); // [4, 4]
  console.log(fruits); // ["apple", "banana", "grape", "orange"]
  console.log(colors); // ["red", "yellow", "green", "orange"]
})();

Callbacks

If 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.

function add(a, b, cb) {
  cb(a + b);
}
function sub(a, b, cb) {
  setTimeout(() => {
    cb(a - b);
  }, 1000);
}
(async () => {
  let cb = (result) => {
    console.log("result", result);
  };
  let proxy = proxly(add, sub);
  proxy(6, 4, cb);
})();

Output:

result 10
result 2

Examples

See the examples folder

License

MIT License (c) Preet Shihn

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].