Skip to content

Commit

Permalink
Remove key from decode type
Browse files Browse the repository at this point in the history
  • Loading branch information
blakeembrey committed May 21, 2024
1 parent 55fbd02 commit 44a5141
Showing 1 changed file with 4 additions and 5 deletions.
9 changes: 4 additions & 5 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -409,7 +409,7 @@ export interface RegexpToFunctionOptions {
/**
* Function for decoding strings for params.
*/
decode?: (value: string, token: Key) => string;
decode?: (value: string) => string;
}

/**
Expand All @@ -424,11 +424,10 @@ export function regexpToFunction<P extends object = object>(
const decoders = keys.map((key) => {
if (key.split) {
const splitRe = new RegExp(key.split, "g");
return (value: string, key: Key) =>
value.split(splitRe).map((part) => decode(part, key));
return (value: string) => value.split(splitRe).map(decode);
}

return (value: string, key: Key) => decode(value, key);
return decode;
});

return function match(pathname: string) {
Expand All @@ -443,7 +442,7 @@ export function regexpToFunction<P extends object = object>(

const key = keys[i - 1];
const decoder = decoders[i - 1];
params[key.name] = decoder(m[i], key);
params[key.name] = decoder(m[i]);
}

return { path, index, params };
Expand Down

0 comments on commit 44a5141

Please sign in to comment.