Last active
August 29, 2015 14:02
-
-
Save wryk/b6516d9506f5546adde3 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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; | |
| }; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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