UNPKG

1.88 kBJavaScriptView Raw
1"use strict";
2
3Object.defineProperty(exports, "__esModule", {
4 value: true
5});
6exports["default"] = void 0;
7
8var _LRUCache = _interopRequireDefault(require("./LRUCache"));
9
10function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
11
12function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
13
14function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
15
16function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
17
18// A cache for frequently used country-specific regular expressions. Set to 32 to cover ~2-3
19// countries being used for the same doc with ~10 patterns for each country. Some pages will have
20// a lot more countries in use, but typically fewer numbers for each so expanding the cache for
21// that use-case won't have a lot of benefit.
22var RegExpCache =
23/*#__PURE__*/
24function () {
25 function RegExpCache(size) {
26 _classCallCheck(this, RegExpCache);
27
28 this.cache = new _LRUCache["default"](size);
29 }
30
31 _createClass(RegExpCache, [{
32 key: "getPatternForRegExp",
33 value: function getPatternForRegExp(pattern) {
34 var regExp = this.cache.get(pattern);
35
36 if (!regExp) {
37 regExp = new RegExp('^' + pattern);
38 this.cache.put(pattern, regExp);
39 }
40
41 return regExp;
42 }
43 }]);
44
45 return RegExpCache;
46}();
47
48exports["default"] = RegExpCache;
49//# sourceMappingURL=RegExpCache.js.map
\No newline at end of file