js-reverse

Allows to store urls in one place and get it everywhere you want. Just like in Django.


License
CNRI-Python-GPL-Compatible
Install
npm install js-reverse@1.2.0

Documentation

js-reverse

Allows to store urls in one place and get it everywhere you want. Just like in Django.

How to use

Install

yarn add js-reverse
or
npm install js-reverse

Define urls in one place

//urls.js file

const urls = {
    'allImages': '/images/all/',
    'catImage': '/images/<animal>/<id>/',
};

module.exports = urls;

Use it everywhere you want

import Library from 'js-reverse';
import urls from './urls';

const library = new Library('big-cat-database.com');
library.register(urls);

Without params in urls

library.get('allImages');
// big-cat-database.com/images/all/

With params in <> brackets

library.get('catImage', {animal: 'cat', id: 9000});
// big-cat-database.com/images/cat/9000/

With query string

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

Tests

To run the tests just use npm run test or yarn test. This starts the Jest tests, which will run all *.spec.js test files.