@nyaomaru/divider 1.4.0 → 1.4.1

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.
@@ -6,18 +6,18 @@ const chunk_1 = require("@/utils/chunk");
6
6
  const divider_1 = require("@/core/divider");
7
7
  function dividerLoop(input, size, options) {
8
8
  var _a;
9
- if (!(0, is_1.isNumber)(size) || size <= 0) {
9
+ if (!(0, is_1.isPositiveInteger)(size)) {
10
10
  console.warn('dividerLoop: chunk size must be a positive number');
11
11
  return [];
12
12
  }
13
- const flatten = (_a = options === null || options === void 0 ? void 0 : options.flatten) !== null && _a !== void 0 ? _a : false;
14
13
  if ((0, is_1.isString)(input)) {
15
14
  const indexes = (0, chunk_1.generateIndexes)(input, size);
16
- return (0, divider_1.divider)(input, ...indexes, { flatten });
15
+ return (0, divider_1.divider)(input, ...indexes);
17
16
  }
18
17
  const result = input.map((item) => {
19
18
  const indexes = (0, chunk_1.generateIndexes)(item, size);
20
19
  return (0, divider_1.divider)(item, ...indexes);
21
20
  });
21
+ const flatten = (_a = options === null || options === void 0 ? void 0 : options.flatten) !== null && _a !== void 0 ? _a : false;
22
22
  return (flatten ? result.flat() : result);
23
23
  }
@@ -3,6 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.isNumber = exports.isString = void 0;
4
4
  exports.isOptions = isOptions;
5
5
  exports.isEmptyArray = isEmptyArray;
6
+ exports.isPositiveInteger = isPositiveInteger;
6
7
  const isString = (arg) => typeof arg === 'string';
7
8
  exports.isString = isString;
8
9
  const isNumber = (arg) => typeof arg === 'number';
@@ -13,3 +14,6 @@ function isOptions(arg) {
13
14
  function isEmptyArray(input) {
14
15
  return Array.isArray(input) && input.length === 0;
15
16
  }
17
+ function isPositiveInteger(value) {
18
+ return Number.isInteger(value) && value > 0;
19
+ }
@@ -1,20 +1,20 @@
1
- import { isString, isNumber } from '@/utils/is';
1
+ import { isString, isPositiveInteger } from '@/utils/is';
2
2
  import { generateIndexes } from '@/utils/chunk';
3
3
  import { divider } from '@/core/divider';
4
4
  export function dividerLoop(input, size, options) {
5
5
  var _a;
6
- if (!isNumber(size) || size <= 0) {
6
+ if (!isPositiveInteger(size)) {
7
7
  console.warn('dividerLoop: chunk size must be a positive number');
8
8
  return [];
9
9
  }
10
- const flatten = (_a = options === null || options === void 0 ? void 0 : options.flatten) !== null && _a !== void 0 ? _a : false;
11
10
  if (isString(input)) {
12
11
  const indexes = generateIndexes(input, size);
13
- return divider(input, ...indexes, { flatten });
12
+ return divider(input, ...indexes);
14
13
  }
15
14
  const result = input.map((item) => {
16
15
  const indexes = generateIndexes(item, size);
17
16
  return divider(item, ...indexes);
18
17
  });
18
+ const flatten = (_a = options === null || options === void 0 ? void 0 : options.flatten) !== null && _a !== void 0 ? _a : false;
19
19
  return (flatten ? result.flat() : result);
20
20
  }
@@ -6,3 +6,6 @@ export function isOptions(arg) {
6
6
  export function isEmptyArray(input) {
7
7
  return Array.isArray(input) && input.length === 0;
8
8
  }
9
+ export function isPositiveInteger(value) {
10
+ return Number.isInteger(value) && value > 0;
11
+ }
@@ -4,3 +4,4 @@ export declare function isOptions(arg: unknown): arg is {
4
4
  flatten?: boolean;
5
5
  };
6
6
  export declare function isEmptyArray<T>(input: T[]): boolean;
7
+ export declare function isPositiveInteger(value: unknown): boolean;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@nyaomaru/divider",
3
3
  "type": "module",
4
- "version": "1.4.0",
4
+ "version": "1.4.1",
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",