@valkyriestudios/utils 12.2.0 → 12.3.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/array/dedupe.js +8 -3
- package/array/mapFn.js +1 -5
- package/array/mapKey.js +1 -5
- package/array/sort.js +1 -1
- package/function/is.d.ts +1 -1
- package/function/isAsync.d.ts +1 -1
- package/index.d.ts +5 -5
- package/package.json +1 -1
package/array/dedupe.js
CHANGED
|
@@ -1,13 +1,18 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const fnv1A_1 = require("../hash/fnv1A");
|
|
3
4
|
function dedupe(val) {
|
|
4
5
|
if (!Array.isArray(val))
|
|
5
6
|
return [];
|
|
6
7
|
const set = new Set();
|
|
8
|
+
const acc = [];
|
|
7
9
|
for (const item of val) {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
+
const hash = (0, fnv1A_1.default)(item);
|
|
11
|
+
if (set.has(hash))
|
|
12
|
+
continue;
|
|
13
|
+
set.add(hash);
|
|
14
|
+
acc.push(item);
|
|
10
15
|
}
|
|
11
|
-
return
|
|
16
|
+
return acc;
|
|
12
17
|
}
|
|
13
18
|
exports.default = dedupe;
|
package/array/mapFn.js
CHANGED
|
@@ -4,11 +4,7 @@ function mapFn(arr, fn, opts) {
|
|
|
4
4
|
if ((!Array.isArray(arr) || !arr.length) ||
|
|
5
5
|
typeof fn !== 'function')
|
|
6
6
|
return {};
|
|
7
|
-
|
|
8
|
-
if (opts && Object.prototype.toString.call(opts) === '[object Object]') {
|
|
9
|
-
if (opts.merge === true)
|
|
10
|
-
MERGE = true;
|
|
11
|
-
}
|
|
7
|
+
const MERGE = opts && Object.prototype.toString.call(opts) === '[object Object]' && opts.merge === true;
|
|
12
8
|
const map = {};
|
|
13
9
|
let hash = false;
|
|
14
10
|
for (const el of arr) {
|
package/array/mapKey.js
CHANGED
|
@@ -7,11 +7,7 @@ function mapKey(arr, key, opts) {
|
|
|
7
7
|
const key_s = key.trim();
|
|
8
8
|
if (!key_s.length)
|
|
9
9
|
return {};
|
|
10
|
-
|
|
11
|
-
if (opts && Object.prototype.toString.call(opts) === '[object Object]') {
|
|
12
|
-
if (opts.merge === true)
|
|
13
|
-
MERGE = true;
|
|
14
|
-
}
|
|
10
|
+
const MERGE = opts && Object.prototype.toString.call(opts) === '[object Object]' && opts.merge === true;
|
|
15
11
|
const map = {};
|
|
16
12
|
for (const el of arr) {
|
|
17
13
|
if (Object.prototype.toString.call(el) !== '[object Object]' ||
|
package/array/sort.js
CHANGED
|
@@ -43,7 +43,7 @@ function sort(arr, by, dir = 'asc', opts) {
|
|
|
43
43
|
NOKEY_AT_END = false;
|
|
44
44
|
if (typeof opts.filter_fn === 'function') {
|
|
45
45
|
const fn = opts.filter_fn;
|
|
46
|
-
FILTER_FN = el => (0, isNotEmpty_1.default)(el) && fn(el);
|
|
46
|
+
FILTER_FN = (el => (0, isNotEmpty_1.default)(el) && fn(el));
|
|
47
47
|
}
|
|
48
48
|
}
|
|
49
49
|
const prepared_arr = [];
|
package/function/is.d.ts
CHANGED
package/function/isAsync.d.ts
CHANGED
package/index.d.ts
CHANGED
|
@@ -18,10 +18,10 @@ declare module "date/is" {
|
|
|
18
18
|
export default function isDate(val: unknown): val is Date;
|
|
19
19
|
}
|
|
20
20
|
declare module "function/is" {
|
|
21
|
-
export default function isFunction(val: unknown): val is
|
|
21
|
+
export default function isFunction(val: unknown): val is (...args: unknown[]) => unknown;
|
|
22
22
|
}
|
|
23
23
|
declare module "function/isAsync" {
|
|
24
|
-
export default function isAsyncFunction(val: unknown): val is
|
|
24
|
+
export default function isAsyncFunction(val: unknown): val is (...args: unknown[]) => Promise<unknown>;
|
|
25
25
|
}
|
|
26
26
|
declare module "number/is" {
|
|
27
27
|
export default function isNumber(val: unknown): val is number;
|
|
@@ -160,6 +160,9 @@ declare module "is" {
|
|
|
160
160
|
}>;
|
|
161
161
|
export default Is;
|
|
162
162
|
}
|
|
163
|
+
declare module "hash/fnv1A" {
|
|
164
|
+
export default function fnv1A(data: unknown, offset?: number): number;
|
|
165
|
+
}
|
|
163
166
|
declare module "array/dedupe" {
|
|
164
167
|
export default function dedupe<T>(val: T[]): T[];
|
|
165
168
|
}
|
|
@@ -294,9 +297,6 @@ declare module "function/noopreturn" {
|
|
|
294
297
|
declare module "function/sleep" {
|
|
295
298
|
export default function sleep(ms?: number): Promise<void>;
|
|
296
299
|
}
|
|
297
|
-
declare module "hash/fnv1A" {
|
|
298
|
-
export default function fnv1A(data: unknown, offset?: number): number;
|
|
299
|
-
}
|
|
300
300
|
declare module "hash/guid" {
|
|
301
301
|
export default function guid(): string;
|
|
302
302
|
}
|
package/package.json
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{ "name": "@valkyriestudios/utils", "version": "12.
|
|
1
|
+
{ "name": "@valkyriestudios/utils", "version": "12.3.0", "description": "A collection of single-function utilities for common tasks", "author": { "name": "Peter Vermeulen", "email": "contact@valkyriestudios.be", "url": "www.valkyriestudios.be" }, "keywords": [ "utility", "library", "javascript", "js", "node", "bun" ], "license": "MIT", "repository": { "type": "git", "url": "git+https://github.com/ValkyrieStudios/utils.git" }, "bugs": { "url": "https://github.com/ValkyrieStudios/utils/issues" }, "homepage": "https://github.com/ValkyrieStudios/utils#readme", "types": "index.d.ts" }
|