How to use path-to-regexp

Comprehensive path-to-regexp code examples:

How to use path-to-regexp.match:

248
249
250
251
252
253
254
255
256
257
  // console.log('testPath', path);
  const arr = path
    .split(',')
    .map(x => x.trim())
    .filter(Boolean)
    .filter(path => pathToReg.match(path))
    .map(x => '/' + x.replace(/(^\/|\/$)/g, ''));
  return arr.length > 1 ? arr : arr.pop();
}

How to use path-to-regexp.parse:

2
3
4
5
6
7
8
9
10
11
12
13
// const cron = require("node-cron");


// const { pathToRegexp, match, parse, compile } = require("path-to-regexp");
// pathToRegexp(path, keys?, options?)
// match(path)
// parse(path)
// compile(path)


const app = express();

How to use path-to-regexp.compile:

42
43
44
45
46
47
48
49
50
51
const selectedMailIds = useSelector(({ mailApp }) => mailApp.mails.selectedMailIds);
const labels = useSelector(selectLabelsEntities);
const routeParams = useParams();

const classes = useStyles(props);
const toPath = pathToRegexp.compile(props.match.path);
const checked = selectedMailIds.length > 0 && selectedMailIds.find(id => id === props.mail.id) !== undefined;

return (
	<ListItem

How to use path-to-regexp.pathToRegexp:

233
234
235
236
237
238
239
240
241

if (typeof reducer === 'string' || path) {
    const usePath = path || reducer;
    resolverPath = this._normalizePath(usePath);
    resolverPath = resolverPath.replace(/\*/g, '(.*)');
    const pathMatch = pathToRegexp(resolverPath, [], { end: resolverPath === '' });

    reduce = (req, res, relativePostBack, pathContext, action) => {
        const actionMatches = action && (resolverPath === '/*' || pathMatch.exec(action));