@mapomodule/utils 1.0.0-alpha.34 → 1.0.0-alpha.43
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/CHANGELOG.md +27 -0
- package/helpers/cssVariables.js +12 -0
- package/helpers/datetime.js +68 -0
- package/helpers/objHelpers.js +14 -9
- package/package.json +2 -2
package/CHANGELOG.md
CHANGED
|
@@ -3,6 +3,33 @@
|
|
|
3
3
|
All notable changes to this project will be documented in this file.
|
|
4
4
|
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
|
5
5
|
|
|
6
|
+
# [1.0.0-alpha.43](https://github.com/lotrekagency/mapo/compare/v1.0.0-alpha.42...v1.0.0-alpha.43) (2023-02-02)
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
### Bug Fixes
|
|
10
|
+
|
|
11
|
+
* put version on @mapomodule/utils ([9182283](https://github.com/lotrekagency/mapo/commit/9182283aeef7075a664ce12a45c94b934d5c491a))
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
# [1.0.0-alpha.40](https://github.com/lotrekagency/mapo/compare/v1.0.0-alpha.39...v1.0.0-alpha.40) (2022-12-20)
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
### Bug Fixes
|
|
21
|
+
|
|
22
|
+
* rewritten and more precise diffObjs function ([3e79775](https://github.com/lotrekagency/mapo/commit/3e797756d0dc48142febcdb806390552ea522b30))
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
### Features
|
|
26
|
+
|
|
27
|
+
* style scrollbars ([48e4c7b](https://github.com/lotrekagency/mapo/commit/48e4c7b047a1062464d823ddeebdc60b96ea11a8))
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
|
|
6
33
|
# [1.0.0-alpha.34](https://github.com/lotrekagency/mapo/compare/v1.0.0-alpha.33...v1.0.0-alpha.34) (2022-11-11)
|
|
7
34
|
|
|
8
35
|
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
const pad = (val, len = 2) => String(val).padStart(len, "0");
|
|
2
|
+
const convertToDate = (date) =>
|
|
3
|
+
typeof date == "string" ? new Date(date) : date;
|
|
4
|
+
|
|
5
|
+
function getUTC(date) {
|
|
6
|
+
return new Date(date.toISOString().slice(0, -1));
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
function cleanDateStr(dateStr) {
|
|
10
|
+
return dateStr &&
|
|
11
|
+
!dateStr.endsWith("Z") &&
|
|
12
|
+
dateStr.slice(-6).indexOf("+") === -1 &&
|
|
13
|
+
dateStr.slice(-6).indexOf("-") === -1
|
|
14
|
+
? dateStr + "Z"
|
|
15
|
+
: dateStr;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
function formatLocalTime(date) {
|
|
19
|
+
return `${pad(date.getHours())}:${pad(date.getMinutes())}:${pad(
|
|
20
|
+
date.getSeconds()
|
|
21
|
+
)}`;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
function formatLocalDate(date) {
|
|
25
|
+
return `${date.getFullYear()}-${pad(date.getMonth() + 1)}-${pad(
|
|
26
|
+
date.getDate()
|
|
27
|
+
)}`;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
function formatLocalDateTime(date) {
|
|
31
|
+
return `${formatLocalDate(date)}T${formatLocalTime(date)}`;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
function formatUTCTime(date) {
|
|
35
|
+
return formatLocalTime(getUTC(date));
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
function formatUTCDate(date) {
|
|
39
|
+
return formatLocalDate(getUTC(date));
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
const formatOps = Object.fromEntries(
|
|
43
|
+
Object.entries({
|
|
44
|
+
getUTC,
|
|
45
|
+
formatLocalTime,
|
|
46
|
+
formatLocalDate,
|
|
47
|
+
formatLocalDateTime,
|
|
48
|
+
formatUTCTime,
|
|
49
|
+
formatUTCDate
|
|
50
|
+
}).map(([k, func]) => [k, (date) => func(convertToDate(date))])
|
|
51
|
+
);
|
|
52
|
+
|
|
53
|
+
function mergeDate(dateTime, date) {
|
|
54
|
+
let newDateTime = new Date(dateTime);
|
|
55
|
+
date = convertToDate(date);
|
|
56
|
+
newDateTime.setFullYear(date.getFullYear());
|
|
57
|
+
newDateTime.setMonth(date.getMonth());
|
|
58
|
+
newDateTime.setDate(date.getDate());
|
|
59
|
+
return newDateTime;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
function mergeTime(dateTime, time) {
|
|
63
|
+
let newDateTime = new Date(dateTime);
|
|
64
|
+
let timeDateTime = new Date(`2000-01-01T${time}`);
|
|
65
|
+
return mergeDate(timeDateTime, newDateTime);
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
module.exports = { ...formatOps, cleanDateStr, mergeDate, mergeTime };
|
package/helpers/objHelpers.js
CHANGED
|
@@ -57,7 +57,7 @@ function findPropPaths(obj, predicate) {
|
|
|
57
57
|
const path = [];
|
|
58
58
|
const results = [];
|
|
59
59
|
if (!obj && (typeof obj !== "object" || Array.isArray(obj))) {
|
|
60
|
-
throw new TypeError("First argument of
|
|
60
|
+
throw new TypeError("First argument of findPropPaths is not the correct type Object");
|
|
61
61
|
}
|
|
62
62
|
if (typeof predicate !== "function") {
|
|
63
63
|
throw new TypeError("Predicate is not a function");
|
|
@@ -83,17 +83,22 @@ function findPropPaths(obj, predicate) {
|
|
|
83
83
|
return results;
|
|
84
84
|
}
|
|
85
85
|
|
|
86
|
-
function diffObjs(obj1, obj2) {
|
|
87
|
-
const a =
|
|
88
|
-
const b =
|
|
86
|
+
function diffObjs(obj1, obj2, clone=deepClone) {
|
|
87
|
+
const a = obj1 && clone(obj1) || obj2 && obj2.__proto__.constructor();
|
|
88
|
+
const b = obj2 && clone(obj2) || obj1 && obj1.__proto__.constructor();
|
|
89
89
|
for (const i in b) {
|
|
90
90
|
if (JSON.stringify(a[i]) === JSON.stringify(b[i])) {
|
|
91
|
-
delete b[i]
|
|
92
|
-
} else if (!Array.isArray(b[i]) && typeof b[i] == 'object') {
|
|
93
|
-
|
|
94
|
-
|
|
91
|
+
delete b[i];
|
|
92
|
+
} else if (b[i] && !Array.isArray(b[i]) && typeof b[i] == 'object') {
|
|
93
|
+
const diff = diffObjs(a[i], b[i], (v) => v);
|
|
94
|
+
if (diff !== undefined){
|
|
95
|
+
b[i] = diff;
|
|
96
|
+
} else {
|
|
97
|
+
delete b[i];
|
|
98
|
+
};
|
|
99
|
+
};
|
|
95
100
|
}
|
|
96
|
-
return b;
|
|
101
|
+
return b && Object.keys(b).length ? b : undefined;
|
|
97
102
|
}
|
|
98
103
|
|
|
99
104
|
module.exports = {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mapomodule/utils",
|
|
3
|
-
"version": "1.0.0-alpha.
|
|
3
|
+
"version": "1.0.0-alpha.43",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"description": "This is part of Mapo nuxt module. Provides a set of utils for the project.",
|
|
6
6
|
"author": "bnznamco <gabriele.baldi.01@gmail.com>",
|
|
@@ -9,5 +9,5 @@
|
|
|
9
9
|
"publishConfig": {
|
|
10
10
|
"access": "public"
|
|
11
11
|
},
|
|
12
|
-
"gitHead": "
|
|
12
|
+
"gitHead": "ffa0eeb2768f663bd8906832c614c51c76987027"
|
|
13
13
|
}
|