@nyaomaru/divider 2.0.10 → 2.0.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
@@ -304,13 +304,26 @@ function extractOptions(args) {
304
304
  options
305
305
  };
306
306
  }
307
+ function mapDividerOutput(output, transform) {
308
+ return isNestedStringArray(output) ? output.map(transform) : transform(output);
309
+ }
310
+ function filterDividerOutput(output, shouldKeep, preserveEmpty) {
311
+ if (!isNestedStringArray(output)) {
312
+ return output.filter(shouldKeep);
313
+ }
314
+ const filteredRows = output.map((row) => row.filter(shouldKeep));
315
+ return preserveEmpty ? filteredRows : filteredRows.filter((row) => row.length > 0);
316
+ }
317
+ function resolveExcludePredicate(exclude) {
318
+ if (exclude == null || isNoneMode(exclude) || typeof exclude !== "string") {
319
+ return null;
320
+ }
321
+ return Object.hasOwn(excludePredicateMap, exclude) ? excludePredicateMap[exclude] : null;
322
+ }
307
323
  function trimSegments(segments, preserveEmpty) {
308
324
  const trimmed = segments.map((segment) => segment.trim());
309
325
  return preserveEmpty ? trimmed : trimmed.filter((segment) => !isEmptyString(segment));
310
326
  }
