Skip to content

Commit 43cbe49

Browse files
committed
Add trailing option back
1 parent acf5193 commit 43cbe49

File tree

2 files changed

+7
-1
lines changed

2 files changed

+7
-1
lines changed

Readme.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ The `match` function returns a function for transforming paths into parameters:
6868
- **options** _(optional)_ (See [parse](#parse) for more options)
6969
- **sensitive** Regexp will be case sensitive. (default: `false`)
7070
- **end** Validate the match reaches the end of the string. (default: `true`)
71+
- **trailing** Allows optional trailing delimiter to match. (default: `true`)
7172
- **decode** Function for decoding strings to params, or `false` to disable all processing. (default: `decodeURIComponent`)
7273

7374
```js

src/index.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,10 @@ export interface MatchOptions extends PathOptions {
4141
* Matches the path completely without trailing characters. (default: `true`)
4242
*/
4343
end?: boolean;
44+
/**
45+
* Allows optional trailing delimiter to match. (default: `true`)
46+
*/
47+
trailing?: boolean;
4448
}
4549

4650
export interface CompileOptions extends PathOptions {
@@ -483,12 +487,13 @@ export function $match<P extends ParamData>(
483487
data: TokenData,
484488
options: MatchOptions = {},
485489
): MatchFunction<P> {
486-
const { decode = decodeURIComponent, end = true } = options;
490+
const { decode = decodeURIComponent, end = true, trailing = true } = options;
487491
const { tokens, delimiter } = data;
488492
const flags = toFlags(options);
489493
const [source, keys] = toRegExp(tokens, delimiter);
490494

491495
let pattern = `^${source}`;
496+
if (trailing) pattern += `(?:${escape(delimiter)})?`;
492497
pattern += end ? "$" : `(?=${escape(delimiter)}|$)`;
493498
const re = new RegExp(pattern, flags);
494499

0 commit comments

Comments
 (0)