Skip to content

Wildcard, unicode, and modifier changes

Compare
Choose a tag to compare
@blakeembrey blakeembrey released this 20 Jun 23:27
· 7 commits to master since this release
ec35fbd

Hi all! There's a few major breaking changes in this release so read carefully.

Breaking changes:

  • The function returned by compile only accepts strings as values (i.e. no numbers, use String(value) before compiling a path)
    • For repeated values, when encode !== false, it must be an array of strings
  • Parameter names can contain all unicode identifier characters (defined as regex \p{XID_Continue}).
  • Modifiers (?, *, +) must be used after a param explicitly wrapped in {}
    • No more implied prefix of / or .
  • No support for arrays or regexes as inputs
  • The wildcard (standalone *) has been added back and matches Express.js expected behavior
  • Removed endsWith option
  • Renamed strict: true to trailing: false
  • Reserved ;, ,, !, and @ for future use-cases
  • Removed tokensToRegexp, tokensToFunction and regexpToFunction in favor of simplifying exports
  • Enable a "loose" mode by default, so / can be repeated multiple times in a matched path (i.e. /foo works like //foo, etc)
  • encode and decode no longer receive the token as the second parameter
  • Removed the ESM + CommonJS dual package in favor of only one CommonJS supported export
  • Minimum JS support for ES2020 (previous ES2015)
  • Encode defaults to encodeURIComponent and decode defaults to decodeURIComponent

Added:

  • Adds encodePath to fix an issue around encode being used for both path and parameters (the path and parameter should be encoded slightly differently)
  • Adds loose as an option to support arbitrarily matching the delimiter in paths, e.g. foo/bar and foo///bar should work the same
  • Allow encode and decode to be set to false which skips all processing of the parameters input/output
  • All remaining methods support TokenData (exported, returned by parse) as input
    • This should be useful if you are programmatically building paths to match or want to avoid parsing multiple times

Requests for feedback:

  • Requiring {} is an obvious drawback but I'm seeking feedback on whether it helps make path behavior clearer
    • Related: Removing / and . as implicit prefixes
  • Removing array and regex support is to reduce the overall package size for things many users don't need
  • Unicode IDs are added to align more closely with browser URLPattern behavior, which uses JS identifiers

v6.2.2...v7.0.0