@nyaomaru/divider 2.0.4 → 2.0.6

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.
package/dist/index.cjs CHANGED
@@ -122,10 +122,7 @@ function isNoneMode(value) {
122
122
  function normalizeSeparators(separators) {
123
123
  return Array.from(new Set(separators)).filter(
124
124
  (separator) => !isEmptyString(separator)
125
- ).sort((left, right) => right.length - left.length);
126
- }
127
- function createCacheKey(normalizedSeparators) {
128
- return normalizedSeparators.join(CACHE_KEY_SEPARATOR);
125
+ );
129
126
  }
130
127
  var RegexCache = class {
131
128
  cache = /* @__PURE__ */ new Map();
@@ -141,15 +138,6 @@ var RegexCache = class {
141
138
  */
142
139
  get(separators) {
143
140
  const key = this.createKey(separators);
144
- return this.getByKey(key);
145
- }
146
- /**
147
- * Retrieves a cached RegExp for a precomputed cache key.
148
- *
149
- * @param key - Cache key string
150
- * @returns Cached RegExp or null if not found
151
- */
152
- getByKey(key) {
153
141
  const regex = this.cache.get(key);
154
142
  if (regex) {
155
143
  this.cache.delete(key);
@@ -165,15 +153,6 @@ var RegexCache = class {
165
153
  */
166
154
  set(separators, regex) {
167
155
  const key = this.createKey(separators);
168
- this.setByKey(key, regex);
169
- }
170
- /**
171
- * Stores a RegExp in the cache for a precomputed cache key.
172
- *
173
- * @param key - Cache key string
174
- * @param regex - Compiled RegExp to cache
175
- */
176
- setByKey(key, regex) {
177
156
  if (this.cache.has(key)) {
178
157
  this.cache.delete(key);
179
158
  }
@@ -194,7 +173,7 @@ var RegexCache = class {
194
173
  */
195
174
  createKey(separators) {
196
175
  const normalizedSeparators = normalizeSeparators(separators);
197
- return createCacheKey(normalizedSeparators);
176
+ return normalizedSeparators.join(CACHE_KEY_SEPARATOR);
198
177
  }
199
178
  /**
200
179
  * Gets current cache size for debugging/monitoring.
@@ -215,16 +194,15 @@ var RegexCache = class {
215
194
  var regexCache = new RegexCache();
216
195
  function getRegex(separators) {
217
196
  if (isEmptyArray(separators)) return null;
197
+ const cached = regexCache.get(separators);
198
+ if (cached) return cached;
218
199
  const uniqueSeparators = normalizeSeparators(separators);
219
200
  if (uniqueSeparators.length === 0) {
220
201
  return null;
221
202
  }
222
- const cacheKey = createCacheKey(uniqueSeparators);
223
- const cached = regexCache.getByKey(cacheKey);
224
- if (cached) return cached;
225
203
  const pattern = uniqueSeparators.map(escapeRegExp).join("|");
226
204
  const regex = new RegExp(`(?:${pattern})`, "g");
227
- regexCache.setByKey(cacheKey, regex);
205
+ regexCache.set(separators, regex);
228
206
  return regex;
229
207
  }
230
208
  function escapeRegExp(str) {
@@ -575,27 +553,8 @@ function tryExtractQuery(input) {
575
553
  const url = new URL(input);
576
554
  return url.search.startsWith(QUERY_SEPARATORS.QUESTION_MARK) ? url.search.slice(1) : url.search;
577
555
  } catch {
578
- return extractQueryFromQuestionMark(input);
579
- }
580
- }
581
- function extractQueryFromQuestionMark(input) {
582
- const fragmentIndex = input.indexOf("#");
583
- const withoutFragment = fragmentIndex >= 0 ? input.slice(0, fragmentIndex) : input;
584
- const questionMarkIndex = withoutFragment.indexOf(
585
- QUERY_SEPARATORS.QUESTION_MARK
586
- );
587
- if (questionMarkIndex < 0) {
588
- return withoutFragment;
589
- }
590
- if (questionMarkIndex === 0) {
591
- return withoutFragment.slice(1);
592
- }
593
- const prefix = withoutFragment.slice(0, questionMarkIndex);
594
- const hasQuerySeparatorBefore = prefix.includes(QUERY_SEPARATORS.AMPERSAND) || prefix.includes(QUERY_SEPARATORS.EQUALS);
595
- if (hasQuerySeparatorBefore) {
596
- return withoutFragment;
556
+ return input;
597
557
  }
598
- return withoutFragment.slice(questionMarkIndex + 1);
599
558
  }
600
559
  function stripLeadingQuestionMark(query) {
601
560
  return query.startsWith(QUERY_SEPARATORS.QUESTION_MARK) ? query.slice(1) : query;
package/dist/index.js CHANGED
@@ -88,10 +88,7 @@ function isNoneMode(value) {
88
88
  function normalizeSeparators(separators) {
89
89
  return Array.from(new Set(separators)).filter(
90
90
  (separator) => !isEmptyString(separator)
91
- ).sort((left, right) => right.length - left.length);
92
- }
93
- function createCacheKey(normalizedSeparators) {
94
- return normalizedSeparators.join(CACHE_KEY_SEPARATOR);
91
+ );
95
92
  }
96
93
  var RegexCache = class {
97
94
  cache = /* @__PURE__ */ new Map();
@@ -107,15 +104,6 @@ var RegexCache = class {
107
104
  */
108
105
  get(separators) {
109
106
  const key = this.createKey(separators);
110
- return this.getByKey(key);
111
- }
112
- /**
113
- * Retrieves a cached RegExp for a precomputed cache key.
114
- *
115
- * @param key - Cache key string
116
- * @returns Cached RegExp or null if not found
117
- */
118
- getByKey(key) {
119
107
  const regex = this.cache.get(key);
120
108
  if (regex) {
121
109
  this.cache.delete(key);
@@ -131,15 +119,6 @@ var RegexCache = class {
131
119
  */
132
120
  set(separators, regex) {
133
121
  const key = this.createKey(separators);
134
- this.setByKey(key, regex);
135
- }
136
- /**
137
- * Stores a RegExp in the cache for a precomputed cache key.
138
- *
139
- * @param key - Cache key string
140
- * @param regex - Compiled RegExp to cache
141
- */
142
- setByKey(key, regex) {
143
122
  if (this.cache.has(key)) {
144
123
  this.cache.delete(key);
145
124
  }
@@ -160,7 +139,7 @@ var RegexCache = class {
160
139
  */
161
140
  createKey(separators) {
162
141
  const normalizedSeparators = normalizeSeparators(separators);
163
- return createCacheKey(normalizedSeparators);
142
+ return normalizedSeparators.join(CACHE_KEY_SEPARATOR);
164
143
  }
165
144
  /**
166
145
  * Gets current cache size for debugging/monitoring.
@@ -181,16 +160,15 @@ var RegexCache = class {
181
160
  var regexCache = new RegexCache();
182
161
  function getRegex(separators) {
183
162
  if (isEmptyArray(separators)) return null;
163
+ const cached = regexCache.get(separators);
164
+ if (cached) return cached;
184
165
  const uniqueSeparators = normalizeSeparators(separators);
185
166
  if (uniqueSeparators.length === 0) {
186
167
  return null;
187
168
  }
188
- const cacheKey = createCacheKey(uniqueSeparators);
189
- const cached = regexCache.getByKey(cacheKey);
190
- if (cached) return cached;
191
169
  const pattern = uniqueSeparators.map(escapeRegExp).join("|");
192
170
  const regex = new RegExp(`(?:${pattern})`, "g");
193
- regexCache.setByKey(cacheKey, regex);
171
+ regexCache.set(separators, regex);
194
172
  return regex;
195
173
  }
196
174
  function escapeRegExp(str) {
@@ -541,27 +519,8 @@ function tryExtractQuery(input) {
541
519
  const url = new URL(input);
542
520
  return url.search.startsWith(QUERY_SEPARATORS.QUESTION_MARK) ? url.search.slice(1) : url.search;
543
521
  } catch {
544
- return extractQueryFromQuestionMark(input);
545
- }
546
- }
547
- function extractQueryFromQuestionMark(input) {
548
- const fragmentIndex = input.indexOf("#");
549
- const withoutFragment = fragmentIndex >= 0 ? input.slice(0, fragmentIndex) : input;
550
- const questionMarkIndex = withoutFragment.indexOf(
551
- QUERY_SEPARATORS.QUESTION_MARK
552
- );
553
- if (questionMarkIndex < 0) {
554
- return withoutFragment;
555
- }
556
- if (questionMarkIndex === 0) {
557
- return withoutFragment.slice(1);
558
- }
559
- const prefix = withoutFragment.slice(0, questionMarkIndex);
560
- const hasQuerySeparatorBefore = prefix.includes(QUERY_SEPARATORS.AMPERSAND) || prefix.includes(QUERY_SEPARATORS.EQUALS);
561
- if (hasQuerySeparatorBefore) {
562
- return withoutFragment;
522
+ return input;
563
523
  }
564
- return withoutFragment.slice(questionMarkIndex + 1);
565
524
  }
566
525
  function stripLeadingQuestionMark(query) {
567
526
  return query.startsWith(QUERY_SEPARATORS.QUESTION_MARK) ? query.slice(1) : query;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@nyaomaru/divider",
3
3
  "type": "module",
4
- "version": "2.0.4",
4
+ "version": "2.0.6",
5
5
  "description": "To divide string or string[] with a given separator",
6
6
  "main": "./dist/index.cjs",
7
7
  "module": "./dist/index.js",