npm.io
0.3.1 • Published 2 years ago

pathern

Licence
MIT
Version
0.3.1
Deps
0
Size
10 kB
Vulns
0
Weekly
0

Build Status Code Coverage downloads version MIT License

size gzip size

Pathern

Minimalistic path pattern matching

Install

npm install pathern

Usage

import * as pathern from 'pathern';

replace

pathern.replace('posts/:postId', '1');                      // 'posts/1'
pathern.replace('posts/:postId', { postId: '1' });          // 'posts/1'
pathern.replace(':a/:b/:c', { a: '1', b: '2', c: '3' });    // '1/2/3'
pathern.replace('$a\\$b\\$c', { a: '1', b: '2', c: '3' }, { // '1/2/3'
  prefix: '

extract

pathern.extract('a/:b/c', 'a/2/c'); // { b: '2' }

matches

pathern.matches('a/:b/c', 'a/2/c'); // true
, delimiter: '\\', });

extract

__CODE_BLOCK_3__

matches

__CODE_BLOCK_4__