Regexparam Versions Save

A tiny (394B) utility that converts route patterns into RegExp. Limited alternative to `path-to-regexp` 🙇‍♂️

v3.0.0

5 months ago

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

  • Support optional wildcards (#25): 5362fba Thank you @benmerckx~!

Chores

  • Update module size: 4ee42b4

Full Changelog: https://github.com/lukeed/regexparam/compare/v2.0.2...v3.0.0

v2.0.2

5 months ago

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: https://github.com/lukeed/regexparam/compare/v2.0.1...v2.0.2

v2.0.1

1 year ago

Patches

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

Chores

  • Consistent spacing in test file (#15): c362f46 Thank you @yuler~!
  • Handle Node16+ error message text assertion in tests (#23): d841bef Thank you @daaku~!
  • Add Node 16 to CI test matrix: f1db5bf

Full Changelog: https://github.com/lukeed/regexparam/compare/v2.0.0...v2.0.1

v2.0.0

3 years ago

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

  • Move CI to Github Actions: a388962, 88c3223
  • Use uvu for test runner: 76a7d1d
  • Use c8 for test coverage: 5126f71
  • Update .gitignore patterns: 1524a64
  • Rename type definition file: d94c507
  • Bump bundt version: 59a1f35
  • Update README docs: 7188552, 04d7131
  • Add Deno section to README: 83bbf70, aeaf512

v1.3.0

3 years ago

Features

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

Chores

  • Add tests for RegExp patterns: 7a4f933, d6d4c3b
  • Update type definitions for RegExp patterns: 0d0e89a
  • Add README docs for RegExp patterns: 0573304, dd056cb
  • Update TravisCI badge: 7cb22a8
  • Update module size: 061a70e

v1.2.2

4 years ago

Patches

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

v1.2.1

5 years ago

Features

  • Add TypeScript definitions: 9e4b215

v1.2.0

5 years ago

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

5 years ago

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

5 years ago

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

  • Update README example: 9c8f482
  • Update module size: fde3d65
  • Import build tool: 41e208d