@redhare/utils
TypeScript icon, indicating that this package has built-in type declarations

0.0.2 • Public • Published

@infra-node-kit/utils

Utils for @infra-node-kit.

isPathMatch

It is a method to judge whether a specific path match the paths rule.

function isPathMatch(
  paths: string[] | undefined | string,
  targetPath: string,
  options?: TokensToRegexpOptions & ParseOptions,
)
  • paths is a path rule array, can reference to path-to-regexp

  • targetPath is the path that needs to judge

  • options is optional, can reference to path-to-regexp

  • * is a special path rule that can match all the paths.

Examples, more detail

it('isPathMatch /:variable match one level ', () => {
  const paths = ['/:variable']
  expect(isPathMatch(paths, '/a')).toBe(true)
  expect(isPathMatch(paths, '/a/b')).toBe(false)
})
it('isPathMatch no query ', () => {
  const paths = ['/:variable']
  expect(isPathMatch(paths, '/a?a=123')).toBe(false)
})

Readme

Keywords

none

Package Sidebar

Install

npm i @redhare/utils

Weekly Downloads

5

Version

0.0.2

License

ISC

Unpacked Size

29.2 kB

Total Files

6

Last publish

Collaborators

  • tobywan
  • yann001
  • jiushu
  • keyunlei
  • zsynuting