311
- function trimNestedSegments(rows, preserveEmpty) {
312
- return rows.map((row) => trimSegments(row, preserveEmpty));
313
- }
314
327
  function applyDividerOptions(result, options) {
315
328
  const shouldPreserveEmpty = options.preserveEmpty === true;
316
329
  let output = result;
@@ -321,22 +334,15 @@ function applyDividerOptions(result, options) {
321
334
  }
322
335
  var applyTrimOption = (output, options, shouldPreserveEmpty) => {
323
336
  if (!options.trim) return output;
324
- return isNestedStringArray(output) ? trimNestedSegments(output, shouldPreserveEmpty) : trimSegments(output, shouldPreserveEmpty);
337
+ return mapDividerOutput(
338
+ output,
339
+ (segments) => trimSegments(segments, shouldPreserveEmpty)
340
+ );
325
341
  };
326
- var applyFlattenOption = (output, options) => options.flatten ? output.flat() : output;
342
+ var applyFlattenOption = (output, options) => options.flatten && isNestedStringArray(output) ? output.flat() : output;
327
343
  var applyExcludeOption = (output, options, shouldPreserveEmpty) => {
328
- if (options.exclude == null || isNoneMode(options.exclude)) return output;
329
- const exclude = options.exclude;
330
- let shouldKeep = () => true;
331
- if (exclude in excludePredicateMap) {
332
- shouldKeep = excludePredicateMap[exclude];
333
- }
334
- const filterNested = (arr) => {
335
- const filteredRows = arr.map((row) => row.filter(shouldKeep));
336
- return shouldPreserveEmpty ? filteredRows : filteredRows.filter((row) => row.length > 0);
337
- };
338
- const filterFlat = (arr) => arr.filter(shouldKeep);
339
- return isNestedStringArray(output) ? filterNested(output) : filterFlat(output);
344
+ const shouldKeep = resolveExcludePredicate(options.exclude);
345
+ return shouldKeep == null ? output : filterDividerOutput(output, shouldKeep, shouldPreserveEmpty);
340
346
  };
341
347
 
342
348
  // src/utils/separator.ts
@@ -464,7 +470,8 @@ var countUnescapedMultiChar = (text, quote) => {
464
470
  const quoteLength = quote.length;
465
471
  const escapedPairLength = escapedPair.length;
466
472
  let count = 0;
467
- for (let index = 0; index < text.length; ) {
473
+ let index = 0;
474
+ while (index < text.length) {
468
475
  if (text.startsWith(escapedPair, index)) {
469
476
  index += escapedPairLength;
470
477
  continue;
package/dist/index.js CHANGED
@@ -270,13 +270,26 @@ function extractOptions(args) {
270
270
  options
271
271
  };
272
272
  }
273
+ function mapDividerOutput(output, transform) {
274
+ return isNestedStringArray(output) ? output.map(transform) : transform(output);
275
+ }
276
+ function filterDividerOutput(output, shouldKeep, preserveEmpty) {
277
+ if (!isNestedStringArray(output)) {
278
+ return output.filter(shouldKeep);
279
+ }
280
+ const filteredRows = output.map((row) => row.filter(shouldKeep));
281
+ return preserveEmpty ? filteredRows : filteredRows.filter((row) => row.length > 0);
282
+ }
283
+ function resolveExcludePredicate(exclude) {
284
+ if (exclude == null || isNoneMode(exclude) || typeof exclude !== "string") {
285
+ return null;
286
+ }
287
+ return Object.hasOwn(excludePredicateMap, exclude) ? excludePredicateMap[exclude] : null;
288
+ }
273
289
  function trimSegments(segments, preserveEmpty) {
274
290
  const trimmed = segments.map((segment) => segment.trim());
275
291
  return preserveEmpty ? trimmed : trimmed.filter((segment) => !isEmptyString(segment));
276
292
  }
277
- function trimNestedSegments(rows, preserveEmpty) {
278
- return rows.map((row) => trimSegments(row, preserveEmpty));
279
- }
280
293
  function applyDividerOptions(result, options) {
281
294
  const shouldPreserveEmpty = options.preserveEmpty === true;
282
295
  let output = result;
@@ -287,22 +300,15 @@ function applyDividerOptions(result, options) {
287
300
  }
288
301
  var applyTrimOption = (output, options, shouldPreserveEmpty) => {
289
302
  if (!options.trim) return output;
290
- return isNestedStringArray(output) ? trimNestedSegments(output, shouldPreserveEmpty) : trimSegments(output, shouldPreserveEmpty);
303
+ return mapDividerOutput(
304
+ output,
305
+ (segments) => trimSegments(segments, shouldPreserveEmpty)
306
+ );
291
307
  };
292
- var applyFlattenOption = (output, options) => options.flatten ? output.flat() : output;
308
+ var applyFlattenOption = (output, options) => options.flatten && isNestedStringArray(output) ? output.flat() : output;
293
309
  var applyExcludeOption = (output, options, shouldPreserveEmpty) => {
294
- if (options.exclude == null || isNoneMode(options.exclude)) return output;
295
- const exclude = options.exclude;
296
- let shouldKeep = () => true;
297
- if (exclude in excludePredicateMap) {
298
- shouldKeep = excludePredicateMap[exclude];
299
- }
300
- const filterNested = (arr) => {
301
- const filteredRows = arr.map((row) => row.filter(shouldKeep));
302
- return shouldPreserveEmpty ? filteredRows : filteredRows.filter((row) => row.length > 0);
303
- };
304
- const filterFlat = (arr) => arr.filter(shouldKeep);
305
- return isNestedStringArray(output) ? filterNested(output) : filterFlat(output);
310
+ const shouldKeep = resolveExcludePredicate(options.exclude);
311
+ return shouldKeep == null ? output : filterDividerOutput(output, shouldKeep, shouldPreserveEmpty);
306
312
  };
307
313
 
308
314
  // src/utils/separator.ts
@@ -430,7 +436,8 @@ var countUnescapedMultiChar = (text, quote) => {
430
436
  const quoteLength = quote.length;
431
437
  const escapedPairLength = escapedPair.length;
432
438
  let count = 0;
433
- for (let index = 0; index < text.length; ) {
439
+ let index = 0;
440
+ while (index < text.length) {
434
441
  if (text.startsWith(escapedPair, index)) {
435
442
  index += escapedPairLength;
436
443
  continue;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@nyaomaru/divider",
3
3
  "type": "module",
4
- "version": "2.0.10",
4
+ "version": "2.0.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",
@@ -35,6 +35,8 @@
35
35
  "author": "nyaomaru",
36
36
  "license": "MIT",
37
37
  "devDependencies": {
38
+ "@swc/core": "^1.15.21",
39
+ "@swc/jest": "^0.2.39",
38
40
  "@eslint/js": "^9.26.0",
39
41
  "@types/jest": "^30.0.0",
40
42
  "@types/node": "^22.15.12",
@@ -48,8 +50,6 @@
48
50
  "knip": "^5.82.1",
49
51
  "lefthook": "^2.0.13",
50
52
  "prettier": "^3.5.3",
51
- "ts-jest": "^29.4.5",
52
- "ts-node": "^10.9.2",
53
53
  "tsup": "^8.4.0",
54
54
  "tsx": "^4.19.4",
55
55
  "typedoc": "^0.28.5",