Skip to content

Commit ee5d486

Browse files
author
Sergio Daniel Xalambrí
committed
[add] url parser
1 parent a1552a2 commit ee5d486

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

lib/parser.js

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
/**
2+
* Parse url
3+
* @param {Object} urls URLs map to use
4+
* @param {String} name URL name to parse
5+
* @param {Object} opts Parameters for the URL
6+
* @returns {String} Parsed URL
7+
*/
8+
function parser(urls, name, opts = undefined) {
9+
const url = urls[name];
10+
11+
if (!opts) return url;
12+
13+
return url
14+
.split('/')
15+
.map(key => {
16+
if (key[0] !== ':') return key;
17+
return opts[key.slice(1, key.length)];
18+
})
19+
.join('/');
20+
}
21+
22+
export default parser;

0 commit comments

Comments
 (0)