diff options
Diffstat (limited to 'vnfmarket/src/main/webapp/vnfmarket/node_modules/regex-cache/index.js')
-rw-r--r-- | vnfmarket/src/main/webapp/vnfmarket/node_modules/regex-cache/index.js | 69 |
1 files changed, 69 insertions, 0 deletions
diff --git a/vnfmarket/src/main/webapp/vnfmarket/node_modules/regex-cache/index.js b/vnfmarket/src/main/webapp/vnfmarket/node_modules/regex-cache/index.js new file mode 100644 index 00000000..13d20226 --- /dev/null +++ b/vnfmarket/src/main/webapp/vnfmarket/node_modules/regex-cache/index.js @@ -0,0 +1,69 @@ +/*! + * regex-cache <https://github.com/jonschlinkert/regex-cache> + * + * Copyright (c) 2015 Jon Schlinkert. + * Licensed under the MIT license. + */ + +'use strict'; + +var isPrimitive = require('is-primitive'); +var equal = require('is-equal-shallow'); +var basic = {}; +var cache = {}; + +/** + * Expose `regexCache` + */ + +module.exports = regexCache; + +/** + * Memoize the results of a call to the new RegExp constructor. + * + * @param {Function} fn [description] + * @param {String} str [description] + * @param {Options} options [description] + * @param {Boolean} nocompare [description] + * @return {RegExp} + */ + +function regexCache(fn, str, opts) { + var key = '_default_', regex, cached; + + if (!str && !opts) { + if (typeof fn !== 'function') { + return fn; + } + return basic[key] || (basic[key] = fn(str)); + } + + var isString = typeof str === 'string'; + if (isString) { + if (!opts) { + return basic[str] || (basic[str] = fn(str)); + } + key = str; + } else { + opts = str; + } + + cached = cache[key]; + if (cached && equal(cached.opts, opts)) { + return cached.regex; + } + + memo(key, opts, (regex = fn(str, opts))); + return regex; +} + +function memo(key, opts, regex) { + cache[key] = {regex: regex, opts: opts}; +} + +/** + * Expose `cache` + */ + +module.exports.cache = cache; +module.exports.basic = basic; |