Skip to content

Commit

Permalink
Allow standalone modifiers
Browse files Browse the repository at this point in the history
  • Loading branch information
blakeembrey committed May 20, 2024
1 parent 0b3aba6 commit 8b4d1fb
Show file tree
Hide file tree
Showing 2 changed files with 85 additions and 0 deletions.
73 changes: 73 additions & 0 deletions src/index.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1698,6 +1698,79 @@ const TESTS: Test[] = [
],
[[{ 0: "test" }, "/test"]],
],
/**
* Standalone modifiers.
*/
[
"/*",
undefined,
[
"/",
{
name: 0,
prefix: "",
suffix: "",
modifier: "",
pattern: ".*",
},
],
[
["/", ["/", ""]],
["/route", ["/route", "route"]],
["/route/nested", ["/route/nested", "route/nested"]],
],
[
[{ 0: "" }, "/"],
[{ 0: "123" }, "/123"],
],
],
[
"/+",
undefined,
[
"/",
{
name: 0,
prefix: "",
suffix: "",
modifier: "",
pattern: ".+",
},
],
[
["/", null],
["/x", ["/x", "x"]],
["/route", ["/route", "route"]],
],
[
[{ 0: "" }, null],
[{ 0: "x" }, "/x"],
[{ 0: "xyz" }, "/xyz"],
],
],
[
"/?",
undefined,
[
"/",
{
name: 0,
prefix: "",
suffix: "",
modifier: "",
pattern: ".?",
},
],
[
["/", ["/", ""]],
["/x", ["/x", "x"]],
["/route", null],
],
[
[{ 0: "" }, "/"],
[{ 0: "x" }, "/x"],
],
],

/**
* Regexps.
Expand Down
12 changes: 12 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,18 @@ export function parse(str: string, options: ParseOptions = {}): Token[] {
continue;
}

const modifier = tokens.tryConsume("MODIFIER");
if (modifier) {
result.push({
name: key++,
prefix: "",
suffix: "",
pattern: `.${modifier}`,
modifier: "",
});
continue;
}

tokens.consume("END");
break;
} while (true);
Expand Down

0 comments on commit 8b4d1fb

Please sign in to comment.