@webdeveric/utils 0.60.0 → 0.62.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/chunk.js +16 -0
- package/dist/cjs/index.js +1 -0
- package/dist/mjs/chunk.js +13 -0
- package/dist/mjs/index.js +1 -0
- package/dist/types/chunk.d.ts +1 -0
- package/dist/types/index.d.ts +1 -0
- package/dist/types/predicate/factory/allOf.d.ts +2 -1
- package/dist/types/predicate/factory/anyOf.d.ts +2 -1
- package/dist/types/types/arrays.d.ts +1 -0
- package/package.json +7 -7
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.chunk = chunk;
|
|
4
|
+
function* chunk(items, chunkSize) {
|
|
5
|
+
if (!Number.isSafeInteger(chunkSize) || chunkSize <= 0) {
|
|
6
|
+
throw new RangeError('Chunk size must be an integer greater than 0');
|
|
7
|
+
}
|
|
8
|
+
const length = items.length;
|
|
9
|
+
if (length === 0) {
|
|
10
|
+
yield items;
|
|
11
|
+
return;
|
|
12
|
+
}
|
|
13
|
+
for (let i = 0; i < length; i += chunkSize) {
|
|
14
|
+
yield items.slice(i, i + chunkSize);
|
|
15
|
+
}
|
|
16
|
+
}
|
package/dist/cjs/index.js
CHANGED
|
@@ -22,6 +22,7 @@ __exportStar(require("./asArray.js"), exports);
|
|
|
22
22
|
__exportStar(require("./asError.js"), exports);
|
|
23
23
|
__exportStar(require("./capitalize.js"), exports);
|
|
24
24
|
__exportStar(require("./cartesian.js"), exports);
|
|
25
|
+
__exportStar(require("./chunk.js"), exports);
|
|
25
26
|
__exportStar(require("./clamp.js"), exports);
|
|
26
27
|
__exportStar(require("./combinations.js"), exports);
|
|
27
28
|
__exportStar(require("./comment.js"), exports);
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
export function* chunk(items, chunkSize) {
|
|
2
|
+
if (!Number.isSafeInteger(chunkSize) || chunkSize <= 0) {
|
|
3
|
+
throw new RangeError('Chunk size must be an integer greater than 0');
|
|
4
|
+
}
|
|
5
|
+
const length = items.length;
|
|
6
|
+
if (length === 0) {
|
|
7
|
+
yield items;
|
|
8
|
+
return;
|
|
9
|
+
}
|
|
10
|
+
for (let i = 0; i < length; i += chunkSize) {
|
|
11
|
+
yield items.slice(i, i + chunkSize);
|
|
12
|
+
}
|
|
13
|
+
}
|
package/dist/mjs/index.js
CHANGED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function chunk<T>(items: T[], chunkSize: number): Generator<T[], undefined, undefined>;
|
package/dist/types/index.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { NonEmptyArray } from '../../types/arrays.js';
|
|
1
2
|
import type { InferPredicatesReturnType, TypePredicateFn } from '../../types/functions.js';
|
|
2
3
|
import type { IntersectionOf } from '../../types/utils.js';
|
|
3
|
-
export declare const allOf: <Predicates extends TypePredicateFn<unknown
|
|
4
|
+
export declare const allOf: <Predicates extends NonEmptyArray<TypePredicateFn<unknown>>>(...predicates: Predicates) => TypePredicateFn<IntersectionOf<InferPredicatesReturnType<Predicates>>>;
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { NonEmptyArray } from '../../types/arrays.js';
|
|
1
2
|
import type { InferPredicatesReturnType, TypePredicateFn } from '../../types/functions.js';
|
|
2
3
|
import type { UnionOf } from '../../types/utils.js';
|
|
3
|
-
export declare const anyOf: <Predicates extends TypePredicateFn<unknown
|
|
4
|
+
export declare const anyOf: <Predicates extends NonEmptyArray<TypePredicateFn<unknown>>>(...predicates: Predicates) => TypePredicateFn<UnionOf<InferPredicatesReturnType<Predicates>>>;
|
|
@@ -8,3 +8,4 @@ export type GetLength<A extends any[]> = A extends {
|
|
|
8
8
|
export type IfLength<A extends any[], L extends number, T, F> = GetLength<A> extends L ? T : F;
|
|
9
9
|
export type IfEmpty<A extends any[], T, F> = GetLength<A> extends 0 ? T : F;
|
|
10
10
|
export type IfArray<Type, T, F> = Type extends unknown[] ? T : F;
|
|
11
|
+
export type NonEmptyArray<Type> = [Type, ...Type[]];
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@webdeveric/utils",
|
|
3
3
|
"description": "Just another collection of utilities.",
|
|
4
|
-
"version": "0.
|
|
4
|
+
"version": "0.62.0",
|
|
5
5
|
"publishConfig": {
|
|
6
6
|
"access": "public"
|
|
7
7
|
},
|
|
@@ -66,7 +66,7 @@
|
|
|
66
66
|
"url": "https://github.com/webdeveric/utils/issues"
|
|
67
67
|
},
|
|
68
68
|
"homepage": "https://github.com/webdeveric/utils/#readme",
|
|
69
|
-
"packageManager": "pnpm@10.
|
|
69
|
+
"packageManager": "pnpm@10.12.1+sha512.f0dda8580f0ee9481c5c79a1d927b9164f2c478e90992ad268bbb2465a736984391d6333d2c327913578b2804af33474ca554ba29c04a8b13060a717675ae3ac",
|
|
70
70
|
"scripts": {
|
|
71
71
|
"clean": "rimraf ./dist/",
|
|
72
72
|
"prebuild": "pnpm clean",
|
|
@@ -87,8 +87,8 @@
|
|
|
87
87
|
"devDependencies": {
|
|
88
88
|
"@commitlint/config-conventional": "^19.8.1",
|
|
89
89
|
"@commitlint/types": "^19.8.1",
|
|
90
|
-
"@types/node": "^22.15.
|
|
91
|
-
"@vitest/coverage-v8": "^3.
|
|
90
|
+
"@types/node": "^22.15.30",
|
|
91
|
+
"@vitest/coverage-v8": "^3.2.3",
|
|
92
92
|
"@webdeveric/eslint-config-ts": "^0.11.0",
|
|
93
93
|
"@webdeveric/prettier-config": "^0.3.0",
|
|
94
94
|
"commitlint": "^19.8.1",
|
|
@@ -97,7 +97,7 @@
|
|
|
97
97
|
"cspell": "^9.0.2",
|
|
98
98
|
"eslint": "^8.57.1",
|
|
99
99
|
"eslint-config-prettier": "^10.1.5",
|
|
100
|
-
"eslint-import-resolver-typescript": "^4.4.
|
|
100
|
+
"eslint-import-resolver-typescript": "^4.4.3",
|
|
101
101
|
"eslint-plugin-import": "^2.31.0",
|
|
102
102
|
"husky": "^9.1.7",
|
|
103
103
|
"jsdom": "^26.1.0",
|
|
@@ -106,8 +106,8 @@
|
|
|
106
106
|
"rimraf": "^6.0.1",
|
|
107
107
|
"semantic-release": "^24.2.5",
|
|
108
108
|
"typescript": "^5.8.3",
|
|
109
|
-
"validate-package-exports": "^0.
|
|
110
|
-
"vitest": "^3.
|
|
109
|
+
"validate-package-exports": "^0.11.0",
|
|
110
|
+
"vitest": "^3.2.3"
|
|
111
111
|
},
|
|
112
112
|
"pnpm": {
|
|
113
113
|
"onlyBuiltDependencies": [
|