New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

anumargak

Package Overview
Dependencies
Maintainers
1
Versions
22
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

anumargak

Amazing fast multipurpose web/ HTTP router

  • 1.4.0
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
9
increased by28.57%
Maintainers
1
Weekly downloads
 
Created
Source

anumargak (अनुमार्गक)

Fastest HTTP Router

Known Vulnerabilities Travis ci Build Status Coverage Status bitHound Overall Score NPM total downloads

Become a Patron! Stubmatic donate button

Features

  • Fastest node js router (as far as Google & I know)
  • Framework independent
  • Supports static and dynamic both type of URLs
  • Supports path parameter with defined type \this\is\:num([0-9]+)
  • Support multiple path parameters
  • Handles enumerated URLs \login\as\:role(admin|staff|user)
  • Supports wildchar \this\is\*, \this\is\wild*
  • You nee not to register 2 separate routes for trailing slash. \like\me\ and \like\me.
  • Capture parameters' value for dynamic URLs.
  • Warn (by default) or silently overwrites (when overwriteAllow : true) same or similar URLs
    • \this\is\static and \this\is\static
    • \this\:param\is\dynamic and \this\param\:is\dynamic
    • \this\is\:uid([a-zA-Z0-9]+) and \this\is\:num([0-9]+)
  • Add similar but not same URLs
    • \this\is\:age([0-9]+) and \this\is\:name([a-zA-Z]+)
  • Support of shorthand methods
  • You can always have a count on registered routes

Usage

const router = require('anumargak')({
  defaultRoute : defaultHandler,
  ignoreTrailingSlash: true,
  overwriteAllow : true
});

anumargak.on("GET", "/this/is/static", handler);
anumargak.on(["POST","PUT"], "/this/is/static", handler);//supports array
anumargak.on("GET", "/this/is/:dynamic", handler);
anumargak.on("GET", "/this/is/:dynamic", handler);//it will overwrite old mapping
anumargak.on("GET", "/this/is/:dynamic/with/:pattern(\\d+)", handler);
//Eg: params = { dynamic : val, pattern: 123}
anumargak.on("GET", "/this/is/:dynamic/with/:two-:params", handler);//use - to separate multiple parameters
anumargak.on("GET", "/this/is/:dynamic/with/:two(\\d+):params", handler);
anumargak.on("GET", "/this/is/:dynamic/with/:two(\\d+)rest", handler);
anumargak.on("GET", "/similar/:string([a-z]{10})", handler);
anumargak.on("GET", "/similar/:number([0-9]{10})", handler);//above route is different from this


anumargak.find("GET","/this/is/static");//will return handler
anumargak.find("GET","/this/is/dynamic/with/123?ignore=me");//ignore query parameters and hashtag part automatically

anumargak.lookup(req,res) ;//will execute handler with req,res and params(for dynamic URLs) as method parameters

console.log(anumargak.count); //Print number of unique routes added

Example with server

const http = require('http')
const router = require('anumargak')()

router.on('GET', '/', (req, res, params) => {
  //process the request response here
})

const server = http.createServer((req, res) => {
  router.lookup(req, res)
})

server.listen(3000, err => {
  if (err) throw err
  console.log('Server listening on: http://localost:3000')
})

wildcard: wild cards are helpful when a route handler wants to control all the underlying paths. Eg. a handler registered with /help* may take care of all the help pages and static resources under the same path.

//this/is/juglee/and/
//this/is/juglee/and/wild
//this/is/juglee/and/wild/and/unknown
anumargak.on("GET", "/this/is/:dynamic/and/*", handler);

//this/is/juglee/and/wild
//this/is/juglee/and/wildlife
//this/is/juglee/and/wild/and/unknown
anumargak.on("GET", "/this/is/:dynamic/and/wild*", handler);

shorthand methods

var router = Anumargak();

router.get("/this/is/:dynamic", () => 30);
router.head("/this/is/:dynamic", () => 30);
router.post("/this/is/:dynamic", () => 30);
router.put("/this/is/:dynamic", () => 30);
router.delete("/this/is/:dynamic", () => 30);

Similar but not same URLs

const anumargak = require('anumargak')()
//this/is/my/75
anumargak.on("GET", "/this/is/my/:age([0-9]{2,3})", handler);

//this/is/my/amit
anumargak.on("GET", "/this/is/my/:name([a-zA-z]+)", handler);

Benchmark

methodurl typeanumargak (अनुमार्गक)find-my-way
findstatic27445088.793130047.682
finddynamic2677420.5451243596.976
finddynamic with query1735442.6471225523.327
findenum25881565.61416613.461
lookupstatic29077013.862400789.425
lookupdynamic2030403.9511101769.543
lookupdynamic with query1419140.375974787.2642
lookupenum15906062.451191961.68

Note : Above benchmark has been taken on 16gb RAM ubuntu 17.10 machine with node v9.5.0 and npm v5.6.0

chart

Worth to mention

  • NIMN निम्न : Schema aware object compression. 60% more compressed than JSON. 40% more compressed than msgpack.
  • imglab : Web based tool to label images for object detection. Use it to train dlib or other object detectors. Integrated with 3rd party libraries to speed up tp process and to make you lazy.
  • fast-lorem-ipsum : Generate lorem ipsum words, sentences, paragraph very quickly. Pure JS implementation.
  • stubmatic : A stub server to mock behaviour of HTTP(s) / REST / SOAP services. You can easily mock msgpack, and nimn data formats as well.
  • fast-xml-parser : Pure JS implementation to parse XML to JSON, JS Object, or Nimn format. Parse back from JSON, JS Object to XML. Or just validate XML syntax.
  • Grapes : Flexible Regular expression engine (for java) which can be applied on char stream. (under development)
  • Muneem (मुनीम): A framework to write fast web services in easy way. Designed specially for developers, QAs, Maintainers, and BAs.

Keywords

FAQs

Package last updated on 26 Jun 2018

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