Releases: lukeed/regexparam
v3.0.0
Breaking
-
Optional wildcard patterns are now fully supported! (#25): 422f630, 5362fba
Previously, an optional wildcard pattern would parse but it didn't behave correctly.
Essentially the "optional" part (?
) was ignored, meaning that optional wildcards were no different than wildcards.
This has been fixed (thanks @benmerckx), but doing so changed the generatedRegExp
(and thus, the matching behavior) for the optional wildcard pattern use case.All other usage is unaffected!
The majority of use cases will see no difference βΒ especially since the previous behavior was unwanted/unexpected anyway.let { pattern } = parse('/users/*?'); // Before: pattern.test('/users'); //=> false << wonky β pattern.test('/users/'); //=> true pattern.test('/users/123'); //=> true // After: pattern.test('/users'); //=> true << YAY β pattern.test('/users/'); //=> true pattern.test('/users/123'); //=> true
-
Renamed the reserved wildcard key (for wildcard value segment) from
wild
to*
:
This allows users to now construct named route patterns using the "wild" placeholder// Before: parse("/books/:genre/*"); //=> { keys: ["genre", "wild"], ... } parse("/:wild"); //=> { keys: ["wild"], ... } // ^^ this meant a named parameter would present like a wildcard, bad! β // After: parse("/books/:genre/*"); //=> { keys: ["genre", "*"], ... } parse("/:wild"); //=> { keys: ["wild"], ... } // ^^ this allows named parameter to look like a named parameter, good! β
Features
- Support optional wildcards (#25): 5362fba
Thank you @benmerckx~!
Chores
- Update module size: 4ee42b4
Full Changelog: v2.0.2...v3.0.0
v2.0.2
v2.0.1
v2.0.0
Breaking
-
Convert
default
export to namedparse
export: d439b9c
Important: No functionality has changed! Simply -how- it's imported-- import regexparam from 'regexparam'; ++ import { parse } from 'regexparam';
-
Require Node 8.x minimum runtime: bc36b93
Previously required Node 6.x
Features
-
Support native ESM imports via "exports" mapping: f2604b2
Note: This is potentially breaking for users of Node 13.0 thru 13.7 β upgrade! All of Node 13.x is officially obsolete!Conditional exports were defined, which means that CommonJS usage is still supported.
-
Added new
inject
function: 9c1a166, 3958c19, 3579e63
Convenience function for injecting values into a route pattern string.
Note: This is fully tree-shakable! Your bundle won't include it if you don't use it.import { inject } from 'regexparam'; inject('/users/:id', { id: 'lukeed' }); //=> '/users/lukeed' inject('/movies/:title.mp4', { title: 'narnia' }); //=> '/movies/narnia.mp4' inject('/:foo/:bar?/:baz?', { foo: 'aaa' }); //=> '/aaa' inject('/:foo/:bar?/:baz?', { foo: 'aaa', baz: 'ccc' }); //=> '/aaa/ccc' inject('/posts/:slug/*', { slug: 'hello', }); //=> '/posts/hello' inject('/posts/:slug/*', { slug: 'hello', wild: 'x/y/z', }); //=> '/posts/hello/x/y/z' // Missing non-optional value // ~> keeps the pattern in output inject('/hello/:world', { abc: 123 }); //=> '/hello/:world'
Chores
v1.3.0
Features
Chores
v1.2.2
v1.2.1
v1.2.0
Features
-
Add
loose
parameter, allowing theRegExp
to match URLs that would otherwise be too long: 8b292f8const rgx = require('regexparam'); rgx('/users').pattern.test('/users/lukeed'); //=> false rgx('/users', true).pattern.test('/users/lukeed'); //=> true rgx('/users/:name').pattern.test('/users/lukeed/repos'); //=> false rgx('/users/:name', true).pattern.test('/users/lukeed/repos'); //=> true
Chores
v1.1.1
v1.1.0
Features
-
Added suffix support for parameter matching: 0896539
const regexparam = require('regexparam'); const myURL = '/movies/narnia.mp4'; // Before: let old = regexparam('/movies/:title'); exec(myURL, old); //=> { title: 'narnia.mp4' } // Now have to parse this String, remove ".mp4", etc // Except, maybe I didn't want to allow MP4 files at all? // After: let now = regexparam('/movies/:title.mp4'); exec(myURL, now); //=> { title: 'narnia' }
This is great because my pattern can exclude file extensions (or whatever) that I don't want to permit. In this case, the URL
"/movies/narnia.mov"
won't match the pattern, and so it will be ignored entirely.I can also define a group of suffices to allow.
Let's change the example to allow MP4 and MOV files:// After (v2): let now = regexparam('/movies/:title.(mp4|mov)'); exec('/movies/narnia.mp4', now); //=> { title: 'narnia' } exec('/movies/narnia.mov', now); //=> { title: 'narnia' } exec('/movies/narnia.wav', now); //=> {} (no match)