@naturalcycles/js-lib 14.207.0 → 14.209.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 +16 -1
- package/dist/array/array.util.js +23 -5
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1 -0
- package/dist/string/regex.d.ts +6 -0
- package/dist/string/regex.js +9 -0
- package/dist-esm/array/array.util.js +21 -4
- package/dist-esm/index.js +1 -0
- package/dist-esm/string/regex.js +6 -0
- package/package.json +1 -1
- package/src/array/array.util.ts +22 -3
- package/src/index.ts +1 -0
- package/src/string/regex.ts +6 -0
|
@@ -116,11 +116,26 @@ export declare function _dropRightWhile<T>(items: T[], predicate: Predicate<T>):
|
|
|
116
116
|
export declare function _count<T>(items: T[], predicate: AbortablePredicate<T>): number;
|
|
117
117
|
export declare function _countBy<T>(items: T[], mapper: Mapper<T, any>): StringMap<number>;
|
|
118
118
|
/**
|
|
119
|
+
* Returns an intersection between 2 arrays.
|
|
120
|
+
*
|
|
121
|
+
* Intersecion means an array of items that are present in both of the arrays.
|
|
122
|
+
*
|
|
123
|
+
* It's more performant to pass a Set as a second argument.
|
|
124
|
+
*
|
|
119
125
|
* @example
|
|
120
126
|
* _intersection([2, 1], [2, 3])
|
|
121
127
|
* // [2]
|
|
122
128
|
*/
|
|
123
|
-
export declare function _intersection<T>(
|
|
129
|
+
export declare function _intersection<T>(a1: T[], a2: T[] | Set<T>): T[];
|
|
130
|
+
/**
|
|
131
|
+
* Returns true if there is at least 1 item common between 2 arrays.
|
|
132
|
+
* Otherwise returns false.
|
|
133
|
+
*
|
|
134
|
+
* It's more performant to use that versus `_intersection(a1, a2).length > 0`.
|
|
135
|
+
*
|
|
136
|
+
* Passing second array as Set is more performant (it'll skip turning the array into Set in-place).
|
|
137
|
+
*/
|
|
138
|
+
export declare function _intersectsWith<T>(a1: T[], a2: T[] | Set<T>): boolean;
|
|
124
139
|
/**
|
|
125
140
|
* @example
|
|
126
141
|
* _difference([2, 1], [2, 3])
|
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._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;
|
|
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._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;
|
|
4
4
|
const is_util_1 = require("../is.util");
|
|
5
5
|
const types_1 = require("../types");
|
|
6
6
|
/**
|
|
@@ -227,16 +227,34 @@ function _countBy(items, mapper) {
|
|
|
227
227
|
exports._countBy = _countBy;
|
|
228
228
|
// investigate: _groupBy
|
|
229
229
|
/**
|
|
230
|
+
* Returns an intersection between 2 arrays.
|
|
231
|
+
*
|
|
232
|
+
* Intersecion means an array of items that are present in both of the arrays.
|
|
233
|
+
*
|
|
234
|
+
* It's more performant to pass a Set as a second argument.
|
|
235
|
+
*
|
|
230
236
|
* @example
|
|
231
237
|
* _intersection([2, 1], [2, 3])
|
|
232
238
|
* // [2]
|
|
233
239
|
*/
|
|
234
|
-
function _intersection(
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
return arrays.reduce((a, b) => a.filter(v => b.includes(v)));
|
|
240
|
+
function _intersection(a1, a2) {
|
|
241
|
+
const a2set = a2 instanceof Set ? a2 : new Set(a2);
|
|
242
|
+
return a1.filter(v => a2set.has(v));
|
|
238
243
|
}
|
|
239
244
|
exports._intersection = _intersection;
|
|
245
|
+
/**
|
|
246
|
+
* Returns true if there is at least 1 item common between 2 arrays.
|
|
247
|
+
* Otherwise returns false.
|
|
248
|
+
*
|
|
249
|
+
* It's more performant to use that versus `_intersection(a1, a2).length > 0`.
|
|
250
|
+
*
|
|
251
|
+
* Passing second array as Set is more performant (it'll skip turning the array into Set in-place).
|
|
252
|
+
*/
|
|
253
|
+
function _intersectsWith(a1, a2) {
|
|
254
|
+
const a2set = a2 instanceof Set ? a2 : new Set(a2);
|
|
255
|
+
return a1.some(v => a2set.has(v));
|
|
256
|
+
}
|
|
257
|
+
exports._intersectsWith = _intersectsWith;
|
|
240
258
|
/**
|
|
241
259
|
* @example
|
|
242
260
|
* _difference([2, 1], [2, 3])
|
package/dist/index.d.ts
CHANGED
|
@@ -83,6 +83,7 @@ export * from './semver';
|
|
|
83
83
|
export * from './web';
|
|
84
84
|
export * from './abort';
|
|
85
85
|
export * from './polyfill';
|
|
86
|
+
export * from './string/regex';
|
|
86
87
|
export * from './zod/zod.util';
|
|
87
88
|
export * from './zod/zod.shared.schemas';
|
|
88
89
|
import { z, ZodSchema, ZodError, ZodIssue } from 'zod';
|
package/dist/index.js
CHANGED
|
@@ -87,6 +87,7 @@ tslib_1.__exportStar(require("./semver"), exports);
|
|
|
87
87
|
tslib_1.__exportStar(require("./web"), exports);
|
|
88
88
|
tslib_1.__exportStar(require("./abort"), exports);
|
|
89
89
|
tslib_1.__exportStar(require("./polyfill"), exports);
|
|
90
|
+
tslib_1.__exportStar(require("./string/regex"), exports);
|
|
90
91
|
tslib_1.__exportStar(require("./zod/zod.util"), exports);
|
|
91
92
|
tslib_1.__exportStar(require("./zod/zod.shared.schemas"), exports);
|
|
92
93
|
const zod_1 = require("zod");
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.SIMPLE_EMAIL_REGEX = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* Simple, intentionally not exhaustive regex to match an email address.
|
|
6
|
+
*
|
|
7
|
+
* Source: https://regexr.com/3e48o
|
|
8
|
+
*/
|
|
9
|
+
exports.SIMPLE_EMAIL_REGEX = /^[\w-.]+@([\w-]+\.)+[\w-]{2,4}$/;
|
|
@@ -207,14 +207,31 @@ export function _countBy(items, mapper) {
|
|
|
207
207
|
}
|
|
208
208
|
// investigate: _groupBy
|
|
209
209
|
/**
|
|
210
|
+
* Returns an intersection between 2 arrays.
|
|
211
|
+
*
|
|
212
|
+
* Intersecion means an array of items that are present in both of the arrays.
|
|
213
|
+
*
|
|
214
|
+
* It's more performant to pass a Set as a second argument.
|
|
215
|
+
*
|
|
210
216
|
* @example
|
|
211
217
|
* _intersection([2, 1], [2, 3])
|
|
212
218
|
* // [2]
|
|
213
219
|
*/
|
|
214
|
-
export function _intersection(
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
220
|
+
export function _intersection(a1, a2) {
|
|
221
|
+
const a2set = a2 instanceof Set ? a2 : new Set(a2);
|
|
222
|
+
return a1.filter(v => a2set.has(v));
|
|
223
|
+
}
|
|
224
|
+
/**
|
|
225
|
+
* Returns true if there is at least 1 item common between 2 arrays.
|
|
226
|
+
* Otherwise returns false.
|
|
227
|
+
*
|
|
228
|
+
* It's more performant to use that versus `_intersection(a1, a2).length > 0`.
|
|
229
|
+
*
|
|
230
|
+
* Passing second array as Set is more performant (it'll skip turning the array into Set in-place).
|
|
231
|
+
*/
|
|
232
|
+
export function _intersectsWith(a1, a2) {
|
|
233
|
+
const a2set = a2 instanceof Set ? a2 : new Set(a2);
|
|
234
|
+
return a1.some(v => a2set.has(v));
|
|
218
235
|
}
|
|
219
236
|
/**
|
|
220
237
|
* @example
|
package/dist-esm/index.js
CHANGED
|
@@ -83,6 +83,7 @@ export * from './semver';
|
|
|
83
83
|
export * from './web';
|
|
84
84
|
export * from './abort';
|
|
85
85
|
export * from './polyfill';
|
|
86
|
+
export * from './string/regex';
|
|
86
87
|
export * from './zod/zod.util';
|
|
87
88
|
export * from './zod/zod.shared.schemas';
|
|
88
89
|
import { z, ZodSchema, ZodError } from 'zod';
|
package/package.json
CHANGED
package/src/array/array.util.ts
CHANGED
|
@@ -253,13 +253,32 @@ export function _countBy<T>(items: T[], mapper: Mapper<T, any>): StringMap<numbe
|
|
|
253
253
|
// investigate: _groupBy
|
|
254
254
|
|
|
255
255
|
/**
|
|
256
|
+
* Returns an intersection between 2 arrays.
|
|
257
|
+
*
|
|
258
|
+
* Intersecion means an array of items that are present in both of the arrays.
|
|
259
|
+
*
|
|
260
|
+
* It's more performant to pass a Set as a second argument.
|
|
261
|
+
*
|
|
256
262
|
* @example
|
|
257
263
|
* _intersection([2, 1], [2, 3])
|
|
258
264
|
* // [2]
|
|
259
265
|
*/
|
|
260
|
-
export function _intersection<T>(
|
|
261
|
-
|
|
262
|
-
return
|
|
266
|
+
export function _intersection<T>(a1: T[], a2: T[] | Set<T>): T[] {
|
|
267
|
+
const a2set = a2 instanceof Set ? a2 : new Set(a2)
|
|
268
|
+
return a1.filter(v => a2set.has(v))
|
|
269
|
+
}
|
|
270
|
+
|
|
271
|
+
/**
|
|
272
|
+
* Returns true if there is at least 1 item common between 2 arrays.
|
|
273
|
+
* Otherwise returns false.
|
|
274
|
+
*
|
|
275
|
+
* It's more performant to use that versus `_intersection(a1, a2).length > 0`.
|
|
276
|
+
*
|
|
277
|
+
* Passing second array as Set is more performant (it'll skip turning the array into Set in-place).
|
|
278
|
+
*/
|
|
279
|
+
export function _intersectsWith<T>(a1: T[], a2: T[] | Set<T>): boolean {
|
|
280
|
+
const a2set = a2 instanceof Set ? a2 : new Set(a2)
|
|
281
|
+
return a1.some(v => a2set.has(v))
|
|
263
282
|
}
|
|
264
283
|
|
|
265
284
|
/**
|
package/src/index.ts
CHANGED
|
@@ -83,6 +83,7 @@ export * from './semver'
|
|
|
83
83
|
export * from './web'
|
|
84
84
|
export * from './abort'
|
|
85
85
|
export * from './polyfill'
|
|
86
|
+
export * from './string/regex'
|
|
86
87
|
export * from './zod/zod.util'
|
|
87
88
|
export * from './zod/zod.shared.schemas'
|
|
88
89
|
import { z, ZodSchema, ZodError, ZodIssue } from 'zod'
|