UNPKG

667 BJavaScriptView Raw
1'use strict';
2
3var map = require('../utilities/map');
4
5/**
6 * Internal: builds extensions based on parameters passed onto `.use()`.
7 *
8 * buildExtensions({ 'users.*': props })
9 * // => [ /^users\.[^.]+$/, props ]
10 */
11
12module.exports = function buildExtensions(keypath, extensions) {
13 var prefix = keypath.length ? keypath.join('.') + '.' : '';
14 return map(extensions, function (properties, keypath) {
15 keypath = (prefix + keypath).replace(/\./g, '\\.').replace(/\*\*/g, '::all::').replace(/\*/g, '::any::').replace(/::all::/g, '.*').replace(/::any::/g, '[^\.]+');
16
17 keypath = new RegExp('^' + keypath + '$');
18 return [keypath, properties];
19 });
20};
\No newline at end of file