@valkyriestudios/utils 12.35.0 → 12.36.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/LICENSE.md +6 -6
- package/README.md +9 -9
- package/array/index.d.ts +14 -14
- package/array/index.js +18 -20
- package/array/sort.js +76 -46
- package/boolean/index.d.ts +1 -2
- package/boolean/index.js +2 -3
- package/caching/index.d.ts +3 -3
- package/caching/index.js +6 -5
- package/date/index.d.ts +15 -15
- package/date/index.js +19 -19
- package/deep/index.d.ts +8 -5
- package/deep/index.js +12 -8
- package/formdata/index.d.ts +2 -3
- package/formdata/index.js +4 -5
- package/function/index.d.ts +9 -8
- package/function/index.js +14 -14
- package/hash/index.d.ts +2 -3
- package/hash/index.js +2 -2
- package/index.d.ts +136 -112
- package/modules/index.d.ts +2 -0
- package/modules/index.js +7 -0
- package/number/index.d.ts +37 -18
- package/number/index.js +58 -38
- package/object/index.d.ts +7 -7
- package/object/index.js +11 -13
- package/object/omit.js +14 -16
- package/object/pick.js +7 -12
- package/package.json +18 -6
- package/regexp/index.d.ts +3 -3
- package/regexp/index.js +5 -5
- package/string/index.d.ts +7 -7
- package/string/index.js +10 -13
package/object/omit.js
CHANGED
|
@@ -6,30 +6,28 @@ function innerOmit(obj, keys) {
|
|
|
6
6
|
const result = { ...obj };
|
|
7
7
|
const groups = {};
|
|
8
8
|
for (let i = 0; i < keys.length; i++) {
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
delete result[root];
|
|
9
|
+
if (typeof keys[i] === 'string') {
|
|
10
|
+
const [root, ...rest] = keys[i].split('.');
|
|
11
|
+
if (rest.length) {
|
|
12
|
+
if (!groups[root])
|
|
13
|
+
groups[root] = [];
|
|
14
|
+
groups[root].push(rest.join('.'));
|
|
15
|
+
}
|
|
16
|
+
else {
|
|
17
|
+
delete result[root];
|
|
18
|
+
}
|
|
20
19
|
}
|
|
21
20
|
}
|
|
22
21
|
for (const root in groups) {
|
|
23
|
-
if (typeof result[root]
|
|
24
|
-
|
|
25
|
-
|
|
22
|
+
if (typeof result[root] === 'object' &&
|
|
23
|
+
result[root] !== null)
|
|
24
|
+
result[root] = innerOmit(result[root], groups[root]);
|
|
26
25
|
}
|
|
27
26
|
return result;
|
|
28
27
|
}
|
|
29
28
|
function omit(obj, keys) {
|
|
30
29
|
if (Object.prototype.toString.call(obj) !== '[object Object]' ||
|
|
31
|
-
!Array.isArray(keys)
|
|
32
|
-
!keys.length)
|
|
30
|
+
!Array.isArray(keys))
|
|
33
31
|
throw new TypeError('Please pass an object to omit from and a keys array');
|
|
34
32
|
return innerOmit(obj, keys);
|
|
35
33
|
}
|
package/object/pick.js
CHANGED
|
@@ -5,24 +5,19 @@ exports.default = pick;
|
|
|
5
5
|
const get_1 = require("../deep/get");
|
|
6
6
|
function pick(obj, keys) {
|
|
7
7
|
if (Object.prototype.toString.call(obj) !== '[object Object]' ||
|
|
8
|
-
!Array.isArray(keys)
|
|
9
|
-
!keys.length)
|
|
8
|
+
!Array.isArray(keys))
|
|
10
9
|
throw new TypeError('Please pass an object to pick from and a keys array');
|
|
11
10
|
const map = {};
|
|
12
11
|
let val;
|
|
13
|
-
let sanitized;
|
|
14
12
|
for (let i = 0; i < keys.length; i++) {
|
|
15
13
|
const key = keys[i];
|
|
16
|
-
if (typeof key !== 'string')
|
|
14
|
+
if (typeof key !== 'string' || !key)
|
|
17
15
|
continue;
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
continue;
|
|
21
|
-
if (sanitized.indexOf('.') >= 0) {
|
|
22
|
-
val = (0, get_1.deepGet)(obj, sanitized);
|
|
16
|
+
if (key.indexOf('.') >= 0) {
|
|
17
|
+
val = (0, get_1.deepGet)(obj, key);
|
|
23
18
|
if (val === undefined)
|
|
24
19
|
continue;
|
|
25
|
-
const parts =
|
|
20
|
+
const parts = key.split('.');
|
|
26
21
|
const parts_len = parts.length;
|
|
27
22
|
let cursor = map;
|
|
28
23
|
for (let y = 0; y < parts_len - 1; y++) {
|
|
@@ -33,8 +28,8 @@ function pick(obj, keys) {
|
|
|
33
28
|
}
|
|
34
29
|
cursor[parts[parts_len - 1].trim()] = val;
|
|
35
30
|
}
|
|
36
|
-
else if (
|
|
37
|
-
map[
|
|
31
|
+
else if (key in obj) {
|
|
32
|
+
map[key] = obj[key];
|
|
38
33
|
}
|
|
39
34
|
}
|
|
40
35
|
return map;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@valkyriestudios/utils",
|
|
3
|
-
"version": "12.
|
|
3
|
+
"version": "12.36.0",
|
|
4
4
|
"description": "A collection of single-function utilities for common tasks",
|
|
5
5
|
"author": {
|
|
6
6
|
"name": "Peter Vermeulen",
|
|
@@ -23,7 +23,7 @@
|
|
|
23
23
|
"lint": "npm run lint:src && npm run lint:test",
|
|
24
24
|
"lint:src": "./node_modules/.bin/eslint ./lib",
|
|
25
25
|
"lint:test": "./node_modules/.bin/eslint ./test",
|
|
26
|
-
"
|
|
26
|
+
"types": "tsc -p ./tsconfig.json --noEmit",
|
|
27
27
|
"benchmark": "node --require esbuild-register ./test/benchmark.ts"
|
|
28
28
|
},
|
|
29
29
|
"repository": {
|
|
@@ -710,6 +710,18 @@
|
|
|
710
710
|
"default": "./hash/guid.js",
|
|
711
711
|
"types": "./hash/guid.d.ts"
|
|
712
712
|
},
|
|
713
|
+
"./modules": {
|
|
714
|
+
"import": {
|
|
715
|
+
"default": "./modules/index.js",
|
|
716
|
+
"types": "./modules/index.d.ts"
|
|
717
|
+
},
|
|
718
|
+
"require": {
|
|
719
|
+
"default": "./modules/index.js",
|
|
720
|
+
"types": "./modules/index.d.ts"
|
|
721
|
+
},
|
|
722
|
+
"default": "./modules/index.js",
|
|
723
|
+
"types": "./modules/index.d.ts"
|
|
724
|
+
},
|
|
713
725
|
"./modules/PubSub": {
|
|
714
726
|
"import": {
|
|
715
727
|
"default": "./modules/PubSub.js",
|
|
@@ -1156,11 +1168,11 @@
|
|
|
1156
1168
|
}
|
|
1157
1169
|
},
|
|
1158
1170
|
"devDependencies": {
|
|
1159
|
-
"@types/node": "^22.
|
|
1171
|
+
"@types/node": "^22.15.16",
|
|
1160
1172
|
"esbuild-register": "^3.6.0",
|
|
1161
|
-
"eslint": "^9.
|
|
1173
|
+
"eslint": "^9.26.0",
|
|
1162
1174
|
"nyc": "^17.1.0",
|
|
1163
|
-
"typescript": "^5.8.
|
|
1164
|
-
"typescript-eslint": "^8.
|
|
1175
|
+
"typescript": "^5.8.3",
|
|
1176
|
+
"typescript-eslint": "^8.32.0"
|
|
1165
1177
|
}
|
|
1166
1178
|
}
|
package/regexp/index.d.ts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
export {
|
|
1
|
+
export { isRegExp } from './is';
|
|
2
|
+
export { sanitizeRegExp } from './sanitize';
|
|
3
|
+
export { sanitizeRegExp as sanitize } from './sanitize';
|
package/regexp/index.js
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.sanitize = exports.sanitizeRegExp = exports.
|
|
4
|
-
|
|
3
|
+
exports.sanitize = exports.sanitizeRegExp = exports.isRegExp = void 0;
|
|
4
|
+
var is_1 = require("./is");
|
|
5
5
|
Object.defineProperty(exports, "isRegExp", { enumerable: true, get: function () { return is_1.isRegExp; } });
|
|
6
|
-
|
|
7
|
-
const sanitize_1 = require("./sanitize");
|
|
6
|
+
var sanitize_1 = require("./sanitize");
|
|
8
7
|
Object.defineProperty(exports, "sanitizeRegExp", { enumerable: true, get: function () { return sanitize_1.sanitizeRegExp; } });
|
|
9
|
-
|
|
8
|
+
var sanitize_2 = require("./sanitize");
|
|
9
|
+
Object.defineProperty(exports, "sanitize", { enumerable: true, get: function () { return sanitize_2.sanitizeRegExp; } });
|
package/string/index.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
export {
|
|
1
|
+
export { humanizeBytes } from './humanizeBytes';
|
|
2
|
+
export { humanizeNumber } from './humanizeNumber';
|
|
3
|
+
export { shorten } from './shorten';
|
|
4
|
+
export { isString } from './is';
|
|
5
|
+
export { isNotEmptyString } from './isNotEmpty';
|
|
6
|
+
export { isNotEmptyString as isNeString } from './isNotEmpty';
|
|
7
|
+
export { isStringBetween } from './isBetween';
|
package/string/index.js
CHANGED
|
@@ -1,20 +1,17 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
4
|
-
|
|
3
|
+
exports.isStringBetween = exports.isNeString = exports.isNotEmptyString = exports.isString = exports.shorten = exports.humanizeNumber = exports.humanizeBytes = void 0;
|
|
4
|
+
var humanizeBytes_1 = require("./humanizeBytes");
|
|
5
5
|
Object.defineProperty(exports, "humanizeBytes", { enumerable: true, get: function () { return humanizeBytes_1.humanizeBytes; } });
|
|
6
|
-
|
|
6
|
+
var humanizeNumber_1 = require("./humanizeNumber");
|
|
7
7
|
Object.defineProperty(exports, "humanizeNumber", { enumerable: true, get: function () { return humanizeNumber_1.humanizeNumber; } });
|
|
8
|
-
|
|
8
|
+
var shorten_1 = require("./shorten");
|
|
9
|
+
Object.defineProperty(exports, "shorten", { enumerable: true, get: function () { return shorten_1.shorten; } });
|
|
10
|
+
var is_1 = require("./is");
|
|
9
11
|
Object.defineProperty(exports, "isString", { enumerable: true, get: function () { return is_1.isString; } });
|
|
10
|
-
|
|
11
|
-
const isNotEmpty_1 = require("./isNotEmpty");
|
|
12
|
+
var isNotEmpty_1 = require("./isNotEmpty");
|
|
12
13
|
Object.defineProperty(exports, "isNotEmptyString", { enumerable: true, get: function () { return isNotEmpty_1.isNotEmptyString; } });
|
|
13
|
-
|
|
14
|
-
Object.defineProperty(exports, "isNeString", { enumerable: true, get: function () { return
|
|
15
|
-
|
|
16
|
-
const isBetween_1 = require("./isBetween");
|
|
14
|
+
var isNotEmpty_2 = require("./isNotEmpty");
|
|
15
|
+
Object.defineProperty(exports, "isNeString", { enumerable: true, get: function () { return isNotEmpty_2.isNotEmptyString; } });
|
|
16
|
+
var isBetween_1 = require("./isBetween");
|
|
17
17
|
Object.defineProperty(exports, "isStringBetween", { enumerable: true, get: function () { return isBetween_1.isStringBetween; } });
|
|
18
|
-
Object.defineProperty(exports, "isBetween", { enumerable: true, get: function () { return isBetween_1.isStringBetween; } });
|
|
19
|
-
const shorten_1 = require("./shorten");
|
|
20
|
-
Object.defineProperty(exports, "shorten", { enumerable: true, get: function () { return shorten_1.shorten; } });
|