PathMaker
A simple system to make URL or FileSystem paths and query strings (for URLs).
Example
import PathMaker from 'pathmaker';
const site = PathMaker('http://www.site.test/');
const api = PathMaker('http://api.site.test/');
const base = PathMaker('http://www.site.test/app-name/');
const AppURL = {
base,
site,
login: base.sub('account/login/'),
forgotPassword: base.sub('account/forgot-password/'),
register: base.sub('account/register/'),
api: {
base: api,
account: api.sub('account'),
oauth: api.sub('oauth'),
user: api.sub('user'),
users: api.sub('users'),
}
};
export default AppURL;
import AppURL from './AppURL';
console.log(
AppURL.site()
);
console.log(
AppURL.base()
);
console.log(
AppURL.login({redirect: '/dashboard'})
);
console.log(
AppURL.base('account/login/', {redirect: '/dashboard'})
);
console.log(
AppURL.api.user('10')
);
Notes
- There is only one option: delimiter. This defaults to a forward slash (
'/'
). - 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.
History
This project was bootstrapped with Best way to create npm packages with create-react-app.