@nyaomaru/divider 2.0.11 → 2.0.13
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 +23 -17
- package/dist/index.js +23 -17
- package/package.json +1 -1
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
|
|
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
|
-
|
|
329
|
-
|
|
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
|
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
|
|
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
|
-
|
|
295
|
-
|
|
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
|