Skip to content

Releases: lukeed/regexparam

v3.0.0

03 Dec 21:56
Compare
Choose a tag to compare

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 generated RegExp (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

Chores


Full Changelog: v2.0.2...v3.0.0

v2.0.2

03 Dec 20:57
Compare
Choose a tag to compare

Patches

  • Remove unnecessary /*#__PURE__*/ comment (#28): 93708aa
    Fixed a warning when using recent Rollup/Vite versions

  • Add "default" export condition for Svelte users (#26): 57af4a5
    Not sure why πŸ˜… but can't hurt


Full Changelog: v2.0.1...v2.0.2

v2.0.1

02 Jul 15:05
Compare
Choose a tag to compare

Patches

  • Added types condition for TypeScript Node16 module resolution (#23): 25f6ebe
    Thank you @daaku~!

Chores


Full Changelog: v2.0.0...v2.0.1

v2.0.0

25 May 00:31
Compare
Choose a tag to compare

Breaking

  • Convert default export to named parse 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

23 May 18:27
Compare
Choose a tag to compare

Features

  • Allow custom RegExp patterns (#7): a4b91bb
  • Expose UMD format as the "unpkg" entry: 019729d

Chores

v1.2.2

22 Jun 21:50
Compare
Choose a tag to compare

Patches

  • (loose) Ensure pattern.exec excludes trailing slashes for matches[0] value (#5, #6): ab9db70

v1.2.1

12 Mar 18:05
Compare
Choose a tag to compare

Features

  • Add TypeScript definitions: 9e4b215

v1.2.0

10 Mar 00:02
Compare
Choose a tag to compare

Features

  • Add loose parameter, allowing the RegExp to match URLs that would otherwise be too long: 8b292f8

    const 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

  • Add loose test suite: 2ed86b2
  • Update "exec" tests, using false to describe no match: 934fc01
  • Update module size: 0e1f4fc

v1.1.1

09 Mar 23:12
Compare
Choose a tag to compare

Patches

  • Shaved 9 bytes by removing unnecessary non-capturing group: b90823f

Chores

  • Add test suite for parsing params output objects: 5617e75
    These ensure / lock-in the matching values for each route pattern.

v1.1.0

09 Mar 17:53
Compare
Choose a tag to compare

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)

Chores