@suzulabo/path-matcher
TypeScript icon, indicating that this package has built-in type declarations

0.0.0 • Public • Published

@suzulabo/path-matcher

Install

pnpm add @suzulabo/path-matcher

Example

type RouteMatch = Match & {
  tag: string;
};

const matches: RouteMatch[] = [
  {
    pattern: '',
    tag: 'index',
  },
  {
    pattern: 'about',
    tag: 'about',
  },
  {
    pattern: /^[0-9A-Z]{5}$/,
    tag: 'post',
    name: 'postID',
    nexts: [
      {
        pattern: /^[0-9]{4}$/,
        tag: 'comment',
        name: 'commentID',
      },
    ],
  },
];

const path = '/ABC12/0001';
const m = pathMatcher(matches, path);
if (m) {
  assert(m.match.tag == 'comment');
  assert(m.params['postID'] == 'ABC12');
  assert(m.params['commentID'] == '0001');
}

Readme

Keywords

Package Sidebar

Install

npm i @suzulabo/path-matcher

Weekly Downloads

1

Version

0.0.0

License

Apache-2.0

Unpacked Size

14.3 kB

Total Files

5

Last publish

Collaborators

  • suzulabo