@redhare/utils
v0.0.2
Published
Utils for @infra-node-kit.
Downloads
3
Keywords
Readme
@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-regexptargetPath
is the path that needs to judgeoptions
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)
})