@nyaomaru/divider 2.0.18 → 2.0.20
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 +24 -8
- package/dist/index.js +24 -8
- package/package.json +19 -18
package/dist/index.cjs
CHANGED
|
@@ -326,19 +326,19 @@ function trimSegments(segments, preserveEmpty) {
|
|
|
326
326
|
}
|
|
327
327
|
|
|
328
328
|
// src/utils/option-transformers.ts
|
|
329
|
-
function applyTrimOption(output, options
|
|
329
|
+
function applyTrimOption(output, options) {
|
|
330
330
|
if (!options.trim) return output;
|
|
331
331
|
return mapDividerOutput(
|
|
332
332
|
output,
|
|
333
|
-
(segments) => trimSegments(segments,
|
|
333
|
+
(segments) => trimSegments(segments, options.preserveEmpty)
|
|
334
334
|
);
|
|
335
335
|
}
|
|
336
336
|
function applyFlattenOption(output, options) {
|
|
337
337
|
return options.flatten && isNestedStringArray(output) ? output.flat() : output;
|
|
338
338
|
}
|
|
339
|
-
function applyExcludeOption(output, options
|
|
339
|
+
function applyExcludeOption(output, options) {
|
|
340
340
|
const shouldKeep = resolveExcludePredicate(options.exclude);
|
|
341
|
-
return shouldKeep == null ? output : filterDividerOutput(output, shouldKeep,
|
|
341
|
+
return shouldKeep == null ? output : filterDividerOutput(output, shouldKeep, options.preserveEmpty);
|
|
342
342
|
}
|
|
343
343
|
|
|
344
344
|
// src/utils/option-arguments.ts
|
|
@@ -354,12 +354,28 @@ function extractOptions(args) {
|
|
|
354
354
|
}
|
|
355
355
|
|
|
356
356
|
// src/utils/option.ts
|
|
357
|
+
var DEFAULT_RESOLVED_OPTIONS = {
|
|
358
|
+
flatten: false,
|
|
359
|
+
trim: false,
|
|
360
|
+
preserveEmpty: false,
|
|
361
|
+
exclude: DIVIDER_EXCLUDE_MODES.NONE
|
|
362
|
+
};
|
|
363
|
+
var isDividerExcludeMode = (value) => isString(value) && Object.values(DIVIDER_EXCLUDE_MODES).includes(
|
|
364
|
+
value
|
|
365
|
+
);
|
|
366
|
+
var resolveExcludeMode = (value) => isDividerExcludeMode(value) ? value : DEFAULT_RESOLVED_OPTIONS.exclude;
|
|
367
|
+
var resolveDividerOptions = (options) => ({
|
|
368
|
+
flatten: options.flatten === true,
|
|
369
|
+
trim: options.trim === true,
|
|
370
|
+
preserveEmpty: options.preserveEmpty === true,
|
|
371
|
+
exclude: resolveExcludeMode(options.exclude)
|
|
372
|
+
});
|
|
357
373
|
function applyDividerOptions(result, options) {
|
|
358
|
-
const
|
|
374
|
+
const resolvedOptions = resolveDividerOptions(options);
|
|
359
375
|
let output = result;
|
|
360
|
-
output = applyTrimOption(output,
|
|
361
|
-
output = applyFlattenOption(output,
|
|
362
|
-
output = applyExcludeOption(output,
|
|
376
|
+
output = applyTrimOption(output, resolvedOptions);
|
|
377
|
+
output = applyFlattenOption(output, resolvedOptions);
|
|
378
|
+
output = applyExcludeOption(output, resolvedOptions);
|
|
363
379
|
return output;
|
|
364
380
|
}
|
|
365
381
|
|
package/dist/index.js
CHANGED
|
@@ -292,19 +292,19 @@ function trimSegments(segments, preserveEmpty) {
|
|
|
292
292
|
}
|
|
293
293
|
|
|
294
294
|
// src/utils/option-transformers.ts
|
|
295
|
-
function applyTrimOption(output, options
|
|
295
|
+
function applyTrimOption(output, options) {
|
|
296
296
|
if (!options.trim) return output;
|
|
297
297
|
return mapDividerOutput(
|
|
298
298
|
output,
|
|
299
|
-
(segments) => trimSegments(segments,
|
|
299
|
+
(segments) => trimSegments(segments, options.preserveEmpty)
|
|
300
300
|
);
|
|
301
301
|
}
|
|
302
302
|
function applyFlattenOption(output, options) {
|
|
303
303
|
return options.flatten && isNestedStringArray(output) ? output.flat() : output;
|
|
304
304
|
}
|
|
305
|
-
function applyExcludeOption(output, options
|
|
305
|
+
function applyExcludeOption(output, options) {
|
|
306
306
|
const shouldKeep = resolveExcludePredicate(options.exclude);
|
|
307
|
-
return shouldKeep == null ? output : filterDividerOutput(output, shouldKeep,
|
|
307
|
+
return shouldKeep == null ? output : filterDividerOutput(output, shouldKeep, options.preserveEmpty);
|
|
308
308
|
}
|
|
309
309
|
|
|
310
310
|
// src/utils/option-arguments.ts
|
|
@@ -320,12 +320,28 @@ function extractOptions(args) {
|
|
|
320
320
|
}
|
|
321
321
|
|
|
322
322
|
// src/utils/option.ts
|
|
323
|
+
var DEFAULT_RESOLVED_OPTIONS = {
|
|
324
|
+
flatten: false,
|
|
325
|
+
trim: false,
|
|
326
|
+
preserveEmpty: false,
|
|
327
|
+
exclude: DIVIDER_EXCLUDE_MODES.NONE
|
|
328
|
+
};
|
|
329
|
+
var isDividerExcludeMode = (value) => isString(value) && Object.values(DIVIDER_EXCLUDE_MODES).includes(
|
|
330
|
+
value
|
|
331
|
+
);
|
|
332
|
+
var resolveExcludeMode = (value) => isDividerExcludeMode(value) ? value : DEFAULT_RESOLVED_OPTIONS.exclude;
|
|
333
|
+
var resolveDividerOptions = (options) => ({
|
|
334
|
+
flatten: options.flatten === true,
|
|
335
|
+
trim: options.trim === true,
|
|
336
|
+
preserveEmpty: options.preserveEmpty === true,
|
|
337
|
+
exclude: resolveExcludeMode(options.exclude)
|
|
338
|
+
});
|
|
323
339
|
function applyDividerOptions(result, options) {
|
|
324
|
-
const
|
|
340
|
+
const resolvedOptions = resolveDividerOptions(options);
|
|
325
341
|
let output = result;
|
|
326
|
-
output = applyTrimOption(output,
|
|
327
|
-
output = applyFlattenOption(output,
|
|
328
|
-
output = applyExcludeOption(output,
|
|
342
|
+
output = applyTrimOption(output, resolvedOptions);
|
|
343
|
+
output = applyFlattenOption(output, resolvedOptions);
|
|
344
|
+
output = applyExcludeOption(output, resolvedOptions);
|
|
329
345
|
return output;
|
|
330
346
|
}
|
|
331
347
|
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nyaomaru/divider",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "2.0.
|
|
4
|
+
"version": "2.0.20",
|
|
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,25 +35,25 @@
|
|
|
35
35
|
"author": "nyaomaru",
|
|
36
36
|
"license": "MIT",
|
|
37
37
|
"devDependencies": {
|
|
38
|
-
"@eslint/js": "^
|
|
39
|
-
"@swc/core": "^1.15.
|
|
38
|
+
"@eslint/js": "^10.0.1",
|
|
39
|
+
"@swc/core": "^1.15.41",
|
|
40
40
|
"@swc/jest": "^0.2.39",
|
|
41
41
|
"@types/jest": "^30.0.0",
|
|
42
|
-
"@types/node": "^22.
|
|
43
|
-
"@typescript-eslint/eslint-plugin": "^8.
|
|
44
|
-
"@typescript-eslint/parser": "^8.
|
|
45
|
-
"bun-types": "^1.
|
|
46
|
-
"eslint": "^
|
|
42
|
+
"@types/node": "^22.19.21",
|
|
43
|
+
"@typescript-eslint/eslint-plugin": "^8.61.1",
|
|
44
|
+
"@typescript-eslint/parser": "^8.61.1",
|
|
45
|
+
"bun-types": "^1.3.14",
|
|
46
|
+
"eslint": "^10.5.0",
|
|
47
47
|
"eslint-config-prettier": "^10.1.8",
|
|
48
|
-
"eslint-plugin-prettier": "^5.5.
|
|
49
|
-
"jest": "^30.2
|
|
50
|
-
"knip": "^
|
|
51
|
-
"lefthook": "^2.
|
|
52
|
-
"prettier": "^3.
|
|
53
|
-
"tsup": "^8.
|
|
54
|
-
"tsx": "^4.
|
|
55
|
-
"typedoc": "^0.28.
|
|
56
|
-
"typescript": "^
|
|
48
|
+
"eslint-plugin-prettier": "^5.5.6",
|
|
49
|
+
"jest": "^30.4.2",
|
|
50
|
+
"knip": "^6.17.1",
|
|
51
|
+
"lefthook": "^2.1.9",
|
|
52
|
+
"prettier": "^3.8.4",
|
|
53
|
+
"tsup": "^8.5.1",
|
|
54
|
+
"tsx": "^4.22.4",
|
|
55
|
+
"typedoc": "^0.28.19",
|
|
56
|
+
"typescript": "^6.0.3"
|
|
57
57
|
},
|
|
58
58
|
"engines": {
|
|
59
59
|
"node": ">=20"
|
|
@@ -64,9 +64,10 @@
|
|
|
64
64
|
},
|
|
65
65
|
"scripts": {
|
|
66
66
|
"test": "jest",
|
|
67
|
+
"test:integration": "tsx tests/integration/usage.test.ts",
|
|
67
68
|
"test:types": "tsc -p tests/tsconfig.json",
|
|
68
69
|
"test:performance": "jest --config jest.performance.config.cjs",
|
|
69
|
-
"test:unit": "jest
|
|
70
|
+
"test:unit": "jest",
|
|
70
71
|
"lint": "eslint .",
|
|
71
72
|
"build": "tsup",
|
|
72
73
|
"typedoc": "typedoc",
|