JSPM

tiny-path-matcher

0.1.0
  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 1
  • Score
    100M100P100Q15397F
  • License MIT

Tiny hierarchical path (tree node) matcher.

Package Exports

  • tiny-path-matcher

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (tiny-path-matcher) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

TinyPathMatcher

This is a tiny (~50 SLOC and and zero-dependency) hierarchical path (tree node) matcher.

npm version

Installation

npm install tiny-path-matcher

(Note: an ES2018+ESM-compatible environment is required.)

Getting started

import { PathNode } from 'tiny-path-matcher';

const rootPathNode  = new PathNode(),
  usersPathNode     = new PathNode('users');
  userPathNode      = new PathNode(/^user-(?<userId>\d+)$/, { description: 'User page' });

rootPathNode.push(usersPathNode);
usersPathNode.push(userPathNode);

let [ pathNode, groups ] = rootPathNode.match([ 'users', 'user-12' ]);
// assert.strictEqual(pathNode, userPathNode)
// assert.deepStrictEqual(grooups, { 'userId': '12' });

rootPathNode.match([ 'users', 'user-12' ]);  // === null

Example

See a full example here.

Author

Alexander Kurakin <kuraga333@mail.ru>

Inspired by

Feedback and contribute

https://github.com/kuraga/tiny-path-matcher/issues

License

MIT