@nyaomaru/divider 2.0.21 → 2.0.22

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
@@ -461,22 +461,32 @@ function truncateChunksToMax(chunks, maxChunks) {
461
461
  const tail = chunks.slice(headCount).join("");
462
462
  return [...head, tail];
463
463
  }
464
+ function applyMaxChunks(chunks, maxChunks) {
465
+ return shouldTruncateChunks(chunks, maxChunks) ? truncateChunksToMax(chunks, maxChunks) : [...chunks];
466
+ }
464
467
 
465
468
  // src/core/divider-loop.ts
469
+ var DEFAULT_DIVIDER_LOOP_OPTIONS = {
470
+ startOffset: PERFORMANCE_CONSTANTS.DEFAULT_START_OFFSET,
471
+ maxChunks: PERFORMANCE_CONSTANTS.DEFAULT_MAX_CHUNKS
472
+ };
473
+ function resolveDividerLoopOptions(options) {
474
+ return {
475
+ startOffset: options?.startOffset ?? DEFAULT_DIVIDER_LOOP_OPTIONS.startOffset,
476
+ maxChunks: options?.maxChunks ?? DEFAULT_DIVIDER_LOOP_OPTIONS.maxChunks
477
+ };
478
+ }
466
479
  function createChunksFromString(str, size, startOffset, maxChunks) {
467
480
  const indexes = generateIndexes(str, size, startOffset);
468
481
  const chunks = divider(str, ...indexes);
469
- return shouldTruncateChunks(chunks, maxChunks) ? truncateChunksToMax(chunks, maxChunks) : chunks;
482
+ return applyMaxChunks(chunks, maxChunks);
470
483
  }
471
484
  function dividerLoop(input, size, options) {
472
485
  if (!isPositiveInteger(size)) {
473
486
  console.warn("dividerLoop: chunk size must be a positive number");
474
487
  return [];
475
488
  }
476
- const {
477
- startOffset = PERFORMANCE_CONSTANTS.DEFAULT_START_OFFSET,
478
- maxChunks = PERFORMANCE_CONSTANTS.DEFAULT_MAX_CHUNKS
479
- } = options ?? {};
489
+ const { startOffset, maxChunks } = resolveDividerLoopOptions(options);
480
490
  return transformDividerInput(
481
491
  input,
482
492
  (str) => createChunksFromString(str, size, startOffset, maxChunks),
package/dist/index.js CHANGED
@@ -427,22 +427,32 @@ function truncateChunksToMax(chunks, maxChunks) {
427
427
  const tail = chunks.slice(headCount).join("");
428
428
  return [...head, tail];
429
429
  }
430
+ function applyMaxChunks(chunks, maxChunks) {
431
+ return shouldTruncateChunks(chunks, maxChunks) ? truncateChunksToMax(chunks, maxChunks) : [...chunks];
432
+ }
430
433
 
431
434
  // src/core/divider-loop.ts
435
+ var DEFAULT_DIVIDER_LOOP_OPTIONS = {
436
+ startOffset: PERFORMANCE_CONSTANTS.DEFAULT_START_OFFSET,
437
+ maxChunks: PERFORMANCE_CONSTANTS.DEFAULT_MAX_CHUNKS
438
+ };
439
+ function resolveDividerLoopOptions(options) {
440
+ return {
441
+ startOffset: options?.startOffset ?? DEFAULT_DIVIDER_LOOP_OPTIONS.startOffset,
442
+ maxChunks: options?.maxChunks ?? DEFAULT_DIVIDER_LOOP_OPTIONS.maxChunks
443
+ };
444
+ }
432
445
  function createChunksFromString(str, size, startOffset, maxChunks) {
433
446
  const indexes = generateIndexes(str, size, startOffset);
434
447
  const chunks = divider(str, ...indexes);
435
- return shouldTruncateChunks(chunks, maxChunks) ? truncateChunksToMax(chunks, maxChunks) : chunks;
448
+ return applyMaxChunks(chunks, maxChunks);
436
449
  }
437
450
  function dividerLoop(input, size, options) {
438
451
  if (!isPositiveInteger(size)) {
439
452
  console.warn("dividerLoop: chunk size must be a positive number");
440
453
  return [];
441
454
  }
442
- const {
443
- startOffset = PERFORMANCE_CONSTANTS.DEFAULT_START_OFFSET,
444
- maxChunks = PERFORMANCE_CONSTANTS.DEFAULT_MAX_CHUNKS
445
- } = options ?? {};
455
+ const { startOffset, maxChunks } = resolveDividerLoopOptions(options);
446
456
  return transformDividerInput(
447
457
  input,
448
458
  (str) => createChunksFromString(str, size, startOffset, maxChunks),
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@nyaomaru/divider",
3
3
  "type": "module",
4
- "version": "2.0.21",
4
+ "version": "2.0.22",
5
5
  "description": "To divide string or string[] with a given separator",
6
6
  "main": "./dist/index.cjs",
7
7
  "module": "./dist/index.js",