pathern
v0.3.1
Published
Minimalistic path pattern matching
Downloads
670
Maintainers
Readme
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: '$',
delimiter: '\\',
});
extract
pathern.extract('a/:b/c', 'a/2/c'); // { b: '2' }
matches
pathern.matches('a/:b/c', 'a/2/c'); // true