path-proxy
Given an group of paths (say, from an API schema), you might need to create a set of proxy objects for interacting with those paths. This is the situation I found myself in while working on the Node client for the Heroku API.
Given a set of paths and a base constructor function, path-proxy will create a network of logical proxy objects based on the paths and attach it to the constructor's prototype.
Install
npm install path-proxy --save
Usage
var pathProxy = ; {} pathProxy; var client = ;client;
This may not appear all that useful—they're mostly just empty functions—until you start mucking around with their prototypes:
var BarProxy = pathProxy;BarProxyprototype { console;}; client; // Logs "hello".
They also have access to a few useful attributes:
var baz = client;bazparams; // ["qux", "baz"]bazpathSegments; // ["foo", "qux", "bar", "baz"]bazpath; // "/foo/qux/bar/baz"
And can access the instance of the base constructor they're based off of:
ApiClientprototype { var message = thisname + " deleted at " + path; ;}; var client = ;clientname = "Jonathan"; BarProxyprototype { thisbase;}; // This:client; // Is equivalent to this:client;
Tests
path-proxy uses jasmine-node for tests. To run them:
$ npm install$ npm test