@nyaomaru/divider 1.9.0 → 1.9.2
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/README.md +6 -0
- package/dist/index.cjs +4 -2
- package/dist/index.d.cts +5 -5
- package/dist/index.d.ts +5 -5
- package/dist/index.js +4 -2
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -265,3 +265,9 @@ We welcome contributions!
|
|
|
265
265
|
Please read our [CONTRIBUTING.md](./CONTRIBUTING.md) guide before submitting a PR.
|
|
266
266
|
|
|
267
267
|
Thank you for your contribution. 😺
|
|
268
|
+
|
|
269
|
+
## 📚 Additional Documents
|
|
270
|
+
|
|
271
|
+
- [DEVELOPER.md](./DEVELOPER.md) — Development setup and contributor guide
|
|
272
|
+
- [CODE_OF_CONDUCT.md](./CODE_OF_CONDUCT.md) — Community standards and conduct
|
|
273
|
+
- [CHANGELOG.md](./CHANGELOG.md) — Version history and notable changes
|
package/dist/index.cjs
CHANGED
|
@@ -316,7 +316,7 @@ function dividerLast(input, ...args) {
|
|
|
316
316
|
return getLastElement(result, "");
|
|
317
317
|
}
|
|
318
318
|
|
|
319
|
-
// src/utils/
|
|
319
|
+
// src/utils/generate-indexes.ts
|
|
320
320
|
function generateIndexes(str, size, startOffset = 0) {
|
|
321
321
|
if (!isPositiveInteger(size)) {
|
|
322
322
|
console.warn("generateIndexes: size must be a positive integer");
|
|
@@ -329,7 +329,7 @@ function generateIndexes(str, size, startOffset = 0) {
|
|
|
329
329
|
return result;
|
|
330
330
|
}
|
|
331
331
|
|
|
332
|
-
// src/
|
|
332
|
+
// src/utils/chunk.ts
|
|
333
333
|
var MIN_ALLOWED_CHUNKS = 0;
|
|
334
334
|
function shouldTruncateChunks(chunks, maxChunks) {
|
|
335
335
|
return isNumber(maxChunks) && maxChunks > MIN_ALLOWED_CHUNKS && maxChunks < chunks.length;
|
|
@@ -340,6 +340,8 @@ function truncateChunksToMax(chunks, maxChunks) {
|
|
|
340
340
|
const tail = chunks.slice(headCount).join("");
|
|
341
341
|
return [...head, tail];
|
|
342
342
|
}
|
|
343
|
+
|
|
344
|
+
// src/core/divider-loop.ts
|
|
343
345
|
function createChunksFromString(str, size, startOffset, maxChunks) {
|
|
344
346
|
const indexes = generateIndexes(str, size, startOffset);
|
|
345
347
|
const chunks = divider(str, ...indexes);
|
package/dist/index.d.cts
CHANGED
|
@@ -16,7 +16,7 @@ declare const DividerExcludeModes: {
|
|
|
16
16
|
|
|
17
17
|
type DividerExcludeMode = (typeof DividerExcludeModes)[keyof typeof DividerExcludeModes];
|
|
18
18
|
type StringInput = string;
|
|
19
|
-
type StringArrayInput = string[];
|
|
19
|
+
type StringArrayInput = readonly string[];
|
|
20
20
|
type DividerInput = StringInput | StringArrayInput;
|
|
21
21
|
type DividerStringResult = string[];
|
|
22
22
|
type DividerArrayResult = string[][];
|
|
@@ -65,7 +65,7 @@ declare function divider<T extends DividerInput>(input: T, ...args: DividerArgs)
|
|
|
65
65
|
* dividerFirst("hello-world", "-") // returns "hello"
|
|
66
66
|
* dividerFirst("abc123def", 3) // returns "abc"
|
|
67
67
|
*/
|
|
68
|
-
declare function dividerFirst(input:
|
|
68
|
+
declare function dividerFirst(input: DividerInput, ...args: DividerSeparators): string;
|
|
69
69
|
|
|
70
70
|
/**
|
|
71
71
|
* Extracts the last segment after dividing the input using specified separators.
|
|
@@ -77,7 +77,7 @@ declare function dividerFirst(input: string | string[], ...args: DividerSeparato
|
|
|
77
77
|
* dividerLast("hello-world", "-") // returns "world"
|
|
78
78
|
* dividerLast("abc123def", 3) // returns "def"
|
|
79
79
|
*/
|
|
80
|
-
declare function dividerLast(input:
|
|
80
|
+
declare function dividerLast(input: DividerInput, ...args: DividerSeparators): string;
|
|
81
81
|
|
|
82
82
|
/**
|
|
83
83
|
* Divides input into chunks of specified size with optional configuration.
|
|
@@ -98,7 +98,7 @@ declare function dividerLast(input: string | string[], ...args: DividerSeparator
|
|
|
98
98
|
* dividerLoop("abcdef", 2) // returns ["ab", "cd", "ef"]
|
|
99
99
|
* dividerLoop("abcdef", 2, { maxChunks: 2 }) // returns ["ab", "cdef"]
|
|
100
100
|
*/
|
|
101
|
-
declare function dividerLoop<T extends
|
|
101
|
+
declare function dividerLoop<T extends DividerInput>(input: T, size: number, options?: DividerLoopOptions): DividerResult<T>;
|
|
102
102
|
|
|
103
103
|
/**
|
|
104
104
|
* Divides a string or array of strings by separating numbers from non-numbers.
|
|
@@ -113,7 +113,7 @@ declare function dividerLoop<T extends string | string[]>(input: T, size: number
|
|
|
113
113
|
* dividerNumberString("abc123def") // returns ["abc", "123", "def"]
|
|
114
114
|
* dividerNumberString("test42") // returns ["test", "42"]
|
|
115
115
|
*/
|
|
116
|
-
declare function dividerNumberString<T extends
|
|
116
|
+
declare function dividerNumberString<T extends DividerInput>(input: T, options?: DividerOptions): DividerResult<T>;
|
|
117
117
|
|
|
118
118
|
type EmailDividerOptions = Pick<DividerOptions, 'trim'> & {
|
|
119
119
|
/** Split top-level domain from the rest of the email address. */
|
package/dist/index.d.ts
CHANGED
|
@@ -16,7 +16,7 @@ declare const DividerExcludeModes: {
|
|
|
16
16
|
|
|
17
17
|
type DividerExcludeMode = (typeof DividerExcludeModes)[keyof typeof DividerExcludeModes];
|
|
18
18
|
type StringInput = string;
|
|
19
|
-
type StringArrayInput = string[];
|
|
19
|
+
type StringArrayInput = readonly string[];
|
|
20
20
|
type DividerInput = StringInput | StringArrayInput;
|
|
21
21
|
type DividerStringResult = string[];
|
|
22
22
|
type DividerArrayResult = string[][];
|
|
@@ -65,7 +65,7 @@ declare function divider<T extends DividerInput>(input: T, ...args: DividerArgs)
|
|
|
65
65
|
* dividerFirst("hello-world", "-") // returns "hello"
|
|
66
66
|
* dividerFirst("abc123def", 3) // returns "abc"
|
|
67
67
|
*/
|
|
68
|
-
declare function dividerFirst(input:
|
|
68
|
+
declare function dividerFirst(input: DividerInput, ...args: DividerSeparators): string;
|
|
69
69
|
|
|
70
70
|
/**
|
|
71
71
|
* Extracts the last segment after dividing the input using specified separators.
|
|
@@ -77,7 +77,7 @@ declare function dividerFirst(input: string | string[], ...args: DividerSeparato
|
|
|
77
77
|
* dividerLast("hello-world", "-") // returns "world"
|
|
78
78
|
* dividerLast("abc123def", 3) // returns "def"
|
|
79
79
|
*/
|
|
80
|
-
declare function dividerLast(input:
|
|
80
|
+
declare function dividerLast(input: DividerInput, ...args: DividerSeparators): string;
|
|
81
81
|
|
|
82
82
|
/**
|
|
83
83
|
* Divides input into chunks of specified size with optional configuration.
|
|
@@ -98,7 +98,7 @@ declare function dividerLast(input: string | string[], ...args: DividerSeparator
|
|
|
98
98
|
* dividerLoop("abcdef", 2) // returns ["ab", "cd", "ef"]
|
|
99
99
|
* dividerLoop("abcdef", 2, { maxChunks: 2 }) // returns ["ab", "cdef"]
|
|
100
100
|
*/
|
|
101
|
-
declare function dividerLoop<T extends
|
|
101
|
+
declare function dividerLoop<T extends DividerInput>(input: T, size: number, options?: DividerLoopOptions): DividerResult<T>;
|
|
102
102
|
|
|
103
103
|
/**
|
|
104
104
|
* Divides a string or array of strings by separating numbers from non-numbers.
|
|
@@ -113,7 +113,7 @@ declare function dividerLoop<T extends string | string[]>(input: T, size: number
|
|
|
113
113
|
* dividerNumberString("abc123def") // returns ["abc", "123", "def"]
|
|
114
114
|
* dividerNumberString("test42") // returns ["test", "42"]
|
|
115
115
|
*/
|
|
116
|
-
declare function dividerNumberString<T extends
|
|
116
|
+
declare function dividerNumberString<T extends DividerInput>(input: T, options?: DividerOptions): DividerResult<T>;
|
|
117
117
|
|
|
118
118
|
type EmailDividerOptions = Pick<DividerOptions, 'trim'> & {
|
|
119
119
|
/** Split top-level domain from the rest of the email address. */
|
package/dist/index.js
CHANGED
|
@@ -283,7 +283,7 @@ function dividerLast(input, ...args) {
|
|
|
283
283
|
return getLastElement(result, "");
|
|
284
284
|
}
|
|
285
285
|
|
|
286
|
-
// src/utils/
|
|
286
|
+
// src/utils/generate-indexes.ts
|
|
287
287
|
function generateIndexes(str, size, startOffset = 0) {
|
|
288
288
|
if (!isPositiveInteger(size)) {
|
|
289
289
|
console.warn("generateIndexes: size must be a positive integer");
|
|
@@ -296,7 +296,7 @@ function generateIndexes(str, size, startOffset = 0) {
|
|
|
296
296
|
return result;
|
|
297
297
|
}
|
|
298
298
|
|
|
299
|
-
// src/
|
|
299
|
+
// src/utils/chunk.ts
|
|
300
300
|
var MIN_ALLOWED_CHUNKS = 0;
|
|
301
301
|
function shouldTruncateChunks(chunks, maxChunks) {
|
|
302
302
|
return isNumber(maxChunks) && maxChunks > MIN_ALLOWED_CHUNKS && maxChunks < chunks.length;
|
|
@@ -307,6 +307,8 @@ function truncateChunksToMax(chunks, maxChunks) {
|
|
|
307
307
|
const tail = chunks.slice(headCount).join("");
|
|
308
308
|
return [...head, tail];
|
|
309
309
|
}
|
|
310
|
+
|
|
311
|
+
// src/core/divider-loop.ts
|
|
310
312
|
function createChunksFromString(str, size, startOffset, maxChunks) {
|
|
311
313
|
const indexes = generateIndexes(str, size, startOffset);
|
|
312
314
|
const chunks = divider(str, ...indexes);
|