Skip to content

Commit

Permalink
chore: readme wildcard vs optional-wildcard usage
Browse files Browse the repository at this point in the history
  • Loading branch information
lukeed committed Dec 3, 2023
1 parent 422f630 commit 5362fba
Showing 1 changed file with 3 additions and 11 deletions.
14 changes: 3 additions & 11 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ import { parse, inject } from 'regexparam';
// Example param-assignment
function exec(path, result) {
let i=0, out={};
let matches = result.pattern.exec(path) || [];
let matches = result.pattern.exec(path);
while (i < result.keys.length) {
out[ result.keys[i] ] = matches[++i] || null;
}
Expand Down Expand Up @@ -82,11 +82,7 @@ let baz = parse('users/*');

baz.pattern.test('/users'); //=> false
baz.pattern.test('/users/lukeed'); //=> true

exec('/users', baz);
//=> { wild: 'lukeed/repos/new' }
exec('/users/lukeed/repos/new', baz);
//=> { wild: 'lukeed/repos/new' }
baz.pattern.test('/users/'); //=> true


// Optional Wildcard
Expand All @@ -97,11 +93,7 @@ let baz = parse('/users/*?');

baz.pattern.test('/users'); //=> true
baz.pattern.test('/users/lukeed'); //=> true

exec('/users', baz);
//=> { wild: null }
exec('/users/lukeed/repos/new', baz);
//=> { wild: 'lukeed/repos/new' }
baz.pattern.test('/users/'); //=> true


// Injecting
Expand Down

0 comments on commit 5362fba

Please sign in to comment.