@mapomodule/utils 1.0.0-alpha.40 → 1.0.0-alpha.44
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/datetime.js +68 -0
- package/helpers/objHelpers.js +4 -2
- package/package.json +2 -3
- package/LICENSE.md +0 -20
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.44](https://github.com/lotrekagency/mapo/compare/v1.0.0-alpha.43...v1.0.0-alpha.44) (2023-06-10)
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
### Bug Fixes
|
|
10
|
+
|
|
11
|
+
* added better reactivity to setPointed function ([78a4a88](https://github.com/lotrekagency/mapo/commit/78a4a88fbc98e5ce0d2662c074541eb4f8fd3ea1))
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
### Performance Improvements
|
|
15
|
+
|
|
16
|
+
* EXPERIMENTAL: use Vue.set in setpointed and directly manipulate js object in FormField ([1c384e9](https://github.com/lotrekagency/mapo/commit/1c384e9d7c922b0e876512de874a3f9832ac30f1))
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
# [1.0.0-alpha.43](https://github.com/lotrekagency/mapo/compare/v1.0.0-alpha.42...v1.0.0-alpha.43) (2023-02-02)
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
### Bug Fixes
|
|
26
|
+
|
|
27
|
+
* put version on @mapomodule/utils ([9182283](https://github.com/lotrekagency/mapo/commit/9182283aeef7075a664ce12a45c94b934d5c491a))
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
|
|
6
33
|
# [1.0.0-alpha.40](https://github.com/lotrekagency/mapo/compare/v1.0.0-alpha.39...v1.0.0-alpha.40) (2022-12-20)
|
|
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
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
const Vue = require('vue')
|
|
2
|
+
|
|
1
3
|
function deepClone(obj) {
|
|
2
4
|
const clone = obj instanceof Array ? Object.assign([]) : Object.assign({});
|
|
3
5
|
for (const i in obj) {
|
|
@@ -18,10 +20,10 @@ function getPointed(obj, kpointed, def) {
|
|
|
18
20
|
function setPointed(obj, kpointed, val) {
|
|
19
21
|
const arr = typeof kpointed == 'string' ? kpointed.split(".") : kpointed
|
|
20
22
|
if (arr.length == 1) {
|
|
21
|
-
obj
|
|
23
|
+
Vue.set(obj, arr[0], val)
|
|
22
24
|
return obj
|
|
23
25
|
}
|
|
24
|
-
obj
|
|
26
|
+
Vue.set(obj, arr[0], obj[arr[0]] || {})
|
|
25
27
|
return setPointed(obj[arr[0]], arr.slice(1), val)
|
|
26
28
|
}
|
|
27
29
|
|
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.44",
|
|
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>",
|
|
@@ -8,6 +8,5 @@
|
|
|
8
8
|
"main": "./index.js",
|
|
9
9
|
"publishConfig": {
|
|
10
10
|
"access": "public"
|
|
11
|
-
}
|
|
12
|
-
"gitHead": "918d8d3ed9a6edc9be25e082f9917866e8c73c57"
|
|
11
|
+
}
|
|
13
12
|
}
|
package/LICENSE.md
DELETED
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
The MIT License (MIT)
|
|
2
|
-
|
|
3
|
-
Copyright (c) Lotrek 2021
|
|
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
|
|
13
|
-
all 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
|