@vroskus/library-helpers 1.0.20 → 1.0.23
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/browser.js +21 -5
- package/dist/common.d.ts +1 -0
- package/dist/common.js +9 -4
- package/dist/node.js +1 -1
- package/package.json +9 -9
package/dist/browser.js
CHANGED
|
@@ -23,15 +23,29 @@ const query_string_1 = __importDefault(require("query-string"));
|
|
|
23
23
|
const react_animations_1 = require("react-animations");
|
|
24
24
|
const aphrodite_1 = require("aphrodite");
|
|
25
25
|
__exportStar(require("./common"), exports);
|
|
26
|
+
const zeroValue = 0;
|
|
26
27
|
const isEmptyString = (value) => {
|
|
27
|
-
if (typeof value === 'string' && value.trim().length ===
|
|
28
|
+
if (typeof value === 'string' && value.trim().length === zeroValue) {
|
|
28
29
|
return true;
|
|
29
30
|
}
|
|
30
31
|
return false;
|
|
31
32
|
};
|
|
33
|
+
const isObject = (input) => input !== null
|
|
34
|
+
&& typeof input === 'object'
|
|
35
|
+
&& (input === null || input === void 0 ? void 0 : input.constructor) === Object;
|
|
32
36
|
const cleanFormValues = (data) => {
|
|
33
37
|
const withoutHiddenItemsData = lodash_1.default.omitBy(data, (value, key) => lodash_1.default.startsWith(key, '_'));
|
|
34
|
-
return lodash_1.default.mapValues(withoutHiddenItemsData, (value) =>
|
|
38
|
+
return lodash_1.default.mapValues(withoutHiddenItemsData, (value) => {
|
|
39
|
+
if (Array.isArray(value) === true) {
|
|
40
|
+
return value.map((valueValue) => {
|
|
41
|
+
if (isObject(valueValue) === true) {
|
|
42
|
+
return (0, exports.cleanFormValues)(valueValue);
|
|
43
|
+
}
|
|
44
|
+
return isEmptyString(valueValue) === true ? null : valueValue;
|
|
45
|
+
});
|
|
46
|
+
}
|
|
47
|
+
return isEmptyString(value) === true ? null : value;
|
|
48
|
+
});
|
|
35
49
|
};
|
|
36
50
|
exports.cleanFormValues = cleanFormValues;
|
|
37
51
|
const animationClass = (name) => {
|
|
@@ -64,11 +78,12 @@ const getUrlGetParams = (input) => {
|
|
|
64
78
|
};
|
|
65
79
|
exports.getUrlGetParams = getUrlGetParams;
|
|
66
80
|
const getScrollTopValue = (elementId, offset) => {
|
|
67
|
-
|
|
81
|
+
const defaultOffset = 15;
|
|
82
|
+
let value = zeroValue;
|
|
68
83
|
if (document && elementId) {
|
|
69
84
|
const element = document.getElementById(elementId);
|
|
70
85
|
if (element) {
|
|
71
|
-
value = element.offsetTop - (offset ||
|
|
86
|
+
value = element.offsetTop - (offset || defaultOffset);
|
|
72
87
|
}
|
|
73
88
|
}
|
|
74
89
|
return value;
|
|
@@ -84,12 +99,13 @@ const scrollTop = (elementId, offset) => {
|
|
|
84
99
|
exports.scrollTop = scrollTop;
|
|
85
100
|
const scrollItem = (itemId, elementId, offset) => {
|
|
86
101
|
if (document) {
|
|
102
|
+
const defaultOffset = -50;
|
|
87
103
|
const item = document.getElementById(itemId);
|
|
88
104
|
const element = document.getElementById(elementId);
|
|
89
105
|
if (item && element) {
|
|
90
106
|
item.scroll({
|
|
91
107
|
behavior: 'smooth',
|
|
92
|
-
top: element.offsetTop + (offset ||
|
|
108
|
+
top: element.offsetTop + (offset || defaultOffset),
|
|
93
109
|
});
|
|
94
110
|
}
|
|
95
111
|
}
|
package/dist/common.d.ts
CHANGED
|
@@ -21,3 +21,4 @@ export declare const getObjectKeys: <T extends Record<string, unknown>, K extend
|
|
|
21
21
|
export declare const getObjectValues: <T extends Record<string, unknown>, K extends keyof T>(o: T) => T[K][];
|
|
22
22
|
export declare const getObjectEntries: <T extends Record<string, unknown>, K extends keyof T>(o: T) => [K, T[K]][];
|
|
23
23
|
export declare const numberValue: (input: unknown) => number;
|
|
24
|
+
export declare const nullValue: (input: unknown) => null | unknown;
|
package/dist/common.js
CHANGED
|
@@ -12,12 +12,15 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
12
12
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
13
|
};
|
|
14
14
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
-
exports.numberValue = exports.getObjectEntries = exports.getObjectValues = exports.getObjectKeys = exports.isDiff = exports.sleep = exports.makeRollingCode = exports.makeCode = exports.getFileUrl = exports.getImageUrl = exports.sortData = exports.getDuration = exports.durationMiddleware = exports.getValue = void 0;
|
|
15
|
+
exports.nullValue = exports.numberValue = exports.getObjectEntries = exports.getObjectValues = exports.getObjectKeys = exports.isDiff = exports.sleep = exports.makeRollingCode = exports.makeCode = exports.getFileUrl = exports.getImageUrl = exports.sortData = exports.getDuration = exports.durationMiddleware = exports.getValue = void 0;
|
|
16
16
|
const lodash_1 = __importDefault(require("lodash"));
|
|
17
17
|
const moment_1 = __importDefault(require("moment"));
|
|
18
18
|
const aigle_1 = __importDefault(require("aigle"));
|
|
19
19
|
const short_hash_1 = __importDefault(require("short-hash"));
|
|
20
20
|
const asyncLodash = aigle_1.default.mixin(lodash_1.default, undefined);
|
|
21
|
+
const zeroValue = 0;
|
|
22
|
+
const mn1 = 1000000000;
|
|
23
|
+
const mn2 = 1000000;
|
|
21
24
|
const getValue = (value, defaultValue) => {
|
|
22
25
|
let output = defaultValue;
|
|
23
26
|
if (value !== null && value !== '') {
|
|
@@ -33,10 +36,10 @@ const durationMiddleware = () => (req, res, next) => {
|
|
|
33
36
|
};
|
|
34
37
|
exports.durationMiddleware = durationMiddleware;
|
|
35
38
|
const getDuration = (start) => {
|
|
36
|
-
let timeInMs =
|
|
39
|
+
let timeInMs = zeroValue;
|
|
37
40
|
if (start) {
|
|
38
41
|
const end = process.hrtime(start);
|
|
39
|
-
timeInMs = (end[0] *
|
|
42
|
+
timeInMs = (end[0] * mn1 + end[1]) / mn2;
|
|
40
43
|
}
|
|
41
44
|
return timeInMs;
|
|
42
45
|
};
|
|
@@ -75,5 +78,7 @@ exports.isDiff = isDiff;
|
|
|
75
78
|
exports.getObjectKeys = Object.keys;
|
|
76
79
|
exports.getObjectValues = Object.values;
|
|
77
80
|
exports.getObjectEntries = Object.entries;
|
|
78
|
-
const numberValue = (input) => (input === '' ?
|
|
81
|
+
const numberValue = (input) => (input === '' ? zeroValue : Number(input));
|
|
79
82
|
exports.numberValue = numberValue;
|
|
83
|
+
const nullValue = (input) => (input === '' ? null : input);
|
|
84
|
+
exports.nullValue = nullValue;
|
package/dist/node.js
CHANGED
|
@@ -20,5 +20,5 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
20
20
|
exports.generateHash = void 0;
|
|
21
21
|
const crypto_1 = __importDefault(require("crypto"));
|
|
22
22
|
__exportStar(require("./common"), exports);
|
|
23
|
-
const generateHash = (value) => crypto_1.default.createHash('
|
|
23
|
+
const generateHash = (value) => crypto_1.default.createHash('sha512').update(value).digest('hex');
|
|
24
24
|
exports.generateHash = generateHash;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vroskus/library-helpers",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.23",
|
|
4
4
|
"description": "Utility helpers",
|
|
5
5
|
"author": "Vilius Roškus <info@regattas.eu>",
|
|
6
6
|
"license": "MIT",
|
|
@@ -19,22 +19,22 @@
|
|
|
19
19
|
"test:e2e": "echo 'No tests'"
|
|
20
20
|
},
|
|
21
21
|
"dependencies": {
|
|
22
|
-
"@types/express": "^
|
|
22
|
+
"@types/express": "^5.0.0",
|
|
23
23
|
"aigle": "^1.14.1",
|
|
24
24
|
"aphrodite": "^2.4.0",
|
|
25
|
-
"express": "^4.
|
|
25
|
+
"express": "^4.21.2",
|
|
26
26
|
"lodash": "^4.17.21",
|
|
27
27
|
"moment": "2.29.4",
|
|
28
|
-
"query-string": "^9.1.
|
|
28
|
+
"query-string": "^9.1.1",
|
|
29
29
|
"react-animations": "^1.0.0",
|
|
30
30
|
"short-hash": "^1.0.0"
|
|
31
31
|
},
|
|
32
32
|
"devDependencies": {
|
|
33
|
-
"@types/jest": "^29.5.
|
|
34
|
-
"@types/lodash": "^4.17.
|
|
35
|
-
"@types/node": "^22.
|
|
33
|
+
"@types/jest": "^29.5.14",
|
|
34
|
+
"@types/lodash": "^4.17.13",
|
|
35
|
+
"@types/node": "^22.10.2",
|
|
36
36
|
"@types/query-string": "^6.3.0",
|
|
37
|
-
"@vroskus/eslint-config": "^1.0.
|
|
38
|
-
"typescript": "^5.
|
|
37
|
+
"@vroskus/eslint-config": "^1.0.19",
|
|
38
|
+
"typescript": "^5.7.2"
|
|
39
39
|
}
|
|
40
40
|
}
|