@mapomodule/utils 1.0.0-alpha.1 → 1.0.0-alpha.10

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 ADDED
@@ -0,0 +1,38 @@
1
+ # Change Log
2
+
3
+ All notable changes to this project will be documented in this file.
4
+ See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
5
+
6
+ # [1.0.0-alpha.10](https://github.com/lotrekagency/mapo/compare/v1.0.0-alpha.9...v1.0.0-alpha.10) (2022-02-11)
7
+
8
+
9
+ ### Bug Fixes
10
+
11
+ * fix objectHelper getPointed returning a keyerror when some point in path are missing ([6f1c2aa](https://github.com/lotrekagency/mapo/commit/6f1c2aa72176c9965e499135042de0646d9a04f8))
12
+
13
+
14
+ ### Features
15
+
16
+ * **core:** Completely rewritten multipart capabilities, now the crud helper autodiscovers whet to use a multipart request. ([0a6546c](https://github.com/lotrekagency/mapo/commit/0a6546c9adeaf1fcf57a88105101e476b8b786dc))
17
+
18
+
19
+
20
+
21
+
22
+ # [1.0.0-alpha.9](https://github.com/lotrekagency/mapo/compare/v1.0.0-alpha.8...v1.0.0-alpha.9) (2022-02-08)
23
+
24
+
25
+ ### Bug Fixes
26
+
27
+ * **core:** fix object setPointed to create missing nesting ([7a26510](https://github.com/lotrekagency/mapo/commit/7a26510d6c1648156bd5a8f18d3851e4fe195d29))
28
+
29
+
30
+
31
+
32
+
33
+ # [1.0.0-alpha.8](https://github.com/lotrekagency/mapo/compare/v1.0.0-alpha.7...v1.0.0-alpha.8) (2022-01-23)
34
+
35
+
36
+ ### Features
37
+
38
+ * **quickedit:** merge detail component logics in to quickedit ([691f610](https://github.com/lotrekagency/mapo/commit/691f610b156f58a5d30598d89bf06425d90451d8))
package/LICENSE.md ADDED
@@ -0,0 +1,20 @@
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
@@ -11,7 +11,7 @@ function deepClone(obj) {
11
11
  }
12
12
 
13
13
  function getPointed(obj, kpointed, def) {
14
- const result = kpointed.split(".").reduce((o, k) => typeof (o) == 'object' ? o[k] : o, obj)
14
+ const result = kpointed.split(".").reduce((o, k) => typeof (o) == 'object' ? (o || {})[k] : o, obj)
15
15
  return result === undefined ? def : result
16
16
  }
17
17
 
@@ -21,19 +21,90 @@ function setPointed(obj, kpointed, val) {
21
21
  obj[arr[0]] = val
22
22
  return obj
23
23
  }
24
- return setPointed(obj[arr[0]] || {}, arr.slice(1), val)
24
+ obj[arr[0]] = obj[arr[0]] || {}
25
+ return setPointed(obj[arr[0]], arr.slice(1), val)
25
26
  }
26
27
 
27
28
  function filterObj(obj, kpointedArr) {
28
- return kpointedArr.reduce((acc, kpointed) => {
29
+ return (kpointedArr || []).reduce((acc, kpointed) => {
29
30
  setPointed(acc, kpointed, getPointed(obj, kpointed))
30
31
  return acc
31
32
  }, {})
32
33
  }
33
34
 
35
+ function isFileInstance(input) {
36
+ if ('File' in window && input instanceof File)
37
+ return true;
38
+ else return false;
39
+ }
40
+
41
+ function isBlobInstance(input) {
42
+ if ('Blob' in window && input instanceof Blob)
43
+ return true;
44
+ else return false;
45
+ }
46
+
47
+ function isFileOrBlob(input) {
48
+ return isFileInstance(input) || isBlobInstance(input)
49
+ }
50
+
51
+ function filesInObject(obj) {
52
+ return findPropPaths(obj, ({ val }) => isFileOrBlob(val))
53
+ }
54
+
55
+ function findPropPaths(obj, predicate) {
56
+ const discoveredObjects = [];
57
+ const path = [];
58
+ const results = [];
59
+ if (!obj && (typeof obj !== "object" || Array.isArray(obj))) {
60
+ throw new TypeError("First argument of finPropPath is not the correct type Object");
61
+ }
62
+ if (typeof predicate !== "function") {
63
+ throw new TypeError("Predicate is not a function");
64
+ }
65
+ (function find(obj) {
66
+ for (const key of Object.keys(obj)) {
67
+ if (predicate({ val: obj[key], obj, path, key }) === true) {
68
+ path.push(key);
69
+ results.push(path.join("."));
70
+ path.pop();
71
+ }
72
+ const o = obj[key];
73
+ if (o && typeof o === "object" && !Array.isArray(o)) {
74
+ if (!discoveredObjects.find(obj => obj === o)) {
75
+ path.push(key);
76
+ discoveredObjects.push(o);
77
+ find(o);
78
+ path.pop();
79
+ }
80
+ }
81
+ }
82
+ }(obj));
83
+ return results;
84
+ }
85
+
86
+ function diffObjs(obj1, obj2) {
87
+ const a = deepClone(obj1)
88
+ const b = deepClone(obj2)
89
+ for (const i in b) {
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
+ b[i] = diffObjs(a[i], b[i])
94
+ }
95
+ }
96
+ return b;
97
+ }
98
+
34
99
  module.exports = {
35
100
  deepClone,
36
101
  getPointed,
37
102
  setPointed,
38
- filterObj
103
+ filterObj,
104
+ isFileInstance,
105
+ isBlobInstance,
106
+ isFileOrBlob,
107
+ filesInObject,
108
+ findPropPaths,
109
+ diffObjs
39
110
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mapomodule/utils",
3
- "version": "1.0.0-alpha.1",
3
+ "version": "1.0.0-alpha.10",
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>",
@@ -12,5 +12,5 @@
12
12
  "publishConfig": {
13
13
  "access": "public"
14
14
  },
15
- "gitHead": "a480dac2e2e78e66e0b5b35bd2f03bc3e1575246"
15
+ "gitHead": "283cad977741523d3a0c300ce08edf1a6855e11c"
16
16
  }