Socket
Book a DemoInstallSign in
Socket

murl

Package Overview
Dependencies
Maintainers
1
Versions
9
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

murl

murl is fast url pattern matching and replacing

latest
Source
npmnpm
Version
0.4.1
Version published
Maintainers
1
Created
Source

murl

murl is fast url pattern matching and replacing. It's avaiable through npm:

npm install murl

What?

murl exposes a single function that accepts a pattern

var murl = require('murl');
var pattern = murl('/{hello}');

If you pass a string to the pattern murl will try and match it

pattern('/world') // -> {hello:'world'}

If you pass an object it will replace into the pattern

pattern({hello:'world'}) // -> '/world'

Patterns

You can use ? to specify a group as optional

murl('/{hello}/{world}?'): matches both /a and /a/b

Per default the {} groups matches until the next character or /.

murl(/{hello}): matches /a but not /a/b murl(/{wid}x{hei}): matches /200x200

Use * to match anything

murl('/*'): matches /a, /a/b/c and so on

Strict mode

Per default murl will disregard trailing / from the input string. Pass {strict:true} to disable this.

var pattern = murl('/{hello}', {strict:true});

console.log(pattern('/world/')); // returns null
console.log(pattern('/world'))   // return {hello:'world'}

License

MIT

Keywords

url

FAQs

Package last updated on 20 Sep 2013

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