@aliexme/js-utils 0.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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2022 Alexander Smirnov
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,9 @@
1
+ # @aliexme/js-utils
2
+
3
+ Common JavaScript utilities
4
+
5
+ ## Installation
6
+
7
+ ```
8
+ npm install @aliexme/js-utils
9
+ ```
@@ -0,0 +1 @@
1
+ export declare const arraysIntersection: <T>(array1: T[], array2: T[], ...arrays: T[][]) => T[];
@@ -0,0 +1,18 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.arraysIntersection = void 0;
4
+ var arraysIntersection = function (array1, array2) {
5
+ var arrays = [];
6
+ for (var _i = 2; _i < arguments.length; _i++) {
7
+ arrays[_i - 2] = arguments[_i];
8
+ }
9
+ if (array1.length === 0 || array2.length === 0 || arrays.some(function (array) { return array.length === 0; }))
10
+ return [];
11
+ var intersection = array1.filter(function (item) { return array2.includes(item); });
12
+ arrays.forEach(function (arrayN) {
13
+ intersection = intersection.filter(function (item) { return arrayN.includes(item); });
14
+ });
15
+ return intersection;
16
+ };
17
+ exports.arraysIntersection = arraysIntersection;
18
+ //# sourceMappingURL=arraysIntersection.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"arraysIntersection.js","sourceRoot":"","sources":["../src/array/arraysIntersection.ts"],"names":[],"mappings":";;;AAAO,IAAM,kBAAkB,GAAG,UAAI,MAAW,EAAE,MAAW;IAAE,gBAAgB;SAAhB,UAAgB,EAAhB,qBAAgB,EAAhB,IAAgB;QAAhB,+BAAgB;;IAC9E,IAAI,MAAM,CAAC,MAAM,KAAK,CAAC,IAAI,MAAM,CAAC,MAAM,KAAK,CAAC,IAAI,MAAM,CAAC,IAAI,CAAC,UAAC,KAAK,IAAK,OAAA,KAAK,CAAC,MAAM,KAAK,CAAC,EAAlB,CAAkB,CAAC;QAAE,OAAO,EAAE,CAAA;IAEvG,IAAI,YAAY,GAAQ,MAAM,CAAC,MAAM,CAAC,UAAC,IAAI,IAAK,OAAA,MAAM,CAAC,QAAQ,CAAC,IAAI,CAAC,EAArB,CAAqB,CAAC,CAAA;IAEtE,MAAM,CAAC,OAAO,CAAC,UAAC,MAAM;QACpB,YAAY,GAAG,YAAY,CAAC,MAAM,CAAC,UAAC,IAAI,IAAK,OAAA,MAAM,CAAC,QAAQ,CAAC,IAAI,CAAC,EAArB,CAAqB,CAAC,CAAA;IACrE,CAAC,CAAC,CAAA;IAEF,OAAO,YAAY,CAAA;AACrB,CAAC,CAAA;AAVY,QAAA,kBAAkB,sBAU9B"}
@@ -0,0 +1,2 @@
1
+ export * from './subtractArrays';
2
+ export * from './arraysIntersection';
package/array/index.js ADDED
@@ -0,0 +1,19 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./subtractArrays"), exports);
18
+ __exportStar(require("./arraysIntersection"), exports);
19
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/array/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,mDAAgC;AAChC,uDAAoC"}
@@ -0,0 +1 @@
1
+ export declare const subtractArrays: <T>(array1: T[], array2: T[]) => T[];
@@ -0,0 +1,10 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.subtractArrays = void 0;
4
+ var subtractArrays = function (array1, array2) {
5
+ if (array1.length === 0 || array2.length === 0)
6
+ return array1;
7
+ return array1.filter(function (item) { return !array2.includes(item); });
8
+ };
9
+ exports.subtractArrays = subtractArrays;
10
+ //# sourceMappingURL=subtractArrays.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"subtractArrays.js","sourceRoot":"","sources":["../src/array/subtractArrays.ts"],"names":[],"mappings":";;;AAAO,IAAM,cAAc,GAAG,UAAI,MAAW,EAAE,MAAW;IACxD,IAAI,MAAM,CAAC,MAAM,KAAK,CAAC,IAAI,MAAM,CAAC,MAAM,KAAK,CAAC;QAAE,OAAO,MAAM,CAAA;IAC7D,OAAO,MAAM,CAAC,MAAM,CAAC,UAAC,IAAI,IAAK,OAAA,CAAC,MAAM,CAAC,QAAQ,CAAC,IAAI,CAAC,EAAtB,CAAsB,CAAC,CAAA;AACxD,CAAC,CAAA;AAHY,QAAA,cAAc,kBAG1B"}
@@ -0,0 +1,14 @@
1
+ export declare const arraysIntersection: <T>(array1: T[], array2: T[], ...arrays: T[][]) => T[];
2
+
3
+ export declare const noop: () => void;
4
+
5
+ export declare const objectForEach: <T extends Record<string, any>>(obj: T, callbackFn: (entry: {
6
+ key: keyof T;
7
+ value: T[keyof T];
8
+ }) => void) => void;
9
+
10
+ export declare const omitUndefinedObjectValues: <T extends Record<string, any>>(obj: T) => T;
11
+
12
+ export declare const subtractArrays: <T>(array1: T[], array2: T[]) => T[];
13
+
14
+ export { }
@@ -0,0 +1 @@
1
+ (function(t,c){typeof exports=="object"&&typeof module<"u"?c(exports):typeof define=="function"&&define.amd?define(["exports"],c):(t=typeof globalThis<"u"?globalThis:t||self,c(t["@aliexme/js-common-utils"]={}))})(this,function(t){"use strict";const c=(e,n)=>e.length===0||n.length===0?e:e.filter(i=>!n.includes(i)),f=(e,n,...i)=>{if(e.length===0||n.length===0||i.some(s=>s.length===0))return[];let o=e.filter(s=>n.includes(s));return i.forEach(s=>{o=o.filter(r=>s.includes(r))}),o},u=(e,n)=>{Object.keys(e).forEach(i=>{const o=e[i];n({key:i,value:o})})},l=e=>{const n={};return u(e,({key:i,value:o})=>{o!==void 0&&(n[i]=o)}),n},d=()=>{};t.arraysIntersection=f,t.noop=d,t.objectForEach=u,t.omitUndefinedObjectValues=l,t.subtractArrays=c,Object.defineProperty(t,Symbol.toStringTag,{value:"Module"})});
@@ -0,0 +1 @@
1
+ export * from './noop';
@@ -0,0 +1,18 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./noop"), exports);
18
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/function/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,yCAAsB"}
@@ -0,0 +1 @@
1
+ export declare const noop: () => void;
@@ -0,0 +1,6 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.noop = void 0;
4
+ var noop = function () { };
5
+ exports.noop = noop;
6
+ //# sourceMappingURL=noop.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"noop.js","sourceRoot":"","sources":["../src/function/noop.ts"],"names":[],"mappings":";;;AAAO,IAAM,IAAI,GAAG,cAAiB,CAAC,CAAA;AAAzB,QAAA,IAAI,QAAqB"}
package/index.d.ts ADDED
@@ -0,0 +1,3 @@
1
+ export * from './array';
2
+ export * from './object';
3
+ export * from './function';
package/index.js ADDED
@@ -0,0 +1,20 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./array"), exports);
18
+ __exportStar(require("./object"), exports);
19
+ __exportStar(require("./function"), exports);
20
+ //# sourceMappingURL=index.js.map
package/index.js.map ADDED
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,0CAAuB;AACvB,2CAAwB;AACxB,6CAA0B"}
@@ -0,0 +1,2 @@
1
+ export * from './objectForEach';
2
+ export * from './omitUndefinedObjectValues';
@@ -0,0 +1,19 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./objectForEach"), exports);
18
+ __exportStar(require("./omitUndefinedObjectValues"), exports);
19
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/object/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,kDAA+B;AAC/B,8DAA2C"}
@@ -0,0 +1,4 @@
1
+ export declare const objectForEach: <T extends Record<string, any>>(obj: T, callbackFn: (entry: {
2
+ key: keyof T;
3
+ value: T[keyof T];
4
+ }) => void) => void;
@@ -0,0 +1,11 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.objectForEach = void 0;
4
+ var objectForEach = function (obj, callbackFn) {
5
+ Object.keys(obj).forEach(function (key) {
6
+ var value = obj[key];
7
+ callbackFn({ key: key, value: value });
8
+ });
9
+ };
10
+ exports.objectForEach = objectForEach;
11
+ //# sourceMappingURL=objectForEach.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"objectForEach.js","sourceRoot":"","sources":["../src/object/objectForEach.ts"],"names":[],"mappings":";;;AAAO,IAAM,aAAa,GAAG,UAC3B,GAAM,EACN,UAAgE;IAEhE,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,OAAO,CAAC,UAAC,GAAG;QAC3B,IAAM,KAAK,GAAG,GAAG,CAAC,GAAG,CAAC,CAAA;QACtB,UAAU,CAAC,EAAE,GAAG,KAAA,EAAE,KAAK,OAAA,EAAE,CAAC,CAAA;IAC5B,CAAC,CAAC,CAAA;AACJ,CAAC,CAAA;AARY,QAAA,aAAa,iBAQzB"}
@@ -0,0 +1 @@
1
+ export declare const omitUndefinedObjectValues: <T extends Record<string, any>>(obj: T) => T;
@@ -0,0 +1,16 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.omitUndefinedObjectValues = void 0;
4
+ var objectForEach_1 = require("./objectForEach");
5
+ var omitUndefinedObjectValues = function (obj) {
6
+ var result = {};
7
+ (0, objectForEach_1.objectForEach)(obj, function (_a) {
8
+ var key = _a.key, value = _a.value;
9
+ if (value !== undefined) {
10
+ result[key] = value;
11
+ }
12
+ });
13
+ return result;
14
+ };
15
+ exports.omitUndefinedObjectValues = omitUndefinedObjectValues;
16
+ //# sourceMappingURL=omitUndefinedObjectValues.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"omitUndefinedObjectValues.js","sourceRoot":"","sources":["../src/object/omitUndefinedObjectValues.ts"],"names":[],"mappings":";;;AAAA,iDAA+C;AAExC,IAAM,yBAAyB,GAAG,UAAgC,GAAM;IAC7E,IAAM,MAAM,GAAG,EAAO,CAAA;IAEtB,IAAA,6BAAa,EAAC,GAAG,EAAE,UAAC,EAAc;YAAZ,GAAG,SAAA,EAAE,KAAK,WAAA;QAC9B,IAAI,KAAK,KAAK,SAAS,EAAE;YACvB,MAAM,CAAC,GAAG,CAAC,GAAG,KAAK,CAAA;SACpB;IACH,CAAC,CAAC,CAAA;IAEF,OAAO,MAAM,CAAA;AACf,CAAC,CAAA;AAVY,QAAA,yBAAyB,6BAUrC"}
package/package.json ADDED
@@ -0,0 +1,38 @@
1
+ {
2
+ "name": "@aliexme/js-utils",
3
+ "version": "0.3.0",
4
+ "description": "Common JavaScript utilities",
5
+ "private": false,
6
+ "author": "Alexander Smirnov <al.smirnov996@gmail.com>",
7
+ "homepage": "https://github.com/aliexme/js-utils",
8
+ "repository": {
9
+ "type": "git",
10
+ "url": "https://github.com/aliexme/js-utils"
11
+ },
12
+ "license": "MIT",
13
+ "main": "index.js",
14
+ "typings": "index.d.ts",
15
+ "publishConfig": {
16
+ "access": "public"
17
+ },
18
+ "scripts": {
19
+ "prepare": "yarn ts:compile",
20
+ "ts:check": "tsc --noEmit",
21
+ "ts:compile": "tsc -p ./tsconfig.lib.json",
22
+ "lint:check": "eslint --ext .js,.ts --ignore-path .gitignore --cache ./",
23
+ "lint:fix": "yarn lint:check --fix",
24
+ "test": "jest",
25
+ "test:coverage": "jest --collectCoverage"
26
+ },
27
+ "dependencies": {},
28
+ "devDependencies": {
29
+ "@types/jest": "^27.5.0",
30
+ "@typescript-eslint/eslint-plugin": "^5.22.0",
31
+ "@typescript-eslint/parser": "^5.22.0",
32
+ "eslint": "^8.14.0",
33
+ "eslint-plugin-import": "^2.26.0",
34
+ "jest": "^28.0.3",
35
+ "ts-jest": "^28.0.1",
36
+ "typescript": "^4.6.4"
37
+ }
38
+ }