@nyaomaru/divider 1.7.2 → 1.7.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.
package/dist/index.cjs CHANGED
@@ -187,12 +187,16 @@ function dividerLast(input, ...args) {
187
187
  }
188
188
 
189
189
  // src/utils/chunk.ts
190
- function generateIndexes(text, size) {
191
- const indexes = [];
192
- for (let i = size; i < text.length; i += size) {
193
- indexes.push(i);
190
+ function generateIndexes(str, size, startOffset = 0) {
191
+ if (!isPositiveInteger(size)) {
192
+ console.warn("generateIndexes: size must be a positive integer");
193
+ return [];
194
+ }
195
+ const result = [];
196
+ for (let i = startOffset + size; i < str.length; i += size) {
197
+ result.push(i);
194
198
  }
195
- return indexes;
199
+ return result;
196
200
  }
197
201
 
198
202
  // src/core/divider-loop.ts
@@ -201,7 +205,7 @@ function dividerLoop(input, size, options) {
201
205
  console.warn("dividerLoop: chunk size must be a positive number");
202
206
  return [];
203
207
  }
204
- const applyChunking = (str) => divider(str, ...generateIndexes(str, size));
208
+ const applyChunking = (str) => divider(str, ...generateIndexes(str, size, options?.startOffset ?? 0));
205
209
  if (isString(input)) {
206
210
  const result2 = applyChunking(input);
207
211
  return applyDividerOptions(result2, options ?? {});
package/dist/index.d.cts CHANGED
@@ -3,6 +3,9 @@ declare const dividerOptionKeys: readonly ["flatten", "trim", "excludeEmpty"];
3
3
  type DividerOptionKey = (typeof dividerOptionKeys)[number];
4
4
  type DividerResult<T extends string | string[]> = T extends string ? string[] : string[][];
5
5
  type DividerOptions = Partial<Record<DividerOptionKey, boolean>>;
6
+ type DividerLoopOptions = DividerOptions & {
7
+ startOffset?: number;
8
+ };
6
9
  type DividerSeparators = (number | string)[];
7
10
  type DividerArgs = DividerSeparators | [...DividerSeparators, DividerOptions];
8
11
 
@@ -12,8 +15,8 @@ declare function dividerFirst(input: string | string[], ...args: DividerSeparato
12
15
 
13
16
  declare function dividerLast(input: string | string[], ...args: DividerSeparators): string;
14
17
 
15
- declare function dividerLoop<T extends string | string[]>(input: T, size: number, options?: DividerOptions): DividerResult<T>;
18
+ declare function dividerLoop<T extends string | string[]>(input: T, size: number, options?: DividerLoopOptions): DividerResult<T>;
16
19
 
17
20
  declare function dividerNumberString<T extends string | string[]>(input: T, options?: DividerOptions): DividerResult<T>;
18
21
 
19
- export { type DividerArgs, type DividerOptionKey, type DividerOptions, type DividerResult, type DividerSeparators, divider, dividerFirst, dividerLast, dividerLoop, dividerNumberString };
22
+ export { type DividerArgs, type DividerLoopOptions, type DividerOptionKey, type DividerOptions, type DividerResult, type DividerSeparators, divider, dividerFirst, dividerLast, dividerLoop, dividerNumberString };
package/dist/index.d.ts CHANGED
@@ -3,6 +3,9 @@ declare const dividerOptionKeys: readonly ["flatten", "trim", "excludeEmpty"];
3
3
  type DividerOptionKey = (typeof dividerOptionKeys)[number];
4
4
  type DividerResult<T extends string | string[]> = T extends string ? string[] : string[][];
5
5
  type DividerOptions = Partial<Record<DividerOptionKey, boolean>>;
6
+ type DividerLoopOptions = DividerOptions & {
7
+ startOffset?: number;
8
+ };
6
9
  type DividerSeparators = (number | string)[];
7
10
  type DividerArgs = DividerSeparators | [...DividerSeparators, DividerOptions];
8
11
 
@@ -12,8 +15,8 @@ declare function dividerFirst(input: string | string[], ...args: DividerSeparato
12
15
 
13
16
  declare function dividerLast(input: string | string[], ...args: DividerSeparators): string;
14
17
 
15
- declare function dividerLoop<T extends string | string[]>(input: T, size: number, options?: DividerOptions): DividerResult<T>;
18
+ declare function dividerLoop<T extends string | string[]>(input: T, size: number, options?: DividerLoopOptions): DividerResult<T>;
16
19
 
17
20
  declare function dividerNumberString<T extends string | string[]>(input: T, options?: DividerOptions): DividerResult<T>;
18
21
 
19
- export { type DividerArgs, type DividerOptionKey, type DividerOptions, type DividerResult, type DividerSeparators, divider, dividerFirst, dividerLast, dividerLoop, dividerNumberString };
22
+ export { type DividerArgs, type DividerLoopOptions, type DividerOptionKey, type DividerOptions, type DividerResult, type DividerSeparators, divider, dividerFirst, dividerLast, dividerLoop, dividerNumberString };
package/dist/index.js CHANGED
@@ -157,12 +157,16 @@ function dividerLast(input, ...args) {
157
157
  }
158
158
 
159
159
  // src/utils/chunk.ts
160
- function generateIndexes(text, size) {
161
- const indexes = [];
162
- for (let i = size; i < text.length; i += size) {
163
- indexes.push(i);
160
+ function generateIndexes(str, size, startOffset = 0) {
161
+ if (!isPositiveInteger(size)) {
162
+ console.warn("generateIndexes: size must be a positive integer");
163
+ return [];
164
+ }
165
+ const result = [];
166
+ for (let i = startOffset + size; i < str.length; i += size) {
167
+ result.push(i);
164
168
  }
165
- return indexes;
169
+ return result;
166
170
  }
167
171
 
168
172
  // src/core/divider-loop.ts
@@ -171,7 +175,7 @@ function dividerLoop(input, size, options) {
171
175
  console.warn("dividerLoop: chunk size must be a positive number");
172
176
  return [];
173
177
  }
174
- const applyChunking = (str) => divider(str, ...generateIndexes(str, size));
178
+ const applyChunking = (str) => divider(str, ...generateIndexes(str, size, options?.startOffset ?? 0));
175
179
  if (isString(input)) {
176
180
  const result2 = applyChunking(input);
177
181
  return applyDividerOptions(result2, options ?? {});
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@nyaomaru/divider",
3
3
  "type": "module",
4
- "version": "1.7.2",
4
+ "version": "1.7.3",
5
5
  "description": "To divide string or string[] with a given separator",
6
6
  "main": "./dist/index.cjs",
7
7
  "module": "./dist/index.js",
@@ -35,19 +35,19 @@
35
35
  "author": "nyaomaru",
36
36
  "license": "MIT",
37
37
  "devDependencies": {
38
- "@eslint/js": "^9.22.0",
38
+ "@eslint/js": "^9.26.0",
39
39
  "@types/jest": "^29.5.14",
40
- "@types/node": "^22.13.4",
41
- "eslint": "^9.22.0",
42
- "eslint-config-prettier": "^10.0.1",
43
- "eslint-plugin-prettier": "^5.2.3",
40
+ "@types/node": "^22.15.12",
41
+ "eslint": "^9.26.0",
42
+ "eslint-config-prettier": "^10.1.2",
43
+ "eslint-plugin-prettier": "^5.4.0",
44
44
  "jest": "^29.7.0",
45
- "prettier": "^3.5.1",
46
- "ts-jest": "^29.2.5",
45
+ "prettier": "^3.5.3",
46
+ "ts-jest": "^29.3.2",
47
47
  "ts-node": "^10.9.2",
48
48
  "tsup": "^8.4.0",
49
- "tsx": "^4.19.3",
50
- "typescript": "^5.7.3"
49
+ "tsx": "^4.19.4",
50
+ "typescript": "^5.8.3"
51
51
  },
52
52
  "engines": {
53
53
  "node": ">=18"