1.0.6 • Published 3 years ago

@egoist/path-parser v1.0.6

Weekly downloads
-
License
MIT
Repository
-
Last release
3 years ago

@egoist/path-parser

This module is entirely extracted from vue-router, it's basically a light-weight version of path-to-regexp with path ranking support.

Install

npm i @egoist/path-parser

Usage

Create a path parser:

import { createParser } from '@egoist/path-parser'

const parser = createParser('/user/:user')

parser.parse('/user/egoist')
//=> { user: 'egoist' }
// `null` if not matched

Sort paths by ranking:

import { comparePathParserScore, createParser } from '@egoist/path-parser'

const paths = ['/:user', '/about']

paths.sort((a, b) => {
  return comparePathParserScore(createParser(a), createParser(b))
})
//=> [ '/about', '/:user' ]

Credits

The code is extracted from vue-router, all credits to its author @posva. The code might differ from the upstream in the future.

License

MIT © EGOIST

1.0.6

3 years ago

1.0.4

3 years ago

1.0.3

3 years ago

1.0.1

3 years ago

1.0.0

3 years ago