Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

pathematics

Package Overview
Dependencies
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

pathematics

Parse urls and with Express-like url segments

  • 0.1.1
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
873
increased by576.74%
Maintainers
1
Weekly downloads
 
Created
Source

pathematics

Parse urls and with Express-like url segments

Install

npm install pathematics --save

Usage

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/custom

You 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/custom

Parseing 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 against
  • url - the url to compare and parse with the objectMap

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

Keywords

FAQs

Package last updated on 07 May 2014

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc