@naturalcycles/js-lib 14.223.0 → 14.225.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/array/array.util.d.ts +11 -4
- package/dist/array/array.util.js +21 -5
- package/dist/types.d.ts +2 -0
- package/dist-esm/array/array.util.js +19 -4
- package/package.json +1 -1
- package/src/array/array.util.ts +19 -5
- package/src/types.ts +2 -0
|
@@ -103,12 +103,19 @@ export declare function _sortBy<T>(items: T[], mapper: Mapper<T, any>, mutate?:
|
|
|
103
103
|
*/
|
|
104
104
|
export declare function _sortDescBy<T>(items: T[], mapper: Mapper<T, any>, mutate?: boolean): T[];
|
|
105
105
|
/**
|
|
106
|
-
*
|
|
106
|
+
* Similar to `Array.find`, but the `predicate` may return `END` to stop the iteration early.
|
|
107
107
|
*
|
|
108
|
-
*
|
|
109
|
-
* iOS Safari only has it since 15.4
|
|
108
|
+
* Use `Array.find` if you don't need to stop the iteration early.
|
|
110
109
|
*/
|
|
111
|
-
export declare function
|
|
110
|
+
export declare function _find<T>(items: T[], predicate: AbortablePredicate<T>): T | undefined;
|
|
111
|
+
/**
|
|
112
|
+
* Similar to `Array.findLast`, but the `predicate` may return `END` to stop the iteration early.
|
|
113
|
+
*
|
|
114
|
+
* Use `Array.findLast` if you don't need to stop the iteration early, which is supported:
|
|
115
|
+
* - in Node since 18+
|
|
116
|
+
* - in iOS Safari since 15.4
|
|
117
|
+
*/
|
|
118
|
+
export declare function _findLast<T>(items: T[], predicate: AbortablePredicate<T>): T | undefined;
|
|
112
119
|
export declare function _takeWhile<T>(items: T[], predicate: Predicate<T>): T[];
|
|
113
120
|
export declare function _takeRightWhile<T>(items: T[], predicate: Predicate<T>): T[];
|
|
114
121
|
export declare function _dropWhile<T>(items: T[], predicate: Predicate<T>): T[];
|
package/dist/array/array.util.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
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._first = exports._lastOrUndefined = exports._last = exports._shuffle = exports._mapToObject = exports._sumBy = exports._sum = exports._difference = exports._intersectsWith = 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;
|
|
3
|
+
exports._zip = exports._minByOrUndefined = exports._maxByOrUndefined = exports._minBy = exports._maxBy = exports._max = exports._maxOrUndefined = exports._min = exports._minOrUndefined = exports._first = exports._lastOrUndefined = exports._last = exports._shuffle = exports._mapToObject = exports._sumBy = exports._sum = exports._difference = exports._intersectsWith = exports._intersection = exports._countBy = exports._count = exports._dropRightWhile = exports._dropWhile = exports._takeRightWhile = exports._takeWhile = exports._findLast = exports._find = 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
5
|
const types_1 = require("../types");
|
|
6
6
|
/**
|
|
@@ -172,13 +172,29 @@ function _sortDescBy(items, mapper, mutate = false) {
|
|
|
172
172
|
}
|
|
173
173
|
exports._sortDescBy = _sortDescBy;
|
|
174
174
|
/**
|
|
175
|
-
*
|
|
175
|
+
* Similar to `Array.find`, but the `predicate` may return `END` to stop the iteration early.
|
|
176
176
|
*
|
|
177
|
-
*
|
|
178
|
-
|
|
177
|
+
* Use `Array.find` if you don't need to stop the iteration early.
|
|
178
|
+
*/
|
|
179
|
+
function _find(items, predicate) {
|
|
180
|
+
for (const [i, item] of items.entries()) {
|
|
181
|
+
const result = predicate(item, i);
|
|
182
|
+
if (result === types_1.END)
|
|
183
|
+
return;
|
|
184
|
+
if (result)
|
|
185
|
+
return item;
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
exports._find = _find;
|
|
189
|
+
/**
|
|
190
|
+
* Similar to `Array.findLast`, but the `predicate` may return `END` to stop the iteration early.
|
|
191
|
+
*
|
|
192
|
+
* Use `Array.findLast` if you don't need to stop the iteration early, which is supported:
|
|
193
|
+
* - in Node since 18+
|
|
194
|
+
* - in iOS Safari since 15.4
|
|
179
195
|
*/
|
|
180
196
|
function _findLast(items, predicate) {
|
|
181
|
-
return
|
|
197
|
+
return _find(items.slice().reverse(), predicate);
|
|
182
198
|
}
|
|
183
199
|
exports._findLast = _findLast;
|
|
184
200
|
function _takeWhile(items, predicate) {
|
package/dist/types.d.ts
CHANGED
|
@@ -177,6 +177,8 @@ export type UnixTimestampNumber = number;
|
|
|
177
177
|
* @example 1628945450000
|
|
178
178
|
*/
|
|
179
179
|
export type UnixTimestampMillisNumber = number;
|
|
180
|
+
export type NumberOfHours = number;
|
|
181
|
+
export type NumberOfMinutes = number;
|
|
180
182
|
export type NumberOfSeconds = number;
|
|
181
183
|
export type NumberOfMilliseconds = number;
|
|
182
184
|
/**
|
|
@@ -159,13 +159,28 @@ export function _sortDescBy(items, mapper, mutate = false) {
|
|
|
159
159
|
return _sortBy(items, mapper, mutate, 'desc');
|
|
160
160
|
}
|
|
161
161
|
/**
|
|
162
|
-
*
|
|
162
|
+
* Similar to `Array.find`, but the `predicate` may return `END` to stop the iteration early.
|
|
163
163
|
*
|
|
164
|
-
*
|
|
165
|
-
|
|
164
|
+
* Use `Array.find` if you don't need to stop the iteration early.
|
|
165
|
+
*/
|
|
166
|
+
export function _find(items, predicate) {
|
|
167
|
+
for (const [i, item] of items.entries()) {
|
|
168
|
+
const result = predicate(item, i);
|
|
169
|
+
if (result === END)
|
|
170
|
+
return;
|
|
171
|
+
if (result)
|
|
172
|
+
return item;
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
/**
|
|
176
|
+
* Similar to `Array.findLast`, but the `predicate` may return `END` to stop the iteration early.
|
|
177
|
+
*
|
|
178
|
+
* Use `Array.findLast` if you don't need to stop the iteration early, which is supported:
|
|
179
|
+
* - in Node since 18+
|
|
180
|
+
* - in iOS Safari since 15.4
|
|
166
181
|
*/
|
|
167
182
|
export function _findLast(items, predicate) {
|
|
168
|
-
return
|
|
183
|
+
return _find(items.slice().reverse(), predicate);
|
|
169
184
|
}
|
|
170
185
|
export function _takeWhile(items, predicate) {
|
|
171
186
|
let proceed = true;
|
package/package.json
CHANGED
package/src/array/array.util.ts
CHANGED
|
@@ -195,13 +195,27 @@ export function _sortDescBy<T>(items: T[], mapper: Mapper<T, any>, mutate = fals
|
|
|
195
195
|
}
|
|
196
196
|
|
|
197
197
|
/**
|
|
198
|
-
*
|
|
198
|
+
* Similar to `Array.find`, but the `predicate` may return `END` to stop the iteration early.
|
|
199
199
|
*
|
|
200
|
-
*
|
|
201
|
-
* iOS Safari only has it since 15.4
|
|
200
|
+
* Use `Array.find` if you don't need to stop the iteration early.
|
|
202
201
|
*/
|
|
203
|
-
export function
|
|
204
|
-
|
|
202
|
+
export function _find<T>(items: T[], predicate: AbortablePredicate<T>): T | undefined {
|
|
203
|
+
for (const [i, item] of items.entries()) {
|
|
204
|
+
const result = predicate(item, i)
|
|
205
|
+
if (result === END) return
|
|
206
|
+
if (result) return item
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
/**
|
|
211
|
+
* Similar to `Array.findLast`, but the `predicate` may return `END` to stop the iteration early.
|
|
212
|
+
*
|
|
213
|
+
* Use `Array.findLast` if you don't need to stop the iteration early, which is supported:
|
|
214
|
+
* - in Node since 18+
|
|
215
|
+
* - in iOS Safari since 15.4
|
|
216
|
+
*/
|
|
217
|
+
export function _findLast<T>(items: T[], predicate: AbortablePredicate<T>): T | undefined {
|
|
218
|
+
return _find(items.slice().reverse(), predicate)
|
|
205
219
|
}
|
|
206
220
|
|
|
207
221
|
export function _takeWhile<T>(items: T[], predicate: Predicate<T>): T[] {
|
package/src/types.ts
CHANGED
|
@@ -233,6 +233,8 @@ export type UnixTimestampNumber = number
|
|
|
233
233
|
*/
|
|
234
234
|
export type UnixTimestampMillisNumber = number
|
|
235
235
|
|
|
236
|
+
export type NumberOfHours = number
|
|
237
|
+
export type NumberOfMinutes = number
|
|
236
238
|
export type NumberOfSeconds = number
|
|
237
239
|
export type NumberOfMilliseconds = number
|
|
238
240
|
|