@stndrds/schema 1.0.0-alpha.89 → 1.0.0-alpha.90

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -2,6 +2,45 @@
2
2
  import { isValidIso3 } from "@stndrds/constants";
3
3
  import { z } from "zod";
4
4
 
5
+ // src/lib/lru-cache.ts
6
+ var LRUCache = class {
7
+ constructor(capacity) {
8
+ if (capacity <= 0) {
9
+ throw new Error("LRU cache capacity must be greater than 0");
10
+ }
11
+ this.capacity = capacity;
12
+ this.cache = /* @__PURE__ */ new Map();
13
+ }
14
+ get(key) {
15
+ const value = this.cache.get(key);
16
+ if (value !== void 0) {
17
+ this.cache.delete(key);
18
+ this.cache.set(key, value);
19
+ }
20
+ return value;
21
+ }
22
+ set(key, value) {
23
+ if (this.cache.has(key)) {
24
+ this.cache.delete(key);
25
+ } else if (this.cache.size >= this.capacity) {
26
+ const firstKey = this.cache.keys().next().value;
27
+ if (firstKey !== void 0) {
28
+ this.cache.delete(firstKey);
29
+ }
30
+ }
31
+ this.cache.set(key, value);
32
+ }
33
+ has(key) {
34
+ return this.cache.has(key);
35
+ }
36
+ clear() {
37
+ this.cache.clear();
38
+ }
39
+ get size() {
40
+ return this.cache.size;
41
+ }
42
+ };
43
+
5
44
  // src/phone-utils.ts
6
45
  import { getCountryByIso3, stripTrunkPrefix } from "@stndrds/constants";
7
46
  import { parsePhoneNumberFromString } from "libphonenumber-js";
@@ -81,7 +120,7 @@ function parseRawPhoneInput(rawInput, countryIso3) {
81
120
  }
82
121
 
83
122
  // src/validation/validators.ts
84
- var regexPatternCache = /* @__PURE__ */ new Map();
123
+ var regexPatternCache = new LRUCache(100);
85
124
  function getCachedRegex(pattern) {
86
125
  let cached = regexPatternCache.get(pattern);
87
126
  if (!cached) {
@@ -2,6 +2,45 @@
2
2
  var _constants = require('@stndrds/constants');
3
3
  var _zod = require('zod');
4
4
 
5
+ // src/lib/lru-cache.ts
6
+ var LRUCache = class {
7
+ constructor(capacity) {
8
+ if (capacity <= 0) {
9
+ throw new Error("LRU cache capacity must be greater than 0");
10
+ }
11
+ this.capacity = capacity;
12
+ this.cache = /* @__PURE__ */ new Map();
13
+ }
14
+ get(key) {
15
+ const value = this.cache.get(key);
16
+ if (value !== void 0) {
17
+ this.cache.delete(key);
18
+ this.cache.set(key, value);
19
+ }
20
+ return value;
21
+ }
22
+ set(key, value) {
23
+ if (this.cache.has(key)) {
24
+ this.cache.delete(key);
25
+ } else if (this.cache.size >= this.capacity) {
26
+ const firstKey = this.cache.keys().next().value;
27
+ if (firstKey !== void 0) {
28
+ this.cache.delete(firstKey);
29
+ }
30
+ }
31
+ this.cache.set(key, value);
32
+ }
33
+ has(key) {
34
+ return this.cache.has(key);
35
+ }
36
+ clear() {
37
+ this.cache.clear();
38
+ }
39
+ get size() {
40
+ return this.cache.size;
41
+ }
42
+ };
43
+
5
44
  // src/phone-utils.ts
6
45
 
7
46
  var _libphonenumberjs = require('libphonenumber-js');
@@ -81,7 +120,7 @@ function parseRawPhoneInput(rawInput, countryIso3) {
81
120
  }
82
121
 
83
122
  // src/validation/validators.ts
84
- var regexPatternCache = /* @__PURE__ */ new Map();
123
+ var regexPatternCache = new LRUCache(100);
85
124
  function getCachedRegex(pattern) {
86
125
  let cached = regexPatternCache.get(pattern);
87
126
  if (!cached) {