Allows to store urls in one place and get it everywhere you want. Just like in Django.
yarn add js-reverse
//urls.js file
const urls = {
'allImages': '/images/all/',
'catImage': '/images/<animal>/<id>/',
};
module.exports = urls;
import Library from 'js-reverse/js-reverse/reverse-library';
import urls from 'urls';
const library = new Library('big-cat-database.com');
library.register(urls);
library.get('allImages');
// big-cat-database.com/images/all/
library.get('catImage', {animal: 'cat', id: 9000});
// big-cat-database.com/images/cat/9000/
library.get('catImage', {animal: 'cat', id: 9000}, {paginateBy: 20, order: 'from_cute_to_ugly'});
// http://big-cat-database.com/images/cat/9000/?paginateBy=20&order=from_cute_to_ugly
To run the tests just use npm run test
. This starts the Jasmine tests, that are located in the spec
directory