@nyaomaru/divider 1.2.2 → 1.3.0
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/cjs/core/divider-first.js +3 -6
- package/dist/cjs/core/divider-last.js +2 -5
- package/dist/cjs/core/divider.js +3 -3
- package/dist/cjs/core/parser.js +3 -2
- package/dist/cjs/{core/validator.js → utils/is.js} +1 -1
- package/dist/cjs/utils/regex.js +2 -1
- package/dist/cjs/utils/slice.js +2 -1
- package/dist/esm/core/divider-first.js +3 -6
- package/dist/esm/core/divider-last.js +2 -5
- package/dist/esm/core/divider.js +1 -1
- package/dist/esm/core/parser.js +3 -2
- package/dist/esm/{core/validator.js → utils/is.js} +1 -1
- package/dist/esm/utils/regex.js +2 -1
- package/dist/esm/utils/slice.js +2 -1
- package/dist/types/core/divider-first.d.ts +2 -2
- package/dist/types/core/divider-last.d.ts +2 -2
- package/dist/types/core/types.d.ts +2 -1
- package/package.json +1 -1
- /package/dist/types/{core/validator.d.ts → utils/is.d.ts} +0 -0
|
@@ -3,10 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.dividerFirst = dividerFirst;
|
|
4
4
|
const divider_1 = require("@/core/divider");
|
|
5
5
|
function dividerFirst(input, ...args) {
|
|
6
|
-
var _a
|
|
7
|
-
const result = (0, divider_1.divider)(input, ...args);
|
|
8
|
-
|
|
9
|
-
return (_a = result[0][0]) !== null && _a !== void 0 ? _a : '';
|
|
10
|
-
}
|
|
11
|
-
return (_b = result[0]) !== null && _b !== void 0 ? _b : '';
|
|
6
|
+
var _a;
|
|
7
|
+
const result = (0, divider_1.divider)(input, ...args, { flatten: true });
|
|
8
|
+
return (_a = result[0]) !== null && _a !== void 0 ? _a : '';
|
|
12
9
|
}
|
|
@@ -4,9 +4,6 @@ exports.dividerLast = dividerLast;
|
|
|
4
4
|
const divider_1 = require("@/core/divider");
|
|
5
5
|
function dividerLast(input, ...args) {
|
|
6
6
|
var _a;
|
|
7
|
-
const result = (0, divider_1.divider)(input, ...args);
|
|
8
|
-
|
|
9
|
-
return '';
|
|
10
|
-
const lastElement = result[result.length - 1];
|
|
11
|
-
return Array.isArray(lastElement) ? ((_a = lastElement.at(-1)) !== null && _a !== void 0 ? _a : '') : lastElement;
|
|
7
|
+
const result = (0, divider_1.divider)(input, ...args, { flatten: true });
|
|
8
|
+
return (_a = result.at(-1)) !== null && _a !== void 0 ? _a : '';
|
|
12
9
|
}
|
package/dist/cjs/core/divider.js
CHANGED
|
@@ -2,18 +2,18 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.divider = divider;
|
|
4
4
|
const parser_1 = require("@/core/parser");
|
|
5
|
-
const
|
|
5
|
+
const is_1 = require("@/utils/is");
|
|
6
6
|
function divider(input, ...args) {
|
|
7
7
|
if (typeof input !== 'string' && !Array.isArray(input)) {
|
|
8
8
|
console.warn("divider: 'input' must be a string or an array of strings. So returning an empty array.");
|
|
9
9
|
return [];
|
|
10
10
|
}
|
|
11
|
-
if ((0,
|
|
11
|
+
if ((0, is_1.isEmptyArray)(args)) {
|
|
12
12
|
return (typeof input === 'string' ? [input] : input);
|
|
13
13
|
}
|
|
14
14
|
// Extract the options from the input
|
|
15
15
|
const lastArg = args[args.length - 1];
|
|
16
|
-
const options = (0,
|
|
16
|
+
const options = (0, is_1.isOptions)(lastArg) ? (args.pop(), lastArg) : {};
|
|
17
17
|
// Filter out only numbers and strings
|
|
18
18
|
const { numSeparators, strSeparators } = args.reduce((acc, arg) => {
|
|
19
19
|
if (typeof arg === 'number') {
|
package/dist/cjs/core/parser.js
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.divideString = divideString;
|
|
4
|
-
const
|
|
4
|
+
const is_1 = require("@/utils/is");
|
|
5
5
|
const regex_1 = require("@/utils/regex");
|
|
6
|
+
const slice_1 = require("@/utils/slice");
|
|
6
7
|
function divideString(input, numSeparators, strSeparators) {
|
|
7
|
-
if (numSeparators
|
|
8
|
+
if ((0, is_1.isEmptyArray)(numSeparators) && (0, is_1.isEmptyArray)(strSeparators)) {
|
|
8
9
|
return [input];
|
|
9
10
|
}
|
|
10
11
|
// Precompile regex for string separators
|
package/dist/cjs/utils/regex.js
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.getRegex = getRegex;
|
|
4
|
+
const is_1 = require("@/utils/is");
|
|
4
5
|
const regexCache = new Map();
|
|
5
6
|
function getRegex(separators) {
|
|
6
|
-
if (
|
|
7
|
+
if ((0, is_1.isEmptyArray)(separators))
|
|
7
8
|
return null;
|
|
8
9
|
const key = JSON.stringify(separators);
|
|
9
10
|
if (!regexCache.has(key)) {
|
package/dist/cjs/utils/slice.js
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.sliceByIndexes = sliceByIndexes;
|
|
4
|
+
const is_1 = require("@/utils/is");
|
|
4
5
|
function sliceByIndexes(input, indexes) {
|
|
5
|
-
if (
|
|
6
|
+
if ((0, is_1.isEmptyArray)(indexes))
|
|
6
7
|
return [input];
|
|
7
8
|
const parts = [];
|
|
8
9
|
let start = 0;
|
|
@@ -1,9 +1,6 @@
|
|
|
1
1
|
import { divider } from '@/core/divider';
|
|
2
2
|
export function dividerFirst(input, ...args) {
|
|
3
|
-
var _a
|
|
4
|
-
const result = divider(input, ...args);
|
|
5
|
-
|
|
6
|
-
return (_a = result[0][0]) !== null && _a !== void 0 ? _a : '';
|
|
7
|
-
}
|
|
8
|
-
return (_b = result[0]) !== null && _b !== void 0 ? _b : '';
|
|
3
|
+
var _a;
|
|
4
|
+
const result = divider(input, ...args, { flatten: true });
|
|
5
|
+
return (_a = result[0]) !== null && _a !== void 0 ? _a : '';
|
|
9
6
|
}
|
|
@@ -1,9 +1,6 @@
|
|
|
1
1
|
import { divider } from '@/core/divider';
|
|
2
2
|
export function dividerLast(input, ...args) {
|
|
3
3
|
var _a;
|
|
4
|
-
const result = divider(input, ...args);
|
|
5
|
-
|
|
6
|
-
return '';
|
|
7
|
-
const lastElement = result[result.length - 1];
|
|
8
|
-
return Array.isArray(lastElement) ? ((_a = lastElement.at(-1)) !== null && _a !== void 0 ? _a : '') : lastElement;
|
|
4
|
+
const result = divider(input, ...args, { flatten: true });
|
|
5
|
+
return (_a = result.at(-1)) !== null && _a !== void 0 ? _a : '';
|
|
9
6
|
}
|
package/dist/esm/core/divider.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { divideString } from '@/core/parser';
|
|
2
|
-
import { isOptions, isEmptyArray } from '@/
|
|
2
|
+
import { isOptions, isEmptyArray } from '@/utils/is';
|
|
3
3
|
export function divider(input, ...args) {
|
|
4
4
|
if (typeof input !== 'string' && !Array.isArray(input)) {
|
|
5
5
|
console.warn("divider: 'input' must be a string or an array of strings. So returning an empty array.");
|
package/dist/esm/core/parser.js
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { isEmptyArray } from '@/utils/is';
|
|
2
2
|
import { getRegex } from '@/utils/regex';
|
|
3
|
+
import { sliceByIndexes } from '@/utils/slice';
|
|
3
4
|
export function divideString(input, numSeparators, strSeparators) {
|
|
4
|
-
if (numSeparators
|
|
5
|
+
if (isEmptyArray(numSeparators) && isEmptyArray(strSeparators)) {
|
|
5
6
|
return [input];
|
|
6
7
|
}
|
|
7
8
|
// Precompile regex for string separators
|
package/dist/esm/utils/regex.js
CHANGED
package/dist/esm/utils/slice.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
export declare function dividerFirst<T extends string | string[]
|
|
1
|
+
import type { DividerSeparators } from '@/core/types';
|
|
2
|
+
export declare function dividerFirst<T extends string | string[]>(input: T, ...args: DividerSeparators): string;
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
export declare function dividerLast<T extends string | string[]
|
|
1
|
+
import type { DividerSeparators } from '@/core/types';
|
|
2
|
+
export declare function dividerLast<T extends string | string[]>(input: T, ...args: DividerSeparators): string;
|
|
@@ -2,4 +2,5 @@ export type DividerResult<T extends string | string[], F extends boolean = false
|
|
|
2
2
|
export type DividerOptions<F extends boolean> = {
|
|
3
3
|
flatten?: F;
|
|
4
4
|
};
|
|
5
|
-
export type
|
|
5
|
+
export type DividerSeparators = (number | string)[];
|
|
6
|
+
export type DividerArgs<F extends boolean> = DividerSeparators | [...DividerSeparators, DividerOptions<F>];
|
package/package.json
CHANGED
|
File without changes
|