@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 CHANGED
@@ -244,18 +244,20 @@ function generateIndexes(str, size, startOffset = 0) {
244
244
  }
245
245
 
246
246
  // src/core/divider-loop.ts
247
- function needsTruncation(chunks, maxChunks) {
248
- return isNumber(maxChunks) && 0 < maxChunks && maxChunks < chunks.length;
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 truncateChunks(chunks, maxChunks) {
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 applyChunking(str, size, startOffset, maxChunks) {
257
- const chunks = divider(str, ...generateIndexes(str, size, startOffset));
258
- return needsTruncation(chunks, maxChunks) ? truncateChunks(chunks, maxChunks) : chunks;
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) ? applyChunking(input, size, startOffset, maxChunks) : input.map((str) => applyChunking(str, size, startOffset, maxChunks));
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
- function needsTruncation(chunks, maxChunks) {
218
- return isNumber(maxChunks) && 0 < maxChunks && maxChunks < chunks.length;
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 truncateChunks(chunks, maxChunks) {
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 applyChunking(str, size, startOffset, maxChunks) {
227
- const chunks = divider(str, ...generateIndexes(str, size, startOffset));
228
- return needsTruncation(chunks, maxChunks) ? truncateChunks(chunks, maxChunks) : chunks;
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) ? applyChunking(input, size, startOffset, maxChunks) : input.map((str) => applyChunking(str, size, startOffset, maxChunks));
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
 
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@nyaomaru/divider",
3
3
  "type": "module",
4
- "version": "1.8.11",
4
+ "version": "1.8.12",
5
5
  "description": "To divide string or string[] with a given separator",
6
6
  "main": "./dist/index.cjs",
7
7
  "module": "./dist/index.js",