@naturalcycles/js-lib 14.199.0 → 14.201.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/abort.d.ts +24 -0
- package/dist/abort.js +16 -0
- package/dist/array/array.util.d.ts +5 -1
- package/dist/array/array.util.js +17 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1 -0
- package/dist-esm/abort.js +12 -0
- package/dist-esm/array/array.util.js +15 -0
- package/dist-esm/index.js +1 -0
- package/package.json +1 -1
- package/src/abort.ts +30 -0
- package/src/array/array.util.ts +24 -1
- package/src/index.ts +1 -0
package/dist/abort.d.ts
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Like AbortSignal, but it can "abort itself" via the `.abort()` method.
|
|
3
|
+
*
|
|
4
|
+
* Similar to how DeferredPromise is both a Promise and has `.resolve()` and `.reject()` methods.
|
|
5
|
+
*
|
|
6
|
+
* This is to simplify the AbortController/AbortSignal usage.
|
|
7
|
+
*
|
|
8
|
+
* Before this - you need to keep track of 2 things: AbortController and AbortSignal.
|
|
9
|
+
*
|
|
10
|
+
* After - you are good with only AbortableSignal, which can do both.
|
|
11
|
+
* And it's compatible with AbortSignal (because it extends it).
|
|
12
|
+
*
|
|
13
|
+
* @experimental
|
|
14
|
+
*/
|
|
15
|
+
export interface AbortableSignal extends AbortSignal {
|
|
16
|
+
abort: AbortController['abort'];
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Creates AbortableSignal,
|
|
20
|
+
* which is like AbortSignal, but can "abort itself" with `.abort()` method.
|
|
21
|
+
*
|
|
22
|
+
* @experimental
|
|
23
|
+
*/
|
|
24
|
+
export declare function createAbortableSignal(): AbortableSignal;
|
package/dist/abort.js
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.createAbortableSignal = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* Creates AbortableSignal,
|
|
6
|
+
* which is like AbortSignal, but can "abort itself" with `.abort()` method.
|
|
7
|
+
*
|
|
8
|
+
* @experimental
|
|
9
|
+
*/
|
|
10
|
+
function createAbortableSignal() {
|
|
11
|
+
const ac = new AbortController();
|
|
12
|
+
return Object.assign(ac.signal, {
|
|
13
|
+
abort: ac.abort.bind(ac),
|
|
14
|
+
});
|
|
15
|
+
}
|
|
16
|
+
exports.createAbortableSignal = createAbortableSignal;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { AbortablePredicate, FalsyValue, Mapper, Predicate, SortDirection, StringMap } from '../types';
|
|
2
2
|
/**
|
|
3
3
|
* Creates an array of elements split into groups the length of size. If collection can’t be split evenly, the
|
|
4
4
|
* final chunk will be the remaining elements.
|
|
@@ -110,6 +110,10 @@ export declare function _takeWhile<T>(items: T[], predicate: Predicate<T>): T[];
|
|
|
110
110
|
export declare function _takeRightWhile<T>(items: T[], predicate: Predicate<T>): T[];
|
|
111
111
|
export declare function _dropWhile<T>(items: T[], predicate: Predicate<T>): T[];
|
|
112
112
|
export declare function _dropRightWhile<T>(items: T[], predicate: Predicate<T>): T[];
|
|
113
|
+
/**
|
|
114
|
+
* Counts how many items match the predicate.
|
|
115
|
+
*/
|
|
116
|
+
export declare function _count<T>(items: T[], predicate: AbortablePredicate<T>): number;
|
|
113
117
|
export declare function _countBy<T>(items: T[], mapper: Mapper<T, any>): StringMap<number>;
|
|
114
118
|
/**
|
|
115
119
|
* @example
|
package/dist/array/array.util.js
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports._zip = exports._minByOrUndefined = exports._maxByOrUndefined = exports._minBy = exports._maxBy = exports._max = exports._maxOrUndefined = exports._min = exports._minOrUndefined = exports._lastOrUndefined = exports._last = exports._shuffle = exports._mapToObject = exports._sumBy = exports._sum = exports._difference = exports._intersection = exports._countBy = exports._dropRightWhile = exports._dropWhile = exports._takeRightWhile = exports._takeWhile = exports._findLast = exports._sortDescBy = exports._sortBy = exports._groupBy = exports._mapBy = exports._by = exports._uniqBy = exports._pushUniqBy = exports._pushUniq = exports._uniq = exports._chunk = void 0;
|
|
3
|
+
exports._zip = exports._minByOrUndefined = exports._maxByOrUndefined = exports._minBy = exports._maxBy = exports._max = exports._maxOrUndefined = exports._min = exports._minOrUndefined = exports._lastOrUndefined = exports._last = exports._shuffle = exports._mapToObject = exports._sumBy = exports._sum = exports._difference = exports._intersection = exports._countBy = exports._count = exports._dropRightWhile = exports._dropWhile = exports._takeRightWhile = exports._takeWhile = exports._findLast = exports._sortDescBy = exports._sortBy = exports._groupBy = exports._mapBy = exports._by = exports._uniqBy = exports._pushUniqBy = exports._pushUniq = exports._uniq = exports._chunk = void 0;
|
|
4
4
|
const is_util_1 = require("../is.util");
|
|
5
|
+
const types_1 = require("../types");
|
|
5
6
|
/**
|
|
6
7
|
* Creates an array of elements split into groups the length of size. If collection can’t be split evenly, the
|
|
7
8
|
* final chunk will be the remaining elements.
|
|
@@ -200,6 +201,21 @@ function _dropRightWhile(items, predicate) {
|
|
|
200
201
|
.reverse();
|
|
201
202
|
}
|
|
202
203
|
exports._dropRightWhile = _dropRightWhile;
|
|
204
|
+
/**
|
|
205
|
+
* Counts how many items match the predicate.
|
|
206
|
+
*/
|
|
207
|
+
function _count(items, predicate) {
|
|
208
|
+
let count = 0;
|
|
209
|
+
for (const [i, item] of items.entries()) {
|
|
210
|
+
const r = predicate(item, i);
|
|
211
|
+
if (r === types_1.END)
|
|
212
|
+
break;
|
|
213
|
+
if (r)
|
|
214
|
+
count++;
|
|
215
|
+
}
|
|
216
|
+
return count;
|
|
217
|
+
}
|
|
218
|
+
exports._count = _count;
|
|
203
219
|
function _countBy(items, mapper) {
|
|
204
220
|
const map = {};
|
|
205
221
|
items.forEach((item, index) => {
|
package/dist/index.d.ts
CHANGED
package/dist/index.js
CHANGED
|
@@ -85,6 +85,7 @@ tslib_1.__exportStar(require("./env/buildInfo"), exports);
|
|
|
85
85
|
tslib_1.__exportStar(require("./form.util"), exports);
|
|
86
86
|
tslib_1.__exportStar(require("./semver"), exports);
|
|
87
87
|
tslib_1.__exportStar(require("./web"), exports);
|
|
88
|
+
tslib_1.__exportStar(require("./abort"), exports);
|
|
88
89
|
tslib_1.__exportStar(require("./polyfill"), exports);
|
|
89
90
|
tslib_1.__exportStar(require("./zod/zod.util"), exports);
|
|
90
91
|
tslib_1.__exportStar(require("./zod/zod.shared.schemas"), exports);
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Creates AbortableSignal,
|
|
3
|
+
* which is like AbortSignal, but can "abort itself" with `.abort()` method.
|
|
4
|
+
*
|
|
5
|
+
* @experimental
|
|
6
|
+
*/
|
|
7
|
+
export function createAbortableSignal() {
|
|
8
|
+
const ac = new AbortController();
|
|
9
|
+
return Object.assign(ac.signal, {
|
|
10
|
+
abort: ac.abort.bind(ac),
|
|
11
|
+
});
|
|
12
|
+
}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { _isNotNullish } from '../is.util';
|
|
2
|
+
import { END, } from '../types';
|
|
2
3
|
/**
|
|
3
4
|
* Creates an array of elements split into groups the length of size. If collection can’t be split evenly, the
|
|
4
5
|
* final chunk will be the remaining elements.
|
|
@@ -182,6 +183,20 @@ export function _dropRightWhile(items, predicate) {
|
|
|
182
183
|
.filter((v, index) => (proceed || (proceed = !predicate(v, index))))
|
|
183
184
|
.reverse();
|
|
184
185
|
}
|
|
186
|
+
/**
|
|
187
|
+
* Counts how many items match the predicate.
|
|
188
|
+
*/
|
|
189
|
+
export function _count(items, predicate) {
|
|
190
|
+
let count = 0;
|
|
191
|
+
for (const [i, item] of items.entries()) {
|
|
192
|
+
const r = predicate(item, i);
|
|
193
|
+
if (r === END)
|
|
194
|
+
break;
|
|
195
|
+
if (r)
|
|
196
|
+
count++;
|
|
197
|
+
}
|
|
198
|
+
return count;
|
|
199
|
+
}
|
|
185
200
|
export function _countBy(items, mapper) {
|
|
186
201
|
const map = {};
|
|
187
202
|
items.forEach((item, index) => {
|
package/dist-esm/index.js
CHANGED
package/package.json
CHANGED
package/src/abort.ts
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Like AbortSignal, but it can "abort itself" via the `.abort()` method.
|
|
3
|
+
*
|
|
4
|
+
* Similar to how DeferredPromise is both a Promise and has `.resolve()` and `.reject()` methods.
|
|
5
|
+
*
|
|
6
|
+
* This is to simplify the AbortController/AbortSignal usage.
|
|
7
|
+
*
|
|
8
|
+
* Before this - you need to keep track of 2 things: AbortController and AbortSignal.
|
|
9
|
+
*
|
|
10
|
+
* After - you are good with only AbortableSignal, which can do both.
|
|
11
|
+
* And it's compatible with AbortSignal (because it extends it).
|
|
12
|
+
*
|
|
13
|
+
* @experimental
|
|
14
|
+
*/
|
|
15
|
+
export interface AbortableSignal extends AbortSignal {
|
|
16
|
+
abort: AbortController['abort']
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* Creates AbortableSignal,
|
|
21
|
+
* which is like AbortSignal, but can "abort itself" with `.abort()` method.
|
|
22
|
+
*
|
|
23
|
+
* @experimental
|
|
24
|
+
*/
|
|
25
|
+
export function createAbortableSignal(): AbortableSignal {
|
|
26
|
+
const ac = new AbortController()
|
|
27
|
+
return Object.assign(ac.signal, {
|
|
28
|
+
abort: ac.abort.bind(ac),
|
|
29
|
+
})
|
|
30
|
+
}
|
package/src/array/array.util.ts
CHANGED
|
@@ -1,5 +1,13 @@
|
|
|
1
1
|
import { _isNotNullish } from '../is.util'
|
|
2
|
-
import
|
|
2
|
+
import {
|
|
3
|
+
AbortablePredicate,
|
|
4
|
+
END,
|
|
5
|
+
FalsyValue,
|
|
6
|
+
Mapper,
|
|
7
|
+
Predicate,
|
|
8
|
+
SortDirection,
|
|
9
|
+
StringMap,
|
|
10
|
+
} from '../types'
|
|
3
11
|
|
|
4
12
|
/**
|
|
5
13
|
* Creates an array of elements split into groups the length of size. If collection can’t be split evenly, the
|
|
@@ -216,6 +224,21 @@ export function _dropRightWhile<T>(items: T[], predicate: Predicate<T>): T[] {
|
|
|
216
224
|
.reverse()
|
|
217
225
|
}
|
|
218
226
|
|
|
227
|
+
/**
|
|
228
|
+
* Counts how many items match the predicate.
|
|
229
|
+
*/
|
|
230
|
+
export function _count<T>(items: T[], predicate: AbortablePredicate<T>): number {
|
|
231
|
+
let count = 0
|
|
232
|
+
|
|
233
|
+
for (const [i, item] of items.entries()) {
|
|
234
|
+
const r = predicate(item, i)
|
|
235
|
+
if (r === END) break
|
|
236
|
+
if (r) count++
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
return count
|
|
240
|
+
}
|
|
241
|
+
|
|
219
242
|
export function _countBy<T>(items: T[], mapper: Mapper<T, any>): StringMap<number> {
|
|
220
243
|
const map: StringMap<number> = {}
|
|
221
244
|
|
package/src/index.ts
CHANGED