Skip to content

mafintosh/murl

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

22 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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

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

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

// matches '/a' but not '/a/b'
murl('/{hello}')

// matches '/200x200'
murl('/{wid}x{hei}')

Use * to match anything

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

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

About

murl is url pattern matching and replacing

Resources

License

Stars

Watchers

Forks

Sponsor this project

 

Packages

No packages published