0.0.2 • Published 8 months ago

@redhare/utils v0.0.2

Weekly downloads
-
License
ISC
Repository
-
Last release
8 months ago

@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)
})