@nyaomaru/divider 2.0.14 → 2.0.16
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 +19 -8
- package/dist/index.js +19 -8
- package/package.json +2 -1
package/dist/index.cjs
CHANGED
|
@@ -355,6 +355,13 @@ function applyDividerOptions(result, options) {
|
|
|
355
355
|
return output;
|
|
356
356
|
}
|
|
357
357
|
|
|
358
|
+
// src/utils/transform-divider-input.ts
|
|
359
|
+
function transformDividerInput(input, transform, options) {
|
|
360
|
+
const result = isString(input) ? transform(input) : input.map(transform);
|
|
361
|
+
const resolvedOptions = options ?? {};
|
|
362
|
+
return applyDividerOptions(result, resolvedOptions);
|
|
363
|
+
}
|
|
364
|
+
|
|
358
365
|
// src/utils/separator.ts
|
|
359
366
|
function classifySeparators(args) {
|
|
360
367
|
return args.reduce(
|
|
@@ -367,11 +374,15 @@ function classifySeparators(args) {
|
|
|
367
374
|
);
|
|
368
375
|
}
|
|
369
376
|
|
|
370
|
-
// src/
|
|
371
|
-
function
|
|
372
|
-
const
|
|
373
|
-
const
|
|
374
|
-
return
|
|
377
|
+
// src/core/divider-plan.ts
|
|
378
|
+
function createDividerPlan(args) {
|
|
379
|
+
const { cleanedArgs, options } = extractOptions(args);
|
|
380
|
+
const { numSeparators, strSeparators } = classifySeparators(cleanedArgs);
|
|
381
|
+
return {
|
|
382
|
+
numSeparators,
|
|
383
|
+
strSeparators,
|
|
384
|
+
options
|
|
385
|
+
};
|
|
375
386
|
}
|
|
376
387
|
|
|
377
388
|
// src/core/divider.ts
|
|
@@ -385,8 +396,7 @@ function divider(input, ...args) {
|
|
|
385
396
|
if (isEmptyArray(args)) {
|
|
386
397
|
return ensureStringArray(input);
|
|
387
398
|
}
|
|
388
|
-
const {
|
|
389
|
-
const { numSeparators, strSeparators } = classifySeparators(cleanedArgs);
|
|
399
|
+
const { numSeparators, strSeparators, options } = createDividerPlan(args);
|
|
390
400
|
const applyDivision = (str) => divideString(str, numSeparators, strSeparators, {
|
|
391
401
|
preserveEmpty: options.preserveEmpty
|
|
392
402
|
});
|
|
@@ -504,7 +514,8 @@ function countUnescaped(text, quote) {
|
|
|
504
514
|
// src/utils/divide-preserve.ts
|
|
505
515
|
function dividePreserve(input, separator) {
|
|
506
516
|
if (isEmptyString(input)) return [""];
|
|
507
|
-
|
|
517
|
+
const regex = getRegex([separator]);
|
|
518
|
+
return regex == null ? [input] : input.split(regex);
|
|
508
519
|
}
|
|
509
520
|
|
|
510
521
|
// src/utils/strip-outer-quotes.ts
|
package/dist/index.js
CHANGED
|
@@ -321,6 +321,13 @@ function applyDividerOptions(result, options) {
|
|
|
321
321
|
return output;
|
|
322
322
|
}
|
|
323
323
|
|
|
324
|
+
// src/utils/transform-divider-input.ts
|
|
325
|
+
function transformDividerInput(input, transform, options) {
|
|
326
|
+
const result = isString(input) ? transform(input) : input.map(transform);
|
|
327
|
+
const resolvedOptions = options ?? {};
|
|
328
|
+
return applyDividerOptions(result, resolvedOptions);
|
|
329
|
+
}
|
|
330
|
+
|
|
324
331
|
// src/utils/separator.ts
|
|
325
332
|
function classifySeparators(args) {
|
|
326
333
|
return args.reduce(
|
|
@@ -333,11 +340,15 @@ function classifySeparators(args) {
|
|
|
333
340
|
);
|
|
334
341
|
}
|
|
335
342
|
|
|
336
|
-
// src/
|
|
337
|
-
function
|
|
338
|
-
const
|
|
339
|
-
const
|
|
340
|
-
return
|
|
343
|
+
// src/core/divider-plan.ts
|
|
344
|
+
function createDividerPlan(args) {
|
|
345
|
+
const { cleanedArgs, options } = extractOptions(args);
|
|
346
|
+
const { numSeparators, strSeparators } = classifySeparators(cleanedArgs);
|
|
347
|
+
return {
|
|
348
|
+
numSeparators,
|
|
349
|
+
strSeparators,
|
|
350
|
+
options
|
|
351
|
+
};
|
|
341
352
|
}
|
|
342
353
|
|
|
343
354
|
// src/core/divider.ts
|
|
@@ -351,8 +362,7 @@ function divider(input, ...args) {
|
|
|
351
362
|
if (isEmptyArray(args)) {
|
|
352
363
|
return ensureStringArray(input);
|
|
353
364
|
}
|
|
354
|
-
const {
|
|
355
|
-
const { numSeparators, strSeparators } = classifySeparators(cleanedArgs);
|
|
365
|
+
const { numSeparators, strSeparators, options } = createDividerPlan(args);
|
|
356
366
|
const applyDivision = (str) => divideString(str, numSeparators, strSeparators, {
|
|
357
367
|
preserveEmpty: options.preserveEmpty
|
|
358
368
|
});
|
|
@@ -470,7 +480,8 @@ function countUnescaped(text, quote) {
|
|
|
470
480
|
// src/utils/divide-preserve.ts
|
|
471
481
|
function dividePreserve(input, separator) {
|
|
472
482
|
if (isEmptyString(input)) return [""];
|
|
473
|
-
|
|
483
|
+
const regex = getRegex([separator]);
|
|
484
|
+
return regex == null ? [input] : input.split(regex);
|
|
474
485
|
}
|
|
475
486
|
|
|
476
487
|
// src/utils/strip-outer-quotes.ts
|
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.16",
|
|
5
5
|
"description": "To divide string or string[] with a given separator",
|
|
6
6
|
"main": "./dist/index.cjs",
|
|
7
7
|
"module": "./dist/index.js",
|
|
@@ -64,6 +64,7 @@
|
|
|
64
64
|
},
|
|
65
65
|
"scripts": {
|
|
66
66
|
"test": "jest",
|
|
67
|
+
"test:types": "tsc -p tests/tsconfig.json",
|
|
67
68
|
"test:performance": "jest --config jest.performance.config.cjs",
|
|
68
69
|
"test:unit": "jest --testPathIgnorePatterns=performance",
|
|
69
70
|
"lint": "eslint .",
|