Package Exports
- pathematics
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (pathematics) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
pathematics
Parse urls and with Express-like url segments
Install
npm install pathematics --saveUsage
Each segement in the source key of the map is injected into the destination value of the map. The map determins which key/value pair to use by comparing the url passed into the method with the map keys.
var pathematics = require('pathematics');
var routesMap = {
'/some/:segemented/route': '/new/route/:segmented'
};
var url = pathematics(routesMap, '/some/custom/route');
console.log(url); // OUTPUTS: /new/route/customYou can also partialize the function to reuse the object map
var pathematics = require('pathematics');
var routesMap = {
'/some/:segemented/route': '/new/route/:segmented'
};
var paths = pathematics(routesMap);
var url = paths('/some/custom/route');
console.log(url); // OUTPUTS: /new/route/customParseing route segements with custom meta data is also available. If the value if the key/value pair in the object map is an object, it expects the parameter of url to define the target path with segements.
var pathematics = require('pathematics');
var routesMap = {
'/some/:segemented/route': {
url: '/new/route/:segmented',
metaData: 'something'
}
};
var data = pathematics.withMeta(routesMap, '/some/custom/route');
console.log(data);
/*
OUTPUTS:
{
url: '/new/route/custom',
meta: {
url: '/new/route/:segmented',
metaData: 'something'
}
}
*/API
pathematics(objectMap[, url]);
Generates the parsed url with segments if the url is provided or returns a parsing funciton if no url is provided initially.
objectMap- and object with key values pairs that define routes with segments to match againsturl- the url to compare and parse with theobjectMap
pathematics.withMeta(objectMap[, url]);
Allows you to pass optional meta data around with route segements with the object map.
Run Tests
npm install
npm test