Skip to content

Instantly share code, notes, and snippets.

@wryk
Last active August 29, 2015 14:02
Show Gist options
  • Select an option

  • Save wryk/b6516d9506f5546adde3 to your computer and use it in GitHub Desktop.

Select an option

Save wryk/b6516d9506f5546adde3 to your computer and use it in GitHub Desktop.
import {normalize} from 'path';
export default ResourcePath;
function ResourcePath (value) {
this.value = normalize(value);
}
ResourcePath.prototype.add = function () {
var result = this.value;
for (var i = -1, l = arguments.length; ++i < l;) {
result += '/' + arguments[i];
}
return new ResourcePath(result);
};
ResourcePath.prototype.toString = function () {
return this.value;
};
import ResourcePath from 'resource-path.js';
var api = new ResourcePath('https://api.github.com');
// .value => https://api.github.com
var wryk = api.add('users', 'wryk');
// .value => https://api.github.com/users/wryk
var issues = wryk.add('issues');
// .value => https://api.github.com/users/wryk/issues
wryk.value === wryk.toString();
// => true
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment