@nyaomaru/divider 2.0.17 → 2.0.19
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 +72 -48
- package/dist/index.js +72 -48
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -32,6 +32,38 @@ __export(index_exports, {
|
|
|
32
32
|
});
|
|
33
33
|
module.exports = __toCommonJS(index_exports);
|
|
34
34
|
|
|
35
|
+
// src/utils/guards/primitives.ts
|
|
36
|
+
function isString(value) {
|
|
37
|
+
return typeof value === "string";
|
|
38
|
+
}
|
|
39
|
+
function isNumber(value) {
|
|
40
|
+
return typeof value === "number";
|
|
41
|
+
}
|
|
42
|
+
function isObject(value) {
|
|
43
|
+
return typeof value === "object" && value !== null;
|
|
44
|
+
}
|
|
45
|
+
function isPlainObject(value) {
|
|
46
|
+
if (!isObject(value)) return false;
|
|
47
|
+
const proto = Object.getPrototypeOf(value);
|
|
48
|
+
return proto === null || Object.getPrototypeOf(proto) === null;
|
|
49
|
+
}
|
|
50
|
+
function isPositiveInteger(value) {
|
|
51
|
+
return typeof value === "number" && Number.isInteger(value) && value > 0;
|
|
52
|
+
}
|
|
53
|
+
function isStringOrNumber(value) {
|
|
54
|
+
return isString(value) || isNumber(value);
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
// src/utils/guards/array.ts
|
|
58
|
+
function isEmptyArray(value) {
|
|
59
|
+
return Array.isArray(value) && value.length === 0;
|
|
60
|
+
}
|
|
61
|
+
function isNestedStringArray(value) {
|
|
62
|
+
if (!Array.isArray(value) || value.length === 0) return false;
|
|
63
|
+
const firstRow = value[0];
|
|
64
|
+
return Array.isArray(firstRow) && firstRow.every((item) => isString(item));
|
|
65
|
+
}
|
|
66
|
+
|
|
35
67
|
// src/constants/index.ts
|
|
36
68
|
var DIVIDER_EXCLUDE_MODES = {
|
|
37
69
|
NONE: "none",
|
|
@@ -71,43 +103,7 @@ var QUERY_DECODE_MODES = {
|
|
|
71
103
|
RAW: "raw"
|
|
72
104
|
};
|
|
73
105
|
|
|
74
|
-
// src/utils/
|
|
75
|
-
function isString(value) {
|
|
76
|
-
return typeof value === "string";
|
|
77
|
-
}
|
|
78
|
-
function isNumber(value) {
|
|
79
|
-
return typeof value === "number";
|
|
80
|
-
}
|
|
81
|
-
function isObject(value) {
|
|
82
|
-
return typeof value === "object" && value !== null;
|
|
83
|
-
}
|
|
84
|
-
function isPlainObject(value) {
|
|
85
|
-
if (!isObject(value)) return false;
|
|
86
|
-
const proto = Object.getPrototypeOf(value);
|
|
87
|
-
return proto === null || Object.getPrototypeOf(proto) === null;
|
|
88
|
-
}
|
|
89
|
-
function isOptions(value) {
|
|
90
|
-
if (!isPlainObject(value)) return false;
|
|
91
|
-
const options = value;
|
|
92
|
-
return DIVIDER_OPTION_KEYS.some((key) => Object.hasOwn(options, key));
|
|
93
|
-
}
|
|
94
|
-
function isEmptyArray(value) {
|
|
95
|
-
return Array.isArray(value) && value.length === 0;
|
|
96
|
-
}
|
|
97
|
-
function isPositiveInteger(value) {
|
|
98
|
-
return typeof value === "number" && Number.isInteger(value) && value > 0;
|
|
99
|
-
}
|
|
100
|
-
function isValidInput(value) {
|
|
101
|
-
return isString(value) || Array.isArray(value) && value.every(isString);
|
|
102
|
-
}
|
|
103
|
-
function isStringOrNumber(value) {
|
|
104
|
-
return isString(value) || isNumber(value);
|
|
105
|
-
}
|
|
106
|
-
function isNestedStringArray(value) {
|
|
107
|
-
if (!Array.isArray(value) || value.length === 0) return false;
|
|
108
|
-
const firstRow = value[0];
|
|
109
|
-
return Array.isArray(firstRow) && firstRow.every((item) => isString(item));
|
|
110
|
-
}
|
|
106
|
+
// src/utils/guards/whitespace.ts
|
|
111
107
|
function isSpaceOrTab(value) {
|
|
112
108
|
return value === WHITE_SPACE || value === TAB;
|
|
113
109
|
}
|
|
@@ -117,9 +113,6 @@ function isWhitespaceOnly(value) {
|
|
|
117
113
|
function isEmptyString(value) {
|
|
118
114
|
return value === "";
|
|
119
115
|
}
|
|
120
|
-
function isNoneMode(value) {
|
|
121
|
-
return value === DIVIDER_EXCLUDE_MODES.NONE;
|
|
122
|
-
}
|
|
123
116
|
|
|
124
117
|
// src/utils/regex.ts
|
|
125
118
|
function normalizeSeparators(separators) {
|
|
@@ -275,6 +268,11 @@ var assertValidNumSeparators = (numSeparators) => {
|
|
|
275
268
|
}
|
|
276
269
|
};
|
|
277
270
|
|
|
271
|
+
// src/utils/guards/divider-input.ts
|
|
272
|
+
function isValidInput(value) {
|
|
273
|
+
return isString(value) || Array.isArray(value) && value.every(isString);
|
|
274
|
+
}
|
|
275
|
+
|
|
278
276
|
// src/utils/array.ts
|
|
279
277
|
function ensureStringArray(input) {
|
|
280
278
|
return isString(input) ? [input] : input;
|
|
@@ -293,6 +291,16 @@ var excludePredicateMap = {
|
|
|
293
291
|
whitespace: (s) => !isWhitespaceOnly(s)
|
|
294
292
|
};
|
|
295
293
|
|
|
294
|
+
// src/utils/guards/options.ts
|
|
295
|
+
function isOptions(value) {
|
|
296
|
+
if (!isPlainObject(value)) return false;
|
|
297
|
+
const options = value;
|
|
298
|
+
return DIVIDER_OPTION_KEYS.some((key) => Object.hasOwn(options, key));
|
|
299
|
+
}
|
|
300
|
+
function isNoneMode(value) {
|
|
301
|
+
return value === DIVIDER_EXCLUDE_MODES.NONE;
|
|
302
|
+
}
|
|
303
|
+
|
|
296
304
|
// src/utils/option-exclude.ts
|
|
297
305
|
function resolveExcludePredicate(exclude) {
|
|
298
306
|
if (exclude == null || isNoneMode(exclude) || typeof exclude !== "string") {
|
|
@@ -318,19 +326,19 @@ function trimSegments(segments, preserveEmpty) {
|
|
|
318
326
|
}
|
|
319
327
|
|
|
320
328
|
// src/utils/option-transformers.ts
|
|
321
|
-
function applyTrimOption(output, options
|
|
329
|
+
function applyTrimOption(output, options) {
|
|
322
330
|
if (!options.trim) return output;
|
|
323
331
|
return mapDividerOutput(
|
|
324
332
|
output,
|
|
325
|
-
(segments) => trimSegments(segments,
|
|
333
|
+
(segments) => trimSegments(segments, options.preserveEmpty)
|
|
326
334
|
);
|
|
327
335
|
}
|
|
328
336
|
function applyFlattenOption(output, options) {
|
|
329
337
|
return options.flatten && isNestedStringArray(output) ? output.flat() : output;
|
|
330
338
|
}
|
|
331
|
-
function applyExcludeOption(output, options
|
|
339
|
+
function applyExcludeOption(output, options) {
|
|
332
340
|
const shouldKeep = resolveExcludePredicate(options.exclude);
|
|
333
|
-
return shouldKeep == null ? output : filterDividerOutput(output, shouldKeep,
|
|
341
|
+
return shouldKeep == null ? output : filterDividerOutput(output, shouldKeep, options.preserveEmpty);
|
|
334
342
|
}
|
|
335
343
|
|
|
336
344
|
// src/utils/option-arguments.ts
|
|
@@ -346,12 +354,28 @@ function extractOptions(args) {
|
|
|
346
354
|
}
|
|
347
355
|
|
|
348
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
|
+
});
|
|
349
373
|
function applyDividerOptions(result, options) {
|
|
350
|
-
const
|
|
374
|
+
const resolvedOptions = resolveDividerOptions(options);
|
|
351
375
|
let output = result;
|
|
352
|
-
output = applyTrimOption(output,
|
|
353
|
-
output = applyFlattenOption(output,
|
|
354
|
-
output = applyExcludeOption(output,
|
|
376
|
+
output = applyTrimOption(output, resolvedOptions);
|
|
377
|
+
output = applyFlattenOption(output, resolvedOptions);
|
|
378
|
+
output = applyExcludeOption(output, resolvedOptions);
|
|
355
379
|
return output;
|
|
356
380
|
}
|
|
357
381
|
|
package/dist/index.js
CHANGED
|
@@ -1,3 +1,35 @@
|
|
|
1
|
+
// src/utils/guards/primitives.ts
|
|
2
|
+
function isString(value) {
|
|
3
|
+
return typeof value === "string";
|
|
4
|
+
}
|
|
5
|
+
function isNumber(value) {
|
|
6
|
+
return typeof value === "number";
|
|
7
|
+
}
|
|
8
|
+
function isObject(value) {
|
|
9
|
+
return typeof value === "object" && value !== null;
|
|
10
|
+
}
|
|
11
|
+
function isPlainObject(value) {
|
|
12
|
+
if (!isObject(value)) return false;
|
|
13
|
+
const proto = Object.getPrototypeOf(value);
|
|
14
|
+
return proto === null || Object.getPrototypeOf(proto) === null;
|
|
15
|
+
}
|
|
16
|
+
function isPositiveInteger(value) {
|
|
17
|
+
return typeof value === "number" && Number.isInteger(value) && value > 0;
|
|
18
|
+
}
|
|
19
|
+
function isStringOrNumber(value) {
|
|
20
|
+
return isString(value) || isNumber(value);
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
// src/utils/guards/array.ts
|
|
24
|
+
function isEmptyArray(value) {
|
|
25
|
+
return Array.isArray(value) && value.length === 0;
|
|
26
|
+
}
|
|
27
|
+
function isNestedStringArray(value) {
|
|
28
|
+
if (!Array.isArray(value) || value.length === 0) return false;
|
|
29
|
+
const firstRow = value[0];
|
|
30
|
+
return Array.isArray(firstRow) && firstRow.every((item) => isString(item));
|
|
31
|
+
}
|
|
32
|
+
|
|
1
33
|
// src/constants/index.ts
|
|
2
34
|
var DIVIDER_EXCLUDE_MODES = {
|
|
3
35
|
NONE: "none",
|
|
@@ -37,43 +69,7 @@ var QUERY_DECODE_MODES = {
|
|
|
37
69
|
RAW: "raw"
|
|
38
70
|
};
|
|
39
71
|
|
|
40
|
-
// src/utils/
|
|
41
|
-
function isString(value) {
|
|
42
|
-
return typeof value === "string";
|
|
43
|
-
}
|
|
44
|
-
function isNumber(value) {
|
|
45
|
-
return typeof value === "number";
|
|
46
|
-
}
|
|
47
|
-
function isObject(value) {
|
|
48
|
-
return typeof value === "object" && value !== null;
|
|
49
|
-
}
|
|
50
|
-
function isPlainObject(value) {
|
|
51
|
-
if (!isObject(value)) return false;
|
|
52
|
-
const proto = Object.getPrototypeOf(value);
|
|
53
|
-
return proto === null || Object.getPrototypeOf(proto) === null;
|
|
54
|
-
}
|
|
55
|
-
function isOptions(value) {
|
|
56
|
-
if (!isPlainObject(value)) return false;
|
|
57
|
-
const options = value;
|
|
58
|
-
return DIVIDER_OPTION_KEYS.some((key) => Object.hasOwn(options, key));
|
|
59
|
-
}
|
|
60
|
-
function isEmptyArray(value) {
|
|
61
|
-
return Array.isArray(value) && value.length === 0;
|
|
62
|
-
}
|
|
63
|
-
function isPositiveInteger(value) {
|
|
64
|
-
return typeof value === "number" && Number.isInteger(value) && value > 0;
|
|
65
|
-
}
|
|
66
|
-
function isValidInput(value) {
|
|
67
|
-
return isString(value) || Array.isArray(value) && value.every(isString);
|
|
68
|
-
}
|
|
69
|
-
function isStringOrNumber(value) {
|
|
70
|
-
return isString(value) || isNumber(value);
|
|
71
|
-
}
|
|
72
|
-
function isNestedStringArray(value) {
|
|
73
|
-
if (!Array.isArray(value) || value.length === 0) return false;
|
|
74
|
-
const firstRow = value[0];
|
|
75
|
-
return Array.isArray(firstRow) && firstRow.every((item) => isString(item));
|
|
76
|
-
}
|
|
72
|
+
// src/utils/guards/whitespace.ts
|
|
77
73
|
function isSpaceOrTab(value) {
|
|
78
74
|
return value === WHITE_SPACE || value === TAB;
|
|
79
75
|
}
|
|
@@ -83,9 +79,6 @@ function isWhitespaceOnly(value) {
|
|
|
83
79
|
function isEmptyString(value) {
|
|
84
80
|
return value === "";
|
|
85
81
|
}
|
|
86
|
-
function isNoneMode(value) {
|
|
87
|
-
return value === DIVIDER_EXCLUDE_MODES.NONE;
|
|
88
|
-
}
|
|
89
82
|
|
|
90
83
|
// src/utils/regex.ts
|
|
91
84
|
function normalizeSeparators(separators) {
|
|
@@ -241,6 +234,11 @@ var assertValidNumSeparators = (numSeparators) => {
|
|
|
241
234
|
}
|
|
242
235
|
};
|
|
243
236
|
|
|
237
|
+
// src/utils/guards/divider-input.ts
|
|
238
|
+
function isValidInput(value) {
|
|
239
|
+
return isString(value) || Array.isArray(value) && value.every(isString);
|
|
240
|
+
}
|
|
241
|
+
|
|
244
242
|
// src/utils/array.ts
|
|
245
243
|
function ensureStringArray(input) {
|
|
246
244
|
return isString(input) ? [input] : input;
|
|
@@ -259,6 +257,16 @@ var excludePredicateMap = {
|
|
|
259
257
|
whitespace: (s) => !isWhitespaceOnly(s)
|
|
260
258
|
};
|
|
261
259
|
|
|
260
|
+
// src/utils/guards/options.ts
|
|
261
|
+
function isOptions(value) {
|
|
262
|
+
if (!isPlainObject(value)) return false;
|
|
263
|
+
const options = value;
|
|
264
|
+
return DIVIDER_OPTION_KEYS.some((key) => Object.hasOwn(options, key));
|
|
265
|
+
}
|
|
266
|
+
function isNoneMode(value) {
|
|
267
|
+
return value === DIVIDER_EXCLUDE_MODES.NONE;
|
|
268
|
+
}
|
|
269
|
+
|
|
262
270
|
// src/utils/option-exclude.ts
|
|
263
271
|
function resolveExcludePredicate(exclude) {
|
|
264
272
|
if (exclude == null || isNoneMode(exclude) || typeof exclude !== "string") {
|
|
@@ -284,19 +292,19 @@ function trimSegments(segments, preserveEmpty) {
|
|
|
284
292
|
}
|
|
285
293
|
|
|
286
294
|
// src/utils/option-transformers.ts
|
|
287
|
-
function applyTrimOption(output, options
|
|
295
|
+
function applyTrimOption(output, options) {
|
|
288
296
|
if (!options.trim) return output;
|
|
289
297
|
return mapDividerOutput(
|
|
290
298
|
output,
|
|
291
|
-
(segments) => trimSegments(segments,
|
|
299
|
+
(segments) => trimSegments(segments, options.preserveEmpty)
|
|
292
300
|
);
|
|
293
301
|
}
|
|
294
302
|
function applyFlattenOption(output, options) {
|
|
295
303
|
return options.flatten && isNestedStringArray(output) ? output.flat() : output;
|
|
296
304
|
}
|
|
297
|
-
function applyExcludeOption(output, options
|
|
305
|
+
function applyExcludeOption(output, options) {
|
|
298
306
|
const shouldKeep = resolveExcludePredicate(options.exclude);
|
|
299
|
-
return shouldKeep == null ? output : filterDividerOutput(output, shouldKeep,
|
|
307
|
+
return shouldKeep == null ? output : filterDividerOutput(output, shouldKeep, options.preserveEmpty);
|
|
300
308
|
}
|
|
301
309
|
|
|
302
310
|
// src/utils/option-arguments.ts
|
|
@@ -312,12 +320,28 @@ function extractOptions(args) {
|
|
|
312
320
|
}
|
|
313
321
|
|
|
314
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
|
+
});
|
|
315
339
|
function applyDividerOptions(result, options) {
|
|
316
|
-
const
|
|
340
|
+
const resolvedOptions = resolveDividerOptions(options);
|
|
317
341
|
let output = result;
|
|
318
|
-
output = applyTrimOption(output,
|
|
319
|
-
output = applyFlattenOption(output,
|
|
320
|
-
output = applyExcludeOption(output,
|
|
342
|
+
output = applyTrimOption(output, resolvedOptions);
|
|
343
|
+
output = applyFlattenOption(output, resolvedOptions);
|
|
344
|
+
output = applyExcludeOption(output, resolvedOptions);
|
|
321
345
|
return output;
|
|
322
346
|
}
|
|
323
347
|
|