@nyaomaru/divider 1.8.2 → 1.8.3
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 +13 -15
- package/dist/index.js +13 -15
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -221,23 +221,21 @@ function dividerLoop(input, size, options) {
|
|
|
221
221
|
console.warn("dividerLoop: chunk size must be a positive number");
|
|
222
222
|
return [];
|
|
223
223
|
}
|
|
224
|
-
const
|
|
224
|
+
const finalOptions = options ?? {};
|
|
225
|
+
const { startOffset = 0, maxChunks = 0 } = finalOptions;
|
|
225
226
|
const applyChunking = (str) => {
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
if (shouldTruncateChunks) {
|
|
229
|
-
const head = chunks.slice(0, maxChunks - 1);
|
|
230
|
-
const tail = chunks.slice(maxChunks - 1).join("");
|
|
231
|
-
chunks = [...head, tail];
|
|
232
|
-
}
|
|
233
|
-
return chunks;
|
|
227
|
+
const chunks = divider(str, ...generateIndexes(str, size, startOffset));
|
|
228
|
+
return needsTruncation(chunks) ? truncateChunks(chunks) : chunks;
|
|
234
229
|
};
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
230
|
+
const needsTruncation = (chunks) => isNumber(maxChunks) && 0 < maxChunks && maxChunks < chunks.length;
|
|
231
|
+
const truncateChunks = (chunks) => {
|
|
232
|
+
const HEAD_COUNT = maxChunks - 1;
|
|
233
|
+
const head = chunks.slice(0, HEAD_COUNT);
|
|
234
|
+
const tail = chunks.slice(HEAD_COUNT).join("");
|
|
235
|
+
return [...head, tail];
|
|
236
|
+
};
|
|
237
|
+
const result = isString(input) ? applyChunking(input) : input.map(applyChunking);
|
|
238
|
+
return applyDividerOptions(result, finalOptions);
|
|
241
239
|
}
|
|
242
240
|
|
|
243
241
|
// src/utils/divide.ts
|
package/dist/index.js
CHANGED
|
@@ -191,23 +191,21 @@ function dividerLoop(input, size, options) {
|
|
|
191
191
|
console.warn("dividerLoop: chunk size must be a positive number");
|
|
192
192
|
return [];
|
|
193
193
|
}
|
|
194
|
-
const
|
|
194
|
+
const finalOptions = options ?? {};
|
|
195
|
+
const { startOffset = 0, maxChunks = 0 } = finalOptions;
|
|
195
196
|
const applyChunking = (str) => {
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
if (shouldTruncateChunks) {
|
|
199
|
-
const head = chunks.slice(0, maxChunks - 1);
|
|
200
|
-
const tail = chunks.slice(maxChunks - 1).join("");
|
|
201
|
-
chunks = [...head, tail];
|
|
202
|
-
}
|
|
203
|
-
return chunks;
|
|
197
|
+
const chunks = divider(str, ...generateIndexes(str, size, startOffset));
|
|
198
|
+
return needsTruncation(chunks) ? truncateChunks(chunks) : chunks;
|
|
204
199
|
};
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
200
|
+
const needsTruncation = (chunks) => isNumber(maxChunks) && 0 < maxChunks && maxChunks < chunks.length;
|
|
201
|
+
const truncateChunks = (chunks) => {
|
|
202
|
+
const HEAD_COUNT = maxChunks - 1;
|
|
203
|
+
const head = chunks.slice(0, HEAD_COUNT);
|
|
204
|
+
const tail = chunks.slice(HEAD_COUNT).join("");
|
|
205
|
+
return [...head, tail];
|
|
206
|
+
};
|
|
207
|
+
const result = isString(input) ? applyChunking(input) : input.map(applyChunking);
|
|
208
|
+
return applyDividerOptions(result, finalOptions);
|
|
211
209
|
}
|
|
212
210
|
|
|
213
211
|
// src/utils/divide.ts
|