PathMaker
A factory for making URL/FileSystem paths with templates and URL query strings.
Usage
var basePath = ; var subPath = basePath;; // returns: '/my/path/or/url/'; // returns: '/my/path/or/url/sub/path'
See Examples below for extended usage including templates and URL query strings.
Options
Name | Default Value | Description |
---|---|---|
delimiter |
'/' |
The path delimiter. |
tokenPrefix |
':' |
The path token prefix. |
path |
'' |
The path represented by the PathMaker . |
Notes
- Trailing delimiters are not automatically added or removed at any time.
- Only query object values are encoded with
encodeURIComponent
. No other part of the path is automatically encoded.
Examples
; const site = ;const api = ;const base = ; /** URL makers for any URLs used by this application. */const AppURL = /** Base application URL maker. */ base /** Site URL maker, to make URLs outside of base. */ site login: base product: base products: base /** API URL makers. */ api: /** Base API URL maker. */ base: api account: api oauth: api user: api users: api ; ;
; console; // http://www.site.test/ console; // http://www.site.test/app-name/ console; // http://www.site.test/app-name/products/999/ console; // http://www.site.test/app-name/login/?redirect=%2Fdashboard console; // http://www.site.test/app-name/login/?redirect=%2Fdashboard console; // http://api.site.test/users/10 console; // http://api.site.test/users/10/organizations/search?q=the%20query
Roadmap
Needs Tests!
This code is trivial, it works and it's been in use for a while before it was published as an NPM. However, we need tests to protect against regressions! I think jest is already setup here for us.
History
- This project was bootstrapped with Best way to create npm packages with create-react-app.
- Released 1.0 - 1.0.4
- Released 2.0 with one major breaking change: to add path tokens.