@aliexme/js-utils 1.0.0 → 1.1.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/index.d.ts +1 -0
- package/dist/array/index.js +1 -0
- package/dist/array/index.js.map +1 -1
- package/dist/array/randomArrayItem.d.ts +1 -0
- package/dist/array/randomArrayItem.js +9 -0
- package/dist/array/randomArrayItem.js.map +1 -0
- package/dist/index.d.ts +0 -1
- package/dist/index.js +0 -1
- package/dist/index.js.map +1 -1
- package/dist/number/index.d.ts +1 -0
- package/dist/number/index.js +1 -0
- package/dist/number/index.js.map +1 -1
- package/dist/number/randomInt.d.ts +1 -0
- package/dist/number/randomInt.js +8 -0
- package/dist/number/randomInt.js.map +1 -0
- package/dist/object/findObjectKey.d.ts +1 -0
- package/dist/object/findObjectKey.js +8 -0
- package/dist/object/findObjectKey.js.map +1 -0
- package/dist/object/getObjectKey.d.ts +1 -0
- package/dist/object/getObjectKey.js +9 -0
- package/dist/object/getObjectKey.js.map +1 -0
- package/dist/object/index.d.ts +2 -0
- package/dist/object/index.js +2 -0
- package/dist/object/index.js.map +1 -1
- package/dist/string/index.d.ts +1 -0
- package/dist/string/index.js +1 -0
- package/dist/string/index.js.map +1 -1
- package/dist/string/randomString.d.ts +3 -0
- package/dist/string/randomString.js +32 -0
- package/dist/string/randomString.js.map +1 -0
- package/package.json +2 -2
package/dist/array/index.d.ts
CHANGED
package/dist/array/index.js
CHANGED
|
@@ -18,4 +18,5 @@ __exportStar(require("./uniquify"), exports);
|
|
|
18
18
|
__exportStar(require("./subtractArrays"), exports);
|
|
19
19
|
__exportStar(require("./arraysIntersection"), exports);
|
|
20
20
|
__exportStar(require("./groupArrayItems"), exports);
|
|
21
|
+
__exportStar(require("./randomArrayItem"), exports);
|
|
21
22
|
//# sourceMappingURL=index.js.map
|
package/dist/array/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/array/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,6CAA0B;AAC1B,mDAAgC;AAChC,uDAAoC;AACpC,oDAAiC"}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/array/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,6CAA0B;AAC1B,mDAAgC;AAChC,uDAAoC;AACpC,oDAAiC;AACjC,oDAAiC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const randomArrayItem: <T>(array: T[]) => T;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.randomArrayItem = void 0;
|
|
4
|
+
const randomArrayItem = (array) => {
|
|
5
|
+
const randomIndex = Math.floor(Math.random() * array.length);
|
|
6
|
+
return array[randomIndex];
|
|
7
|
+
};
|
|
8
|
+
exports.randomArrayItem = randomArrayItem;
|
|
9
|
+
//# sourceMappingURL=randomArrayItem.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"randomArrayItem.js","sourceRoot":"","sources":["../../src/array/randomArrayItem.ts"],"names":[],"mappings":";;;AAAO,MAAM,eAAe,GAAG,CAAI,KAAU,EAAK,EAAE;IAClD,MAAM,WAAW,GAAG,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,MAAM,EAAE,GAAG,KAAK,CAAC,MAAM,CAAC,CAAA;IAC5D,OAAO,KAAK,CAAC,WAAW,CAAC,CAAA;AAC3B,CAAC,CAAA;AAHY,QAAA,eAAe,mBAG3B"}
|
package/dist/index.d.ts
CHANGED
package/dist/index.js
CHANGED
|
@@ -20,5 +20,4 @@ __exportStar(require("./array"), exports);
|
|
|
20
20
|
__exportStar(require("./object"), exports);
|
|
21
21
|
__exportStar(require("./function"), exports);
|
|
22
22
|
__exportStar(require("./async"), exports);
|
|
23
|
-
__exportStar(require("./random"), exports);
|
|
24
23
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,2CAAwB;AACxB,2CAAwB;AACxB,0CAAuB;AACvB,2CAAwB;AACxB,6CAA0B;AAC1B,0CAAuB
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,2CAAwB;AACxB,2CAAwB;AACxB,0CAAuB;AACvB,2CAAwB;AACxB,6CAA0B;AAC1B,0CAAuB"}
|
package/dist/number/index.d.ts
CHANGED
package/dist/number/index.js
CHANGED
|
@@ -15,4 +15,5 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
15
15
|
};
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
17
|
__exportStar(require("./round"), exports);
|
|
18
|
+
__exportStar(require("./randomInt"), exports);
|
|
18
19
|
//# sourceMappingURL=index.js.map
|
package/dist/number/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/number/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,0CAAuB"}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/number/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,0CAAuB;AACvB,8CAA2B"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const randomInt: (from?: number, to?: number) => number;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.randomInt = void 0;
|
|
4
|
+
const randomInt = (from = 0, to = 999_999) => {
|
|
5
|
+
return Math.floor(Math.random() * (to - from + 1)) + from;
|
|
6
|
+
};
|
|
7
|
+
exports.randomInt = randomInt;
|
|
8
|
+
//# sourceMappingURL=randomInt.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"randomInt.js","sourceRoot":"","sources":["../../src/number/randomInt.ts"],"names":[],"mappings":";;;AAAO,MAAM,SAAS,GAAG,CAAC,IAAI,GAAG,CAAC,EAAE,EAAE,GAAG,OAAO,EAAU,EAAE;IAC1D,OAAO,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,MAAM,EAAE,GAAG,CAAC,EAAE,GAAG,IAAI,GAAG,CAAC,CAAC,CAAC,GAAG,IAAI,CAAA;AAC3D,CAAC,CAAA;AAFY,QAAA,SAAS,aAErB"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const findObjectKey: <T extends Record<string, unknown>, K extends keyof T = keyof T>(obj: T, predicate: (value: T[K]) => boolean) => K | undefined;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.findObjectKey = void 0;
|
|
4
|
+
const findObjectKey = (obj, predicate) => {
|
|
5
|
+
return Object.entries(obj).find(([, value]) => predicate(value))?.[0];
|
|
6
|
+
};
|
|
7
|
+
exports.findObjectKey = findObjectKey;
|
|
8
|
+
//# sourceMappingURL=findObjectKey.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"findObjectKey.js","sourceRoot":"","sources":["../../src/object/findObjectKey.ts"],"names":[],"mappings":";;;AAAO,MAAM,aAAa,GAAG,CAC3B,GAAM,EACN,SAAmC,EACpB,EAAE;IACjB,OAAO,MAAM,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,KAAK,CAAC,EAAE,EAAE,CAAC,SAAS,CAAC,KAAa,CAAC,CAAC,EAAE,CAAC,CAAC,CAAM,CAAA;AACpF,CAAC,CAAA;AALY,QAAA,aAAa,iBAKzB"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const getObjectKey: <T extends Record<string, unknown>, K extends keyof T = keyof T>(obj: T, value: T[K]) => K;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getObjectKey = void 0;
|
|
4
|
+
const findObjectKey_1 = require("./findObjectKey");
|
|
5
|
+
const getObjectKey = (obj, value) => {
|
|
6
|
+
return (0, findObjectKey_1.findObjectKey)(obj, (objValue) => objValue === value);
|
|
7
|
+
};
|
|
8
|
+
exports.getObjectKey = getObjectKey;
|
|
9
|
+
//# sourceMappingURL=getObjectKey.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"getObjectKey.js","sourceRoot":"","sources":["../../src/object/getObjectKey.ts"],"names":[],"mappings":";;;AAAA,mDAA+C;AAExC,MAAM,YAAY,GAAG,CAC1B,GAAM,EACN,KAAW,EACR,EAAE;IACL,OAAO,IAAA,6BAAa,EAAC,GAAG,EAAE,CAAC,QAAQ,EAAE,EAAE,CAAC,QAAQ,KAAK,KAAK,CAAM,CAAA;AAClE,CAAC,CAAA;AALY,QAAA,YAAY,gBAKxB"}
|
package/dist/object/index.d.ts
CHANGED
package/dist/object/index.js
CHANGED
|
@@ -14,6 +14,8 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
14
14
|
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
15
|
};
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./getObjectKey"), exports);
|
|
18
|
+
__exportStar(require("./findObjectKey"), exports);
|
|
17
19
|
__exportStar(require("./objectForEach"), exports);
|
|
18
20
|
__exportStar(require("./omitObjectProperties"), exports);
|
|
19
21
|
__exportStar(require("./omitUndefinedObjectValues"), exports);
|
package/dist/object/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/object/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,kDAA+B;AAC/B,yDAAsC;AACtC,8DAA2C"}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/object/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,iDAA8B;AAC9B,kDAA+B;AAC/B,kDAA+B;AAC/B,yDAAsC;AACtC,8DAA2C"}
|
package/dist/string/index.d.ts
CHANGED
package/dist/string/index.js
CHANGED
|
@@ -16,4 +16,5 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
17
|
__exportStar(require("./capitalize"), exports);
|
|
18
18
|
__exportStar(require("./secureString"), exports);
|
|
19
|
+
__exportStar(require("./randomString"), exports);
|
|
19
20
|
//# sourceMappingURL=index.js.map
|
package/dist/string/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/string/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,+CAA4B;AAC5B,iDAA8B"}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/string/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,+CAA4B;AAC5B,iDAA8B;AAC9B,iDAA8B"}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.randomString = void 0;
|
|
4
|
+
const randomInt_1 = require("../number/randomInt");
|
|
5
|
+
const randomArrayItem_1 = require("../array/randomArrayItem");
|
|
6
|
+
// prettier-ignore
|
|
7
|
+
const lowercase = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z'];
|
|
8
|
+
// prettier-ignore
|
|
9
|
+
const uppercase = ['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z'];
|
|
10
|
+
// prettier-ignore
|
|
11
|
+
const digits = ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9'];
|
|
12
|
+
// prettier-ignore
|
|
13
|
+
const symbols = ['!', '#', '@', '~', '$', '^', '.', ',', '-', '+', '%', '?', '*', '='];
|
|
14
|
+
const charGroupsMap = {
|
|
15
|
+
1: lowercase,
|
|
16
|
+
2: uppercase,
|
|
17
|
+
3: digits,
|
|
18
|
+
4: symbols,
|
|
19
|
+
};
|
|
20
|
+
const randomString = (options = {}) => {
|
|
21
|
+
const { length = 16 } = options;
|
|
22
|
+
let result = '';
|
|
23
|
+
for (let i = 0; i < length; i++) {
|
|
24
|
+
const charGroupIndex = (0, randomInt_1.randomInt)(1, 4);
|
|
25
|
+
const charGroup = charGroupsMap[charGroupIndex];
|
|
26
|
+
const char = (0, randomArrayItem_1.randomArrayItem)(charGroup);
|
|
27
|
+
result += char;
|
|
28
|
+
}
|
|
29
|
+
return result;
|
|
30
|
+
};
|
|
31
|
+
exports.randomString = randomString;
|
|
32
|
+
//# sourceMappingURL=randomString.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"randomString.js","sourceRoot":"","sources":["../../src/string/randomString.ts"],"names":[],"mappings":";;;AAAA,mDAA+C;AAC/C,8DAA0D;AAE1D,kBAAkB;AAClB,MAAM,SAAS,GAAG,CAAC,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,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AC,EAAE,EAAE,CAAC;QAChC,MAAM,cAAc,GAAG,IAAA,qBAAS,EAAC,CAAC,EAAE,CAAC,CAAC,CAAA;QACtC,MAAM,SAAS,GAAG,aAAa,CAAC,cAA4C,CAAC,CAAA;QAC7E,MAAM,IAAI,GAAG,IAAA,iCAAe,EAAC,SAAS,CAAC,CAAA;QAEvC,MAAM,IAAI,IAAI,CAAA;IAChB,CAAC;IAED,OAAO,MAAM,CAAA;AACf,CAAC,CAAA;AAjBY,QAAA,YAAY,gBAiBxB"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@aliexme/js-utils",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.1.0",
|
|
4
4
|
"description": "Common JavaScript utilities",
|
|
5
5
|
"private": false,
|
|
6
6
|
"author": "Alexander Smirnov <al.smirnov996@gmail.com>",
|
|
@@ -22,5 +22,5 @@
|
|
|
22
22
|
"scripts": {
|
|
23
23
|
"build": "tsc -p ./tsconfig.build.json"
|
|
24
24
|
},
|
|
25
|
-
"gitHead": "
|
|
25
|
+
"gitHead": "193e9418b0fc9d36976de86d3c3da6e996cd5796"
|
|
26
26
|
}
|