@nyaomaru/divider 1.8.11 → 1.8.12
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 +9 -7
- package/dist/index.js +9 -7
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -244,18 +244,20 @@ function generateIndexes(str, size, startOffset = 0) {
|
|
|
244
244
|
}
|
|
245
245
|
|
|
246
246
|
// src/core/divider-loop.ts
|
|
247
|
-
|
|
248
|
-
|
|
247
|
+
var MIN_ALLOWED_CHUNKS = 0;
|
|
248
|
+
function shouldTruncateChunks(chunks, maxChunks) {
|
|
249
|
+
return isNumber(maxChunks) && maxChunks > MIN_ALLOWED_CHUNKS && maxChunks < chunks.length;
|
|
249
250
|
}
|
|
250
|
-
function
|
|
251
|
+
function truncateChunksToMax(chunks, maxChunks) {
|
|
251
252
|
const headCount = maxChunks - 1;
|
|
252
253
|
const head = chunks.slice(0, headCount);
|
|
253
254
|
const tail = chunks.slice(headCount).join("");
|
|
254
255
|
return [...head, tail];
|
|
255
256
|
}
|
|
256
|
-
function
|
|
257
|
-
const
|
|
258
|
-
|
|
257
|
+
function createChunksFromString(str, size, startOffset, maxChunks) {
|
|
258
|
+
const indexes = generateIndexes(str, size, startOffset);
|
|
259
|
+
const chunks = divider(str, ...indexes);
|
|
260
|
+
return shouldTruncateChunks(chunks, maxChunks) ? truncateChunksToMax(chunks, maxChunks) : chunks;
|
|
259
261
|
}
|
|
260
262
|
function dividerLoop(input, size, options) {
|
|
261
263
|
if (!isPositiveInteger(size)) {
|
|
@@ -267,7 +269,7 @@ function dividerLoop(input, size, options) {
|
|
|
267
269
|
startOffset = PERFORMANCE_CONSTANTS.DEFAULT_START_OFFSET,
|
|
268
270
|
maxChunks = PERFORMANCE_CONSTANTS.DEFAULT_MAX_CHUNKS
|
|
269
271
|
} = finalOptions;
|
|
270
|
-
const result = isString(input) ?
|
|
272
|
+
const result = isString(input) ? createChunksFromString(input, size, startOffset, maxChunks) : input.map((str) => createChunksFromString(str, size, startOffset, maxChunks));
|
|
271
273
|
return applyDividerOptions(result, finalOptions);
|
|
272
274
|
}
|
|
273
275
|
|
package/dist/index.js
CHANGED
|
@@ -214,18 +214,20 @@ function generateIndexes(str, size, startOffset = 0) {
|
|
|
214
214
|
}
|
|
215
215
|
|
|
216
216
|
// src/core/divider-loop.ts
|
|
217
|
-
|
|
218
|
-
|
|
217
|
+
var MIN_ALLOWED_CHUNKS = 0;
|
|
218
|
+
function shouldTruncateChunks(chunks, maxChunks) {
|
|
219
|
+
return isNumber(maxChunks) && maxChunks > MIN_ALLOWED_CHUNKS && maxChunks < chunks.length;
|
|
219
220
|
}
|
|
220
|
-
function
|
|
221
|
+
function truncateChunksToMax(chunks, maxChunks) {
|
|
221
222
|
const headCount = maxChunks - 1;
|
|
222
223
|
const head = chunks.slice(0, headCount);
|
|
223
224
|
const tail = chunks.slice(headCount).join("");
|
|
224
225
|
return [...head, tail];
|
|
225
226
|
}
|
|
226
|
-
function
|
|
227
|
-
const
|
|
228
|
-
|
|
227
|
+
function createChunksFromString(str, size, startOffset, maxChunks) {
|
|
228
|
+
const indexes = generateIndexes(str, size, startOffset);
|
|
229
|
+
const chunks = divider(str, ...indexes);
|
|
230
|
+
return shouldTruncateChunks(chunks, maxChunks) ? truncateChunksToMax(chunks, maxChunks) : chunks;
|
|
229
231
|
}
|
|
230
232
|
function dividerLoop(input, size, options) {
|
|
231
233
|
if (!isPositiveInteger(size)) {
|
|
@@ -237,7 +239,7 @@ function dividerLoop(input, size, options) {
|
|
|
237
239
|
startOffset = PERFORMANCE_CONSTANTS.DEFAULT_START_OFFSET,
|
|
238
240
|
maxChunks = PERFORMANCE_CONSTANTS.DEFAULT_MAX_CHUNKS
|
|
239
241
|
} = finalOptions;
|
|
240
|
-
const result = isString(input) ?
|
|
242
|
+
const result = isString(input) ? createChunksFromString(input, size, startOffset, maxChunks) : input.map((str) => createChunksFromString(str, size, startOffset, maxChunks));
|
|
241
243
|
return applyDividerOptions(result, finalOptions);
|
|
242
244
|
}
|
|
243
245
|
|