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)