trocha
v0.2.3
Published
Route/Path listing for JS
Downloads
3
Maintainers
Readme
TrochaJS
TLDR It replace long, ugly, repetitibe url strings with clean objects
An standalone/agnostic library to print valid URLs, ideal for RESTful & SPA frontEnd big projects.
Why this library exist
This library take inspiration from Ruby routing system, where you describe the routes via a simple name tree and call those routes via dinamic function naming, preventing use of string in views and controllers.
Ugly code example
theRoute =
'https://my.domain.com.co/product/' +
myProduct.id +
'/buy' +
'?quantity=' +
sell.quantity
With Trocha
theRoute = myRoutes.product.buy.path({
product_id: myProduct.id,
query: { quantity: sell.quantity }
})
This will print
https://my.domain.com.co/product/<product_id>/buy?quantity=<sell.quantity>
Please see the full docs at here: https://dfoxpro.github.io/trochaJS