npm install url_parser
var urlParser = require('url_parser');
urlParser('http://example.com/terms/:termId/posts/:postId', {
termId: 1,
postId: 2,
}); // -> http://example.com/terms/1/posts/2
var urlParser = require('url_parser');
urlParser('http://example.com/terms/:termId/posts', {
termId: 1,
skip: 5,
take: 10,
}); // -> http://example.com/terms/1/posts?skip=5&take=10
bower install url_parser
In HTML:
<script src="bower_components/url_parser/dist/url-parser.standalone.min.js"></script>
In Javascript:
var url = urlParser('http://example.com/terms/:termId/posts/:postId', {
termId: 1,
postId: 2,
});
console.log(url); // -> http://example.com/terms/1/posts/2
var url = urlParser('http://example.com/terms/:termId/posts', {
termId: 1,
skip: 5,
take: 10,
});
console.log(url); // -> http://example.com/terms/1/posts?skip=5&take=10
$ npm install
$ npm test