router-validator v1.0.0
#Router Validator
##This Tool allow process segment of the URL
##En--lang
This tool is useful for both server and client routes,
his only task is to process the segemntos of a dirrecion and to treat it to see if it coincides with
a certain route. For example, in router libraries for the client that work with the hash-tag, you can collect components with a property url, which has parameters in the path type: to / path /: id
and having a requestto / path / 344
this library will return an object with the id property with the corresponding value of the request. It is of taking into account that the flexibility that this library carries to make modules of routes is the standard, as well as the routes of Express, Connect, and Vue Router, not to mention others.
##Es--lang
Esta herramienta util tanto para rutas del servidor como del cliente, pues
su unica tarea es procesar los segemntos de una dirrecion y tratarlo para ver si coincide con
una determinada ruta. Por ejemplo, en librerias de router para el cliente que trabajar con el hash-tag, usted puede collecionar componentes con una propiedad url, que tenga parametros en la ruta tipo: to/path/:id
y teniendo una peticion to/path/344
esta libreria le devolvera un objecto con la propiedad id con el valor correspondiente, de la petición. Es de tener en cuenta que la flexibilidad que porta esta libreria para hacer modulos de rutas es la estandar, así como las rutas de Express, Connect, y Vue Router, por no mencionar otros.
var segment = require('router-segment');
currentUrl = "/to/path/book/345";
collection = [
{path:'/to',resource:Object}, //target num 1
{path:'/to/elm',resource:Object}, //target num 2
{path:'/home',resource:Object}, //target num 3
{path:'/to/path/:category/:id',resource:Object}, //target num 4
{path:'/login',resource:Object} //target num 5
];
var result = segment(collection,currentUrl); /* ----> return {
target:{//target 4},
param:{category:'book',id:'345'}
}
*/
console.log(result);
//if no have match return {target:false}
##En--lang
If you have a certain logic of more components, it is possible that your url to locate the components, is not in a path
property, for this problem you have a third parameter
which is the name of the property that should be evaluated to locate a certain objective.
The use of this library is minimalist, it is very fast and efficient to locate objects based on route system.
This library does not yet support regular expressions, it wants to make an implementation in the future, while it is in development, as well as its documentation, although this example specifies quite well its operation.
This library can be used to create a system of small routes that do not need to validate regular expressions, but perfectly if they can validate routes with schema parameters : params
.
##Es--lang
Si tienes una determinada logica de componetes más, es posible que tu url para localizar el componentes, no se encuentre en una propiedad path
, para este problema tienes un tercer parametro
que es el nombre de la propiedad que deberá ser evaludad para localizar un determinado objetivo.
El uso de esta libreria es minimalista, es muy rapida y eficiente para localizar objectos basados en sistema de rutas.
Esta libreria aun no soporta expresiones regulares, se quiere hacer una implementación en el futuro, mientras se encuentra en desarrollo, al igual que su documentación, aunque este ejemplo especifica bastante bien su funcionamiento.
Esta libreria puede ser usada para crear sistema de rutas pequeños que no requieran validar expresiones regulares, pero perfectamente si que pueden validar rutas con parametros de esquema :params
.
7 years ago