// and therefore userId is of type number
userId: PARAM_PARSER_INT,
},
- ['profiles', 0]
+ ['profiles', 1]
),
})
// all defaults
teamId: {},
},
- ['teams', 0, 'b']
+ ['teams', 1, 'b']
)
expect(pattern.match('/teams/123/b')).toEqual({
{
teamId: {},
},
- ['teams', 0]
+ ['teams', 1]
)
expect(pattern.match('/teams/a%20b')).toEqual({ teamId: 'a b' })
expect(pattern.build({ teamId: 'a b' })).toBe('/teams/a%20b')
{
teamId: {},
},
- ['teams', 0, 'b']
+ ['teams', 1, 'b']
)
expect(pattern.match('/teams/b')).toEqual({ teamId: null })
{
teamId: {},
},
- ['teams', 0, 'b']
+ ['teams', 1, 'b']
)
expect(pattern.match('/teams/b')).toEqual({ teamId: null })
{
teamId: { repeat: true },
},
- ['teams', 0, 'b']
+ ['teams', 1, 'b']
)
expect(pattern.match('/teams/123/b')).toEqual({ teamId: ['123'] })
{
pathMatch: {},
},
- ['teams', 1]
+ ['teams', 0]
)
expect(pattern.match('/teams/')).toEqual({ pathMatch: '' })
expect(pattern.match('/teams/123/b')).toEqual({ pathMatch: '123/b' })
{
teamId: { repeat: true },
},
- ['teams', 0, 'b']
+ ['teams', 1, 'b']
)
expect(pattern.match('/teams/123/b')).toEqual({ teamId: ['123'] })
teamId: {},
otherId: {},
},
- ['teams', 0, 0]
+ ['teams', 1, 1]
)
expect(pattern.match('/teams/123/456')).toEqual({
teamId: {},
otherId: {},
},
- ['teams', [0, '-b-', 0]]
+ ['teams', [1, '-b-', 1]]
)
expect(pattern.match('/teams/123-b-456')).toEqual({
{
teamId: {},
},
- ['teams', [0, '/']]
+ ['teams', [1, '/']]
)
expect(pattern.match('/teams/123/')).toEqual({
{
teamId: { repeat: true },
},
- ['teams', [0, '/']]
+ ['teams', [1, '/']]
)
expect(pattern.match('/teams/123/')).toEqual({ teamId: ['123'] })
{
teamId: { repeat: true },
},
- ['teams', [0, '/']]
+ ['teams', [1, '/']]
)
expect(pattern.match('/teams/123/')).toEqual({ teamId: ['123'] })
const matcher = new MatcherPatternPathDynamic(
/^\/users\/([^/]+)$/i,
{ userId: { ...PATH_PARAM_PARSER_DEFAULTS } },
- ['users', 0]
+ ['users', 1]
)
expectTypeOf(matcher.match('/users/123')).toEqualTypeOf<{
const matcher = new MatcherPatternPathDynamic(
/^\/users\/([^/]+)\/([^/]+)$/i,
{ userId: { ...PATH_PARAM_SINGLE_DEFAULT, repeat: true } },
- ['users', 0]
+ ['users', 1]
)
expectTypeOf(matcher.match('/users/123/456')).toEqualTypeOf<{
userId: string
// parser: PATH_PARAM_DEFAULT_PARSER,
},
},
- ['profiles', 0]
+ ['profiles', 1]
)
expectTypeOf(matcher.match('/profiles/2')).toEqualTypeOf<{
// otherwise, we need to use a factory function: https://github.com/microsoft/TypeScript/issues/40451
readonly params: TParamsOptions &
Record<string, MatcherPatternPathDynamic_ParamOptions<any, any>>,
- // 0 means a regular param, 1 means a splat, the order comes from the keys in params
+ // 1 means a regular param, 0 means a splat, the order comes from the keys in params
readonly pathParts: Array<string | number | Array<string | number>>
) {
this.paramsKeys = Object.keys(this.params) as Array<keyof TParamsOptions>
return Array.isArray(value)
? value.map(encodeParam).join('/')
- : // part == 0 means a regular param, 1 means a splat
- (part /* part !== 0 */ ? encodePath : encodeParam)(value)
+ : // part == 1 means a regular param, 0 means a splat
+ (part ? encodeParam : encodePath)(value)
} else {
return part
.map(subPart => {
* with the original splat path: e.g. /teams/[...pathMatch] does not match /teams, so it makes
* no sense to build a path it cannot match.
*/
- return lastParamPart && !value ? path + '/' : path
+ return !lastParamPart /** lastParamPart == 0 */ && !value
+ ? path + '/'
+ : path
}
}
const paramMatcher = new MatcherPatternPathDynamic(
/^\/p\/([^/]+)$/,
{ p: {} },
- ['p', 0]
+ ['p', 1]
)
const optionalMatcher = new MatcherPatternPathDynamic(
/^\/optional(?:\/([^/]+))?$/,
{ p: {} },
- ['optional', 0]
+ ['optional', 1]
)
const repeatMatcher = new MatcherPatternPathDynamic(
/^\/repeat\/(.+)$/,
{ r: { repeat: true } },
- ['repeat', 1]
+ ['repeat', 0]
)
const catchAllMatcher = new MatcherPatternPathDynamic(
/^\/(.*)$/,
{ pathMatch: { repeat: true } },
- [1]
+ [0]
)
// Create experimental route records using proper structure
const testCatchAllMatcher = new MatcherPatternPathDynamic(
/^\/(.*)$/,
{ pathMatch: { repeat: true } },
- [1]
+ [0]
)
const catchAllRecord = normalizeRouteRecord({
name: 'notfound',