url-id-replace
Replace things like IDs and other regexes in a URL path with a placeholder
Sample Usage
const parse = ; console; // /users/*console; // /users/*/
Built-in Matchers
A few common matchers are already provided:
const builtInMatchers = urlIdReplace;// Returns an object that looks like this: digits: ... // Regex for matching only digits uuid: // Regex for matching only UUIDs hexLowercase: ... // Regex for matching only lowercase hex values that are at least 7 characters hexUppercase: ... // Regex for matching only uppercase hex values that are at least 7 chracters iso8061: ... // Regex for matching ISO8061 timestamp values
Currently, only digits
and uuid
are included in the list of default matchers. (IE: if you use
the default parameters when building the parser.) The others are provided for your convenience if
you need them. Simply follow the next step for adding custom matchers.
Custom Matchers
Custom matchers are regexes that can be specified when the parser is created
const parse = matchers: /^ITEM-\d*$/;console; // /items/*/locationconsole; // items/123 -- the default matchers were overwritten
This will override the default matchers. The default matchers are still available if you need them
by calling getDefaultMatchers()
. This returns an array of the default RegExps, to which you can
then add other matchers:
const urlIdReplace = ;const parse = ;console; // /items/*/locationconsole; // items/*
You can include the built-in matchers in a similar way:
const urlIdReplace = ;const parse = ;console; // /items/*/location
Changing the Placeholder
Instead of *
, you can specify any string you want to be used for matches:
const parse = placeholder: 'X';console; // items/X/location/