pathern
TypeScript icon, indicating that this package has built-in type declarations

0.3.1 • Public • Published

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: '$',
  delimiter: '\\',
});

extract

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

matches

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

Package Sidebar

Install

npm i pathern

Weekly Downloads

19

Version

0.3.1

License

MIT

Unpacked Size

10.3 kB

Total Files

6

Last publish

Collaborators

  • vdsabev