RegExpCache.js 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637
  1. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  2. function _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); } }
  3. function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
  4. import LRUCache from './LRUCache.js'; // A cache for frequently used country-specific regular expressions. Set to 32 to cover ~2-3
  5. // countries being used for the same doc with ~10 patterns for each country. Some pages will have
  6. // a lot more countries in use, but typically fewer numbers for each so expanding the cache for
  7. // that use-case won't have a lot of benefit.
  8. var RegExpCache = /*#__PURE__*/function () {
  9. function RegExpCache(size) {
  10. _classCallCheck(this, RegExpCache);
  11. this.cache = new LRUCache(size);
  12. }
  13. _createClass(RegExpCache, [{
  14. key: "getPatternForRegExp",
  15. value: function getPatternForRegExp(pattern) {
  16. var regExp = this.cache.get(pattern);
  17. if (!regExp) {
  18. regExp = new RegExp('^' + pattern);
  19. this.cache.put(pattern, regExp);
  20. }
  21. return regExp;
  22. }
  23. }]);
  24. return RegExpCache;
  25. }();
  26. export { RegExpCache as default };
  27. //# sourceMappingURL=RegExpCache.js.map