@nyaomaru/divider 1.2.2 → 1.2.3

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.
@@ -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 validator_1 = require("@/core/validator");
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, validator_1.isEmptyArray)(args)) {
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, validator_1.isOptions)(lastArg) ? (args.pop(), lastArg) : {};
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') {
@@ -1,10 +1,11 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.divideString = divideString;
4
- const slice_1 = require("@/utils/slice");
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.length === 0 && strSeparators.length === 0) {
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
@@ -6,5 +6,5 @@ function isOptions(arg) {
6
6
  return typeof arg === 'object' && arg !== null && 'flatten' in arg;
7
7
  }
8
8
  function isEmptyArray(input) {
9
- return input.length === 0;
9
+ return Array.isArray(input) && input.length === 0;
10
10
  }
@@ -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 (separators.length === 0)
7
+ if ((0, is_1.isEmptyArray)(separators))
7
8
  return null;
8
9
  const key = JSON.stringify(separators);
9
10
  if (!regexCache.has(key)) {
@@ -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 (indexes.length === 0)
6
+ if ((0, is_1.isEmptyArray)(indexes))
6
7
  return [input];
7
8
  const parts = [];
8
9
  let start = 0;
@@ -1,5 +1,5 @@
1
1
  import { divideString } from '@/core/parser';
2
- import { isOptions, isEmptyArray } from '@/core/validator';
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.");
@@ -1,7 +1,8 @@
1
- import { sliceByIndexes } from '@/utils/slice';
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.length === 0 && strSeparators.length === 0) {
5
+ if (isEmptyArray(numSeparators) && isEmptyArray(strSeparators)) {
5
6
  return [input];
6
7
  }
7
8
  // Precompile regex for string separators
@@ -2,5 +2,5 @@ export function isOptions(arg) {
2
2
  return typeof arg === 'object' && arg !== null && 'flatten' in arg;
3
3
  }
4
4
  export function isEmptyArray(input) {
5
- return input.length === 0;
5
+ return Array.isArray(input) && input.length === 0;
6
6
  }
@@ -1,6 +1,7 @@
1
+ import { isEmptyArray } from '@/utils/is';
1
2
  const regexCache = new Map();
2
3
  export function getRegex(separators) {
3
- if (separators.length === 0)
4
+ if (isEmptyArray(separators))
4
5
  return null;
5
6
  const key = JSON.stringify(separators);
6
7
  if (!regexCache.has(key)) {
@@ -1,5 +1,6 @@
1
+ import { isEmptyArray } from '@/utils/is';
1
2
  export function sliceByIndexes(input, indexes) {
2
- if (indexes.length === 0)
3
+ if (isEmptyArray(indexes))
3
4
  return [input];
4
5
  const parts = [];
5
6
  let start = 0;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@nyaomaru/divider",
3
3
  "type": "module",
4
- "version": "1.2.2",
4
+ "version": "1.2.3",
5
5
  "description": "To divide string or string[] with a given separator",
6
6
  "main": "dist/cjs/index.js",
7
7
  "module": "dist/esm/index.js",