@lowdefy/helpers 3.23.0 → 4.0.0-alpha.5
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/applyArrayIndices.js +15 -30
- package/dist/cachedPromises.js +27 -0
- package/dist/get.js +86 -121
- package/dist/index.js +27 -95
- package/dist/mergeObjects.js +11 -25
- package/dist/omit.js +7 -20
- package/dist/serializer.js +134 -162
- package/dist/set.js +80 -124
- package/dist/stableStringify.js +68 -102
- package/dist/swap.js +7 -21
- package/dist/type.js +171 -240
- package/dist/unset.js +67 -102
- package/dist/urlQuery.js +29 -44
- package/package.json +14 -13
package/dist/stableStringify.js
CHANGED
|
@@ -1,23 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.default = void 0;
|
|
7
|
-
|
|
8
|
-
var _type = _interopRequireDefault(require("./type"));
|
|
9
|
-
|
|
10
|
-
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
11
|
-
|
|
12
|
-
/* eslint-disable no-continue */
|
|
13
|
-
|
|
14
|
-
/* eslint-disable no-plusplus */
|
|
15
|
-
|
|
16
|
-
/* eslint-disable consistent-return */
|
|
17
|
-
|
|
18
|
-
/* eslint-disable no-param-reassign */
|
|
19
|
-
|
|
20
|
-
/*
|
|
1
|
+
/* eslint-disable no-continue */ /* eslint-disable no-plusplus */ /* eslint-disable consistent-return */ /* eslint-disable no-param-reassign */ /*
|
|
21
2
|
Copyright 2020-2021 Lowdefy, Inc
|
|
22
3
|
|
|
23
4
|
Licensed under the Apache License, Version 2.0 (the "License");
|
|
@@ -31,8 +12,7 @@ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { de
|
|
|
31
12
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
32
13
|
See the License for the specific language governing permissions and
|
|
33
14
|
limitations under the License.
|
|
34
|
-
*/
|
|
35
|
-
// Derived from source:
|
|
15
|
+
*/ // Derived from source:
|
|
36
16
|
// https://github.com/substack/json-stable-stringify
|
|
37
17
|
// https://github.com/substack/json-stable-stringify/LICENCE
|
|
38
18
|
// This software is released under the MIT license:
|
|
@@ -50,86 +30,72 @@ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { de
|
|
|
50
30
|
// COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
|
|
51
31
|
// IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
|
52
32
|
// CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
33
|
+
import type from './type.js';
|
|
53
34
|
function stableStringify(obj, opts) {
|
|
54
|
-
|
|
55
|
-
if (typeof opts === 'function') opts = {
|
|
56
|
-
cmp: opts
|
|
57
|
-
};
|
|
58
|
-
var space = opts.space || '';
|
|
59
|
-
if (typeof space === 'number') space = Array(space + 1).join(' ');
|
|
60
|
-
var cycles = typeof opts.cycles === 'boolean' ? opts.cycles : false;
|
|
61
|
-
|
|
62
|
-
var replacer = opts.replacer || ((key, value) => value);
|
|
63
|
-
|
|
64
|
-
var cmp = opts.cmp && (f => {
|
|
65
|
-
return node => {
|
|
66
|
-
return (a, b) => {
|
|
67
|
-
var aobj = {
|
|
68
|
-
key: a,
|
|
69
|
-
value: node[a]
|
|
70
|
-
};
|
|
71
|
-
var bobj = {
|
|
72
|
-
key: b,
|
|
73
|
-
value: node[b]
|
|
74
|
-
};
|
|
75
|
-
return f(aobj, bobj);
|
|
76
|
-
};
|
|
35
|
+
if (!opts) opts = {
|
|
77
36
|
};
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
37
|
+
if (typeof opts === 'function') opts = {
|
|
38
|
+
cmp: opts
|
|
39
|
+
};
|
|
40
|
+
let space = opts.space || '';
|
|
41
|
+
if (typeof space === 'number') space = Array(space + 1).join(' ');
|
|
42
|
+
const cycles = typeof opts.cycles === 'boolean' ? opts.cycles : false;
|
|
43
|
+
const replacer = opts.replacer || ((key, value)=>value
|
|
44
|
+
);
|
|
45
|
+
const cmp = opts.cmp && ((f)=>{
|
|
46
|
+
return (node)=>{
|
|
47
|
+
return (a, b)=>{
|
|
48
|
+
const aobj = {
|
|
49
|
+
key: a,
|
|
50
|
+
value: node[a]
|
|
51
|
+
};
|
|
52
|
+
const bobj = {
|
|
53
|
+
key: b,
|
|
54
|
+
value: node[b]
|
|
55
|
+
};
|
|
56
|
+
return f(aobj, bobj);
|
|
57
|
+
};
|
|
58
|
+
};
|
|
59
|
+
})(opts.cmp);
|
|
60
|
+
const seen = [];
|
|
61
|
+
return (function stringify(parent, key, node, level) {
|
|
62
|
+
const indent = space ? `\n${new Array(level + 1).join(space)}` : '';
|
|
63
|
+
const colonSeparator = space ? ': ' : ':';
|
|
64
|
+
if (node && node.toJSON && typeof node.toJSON === 'function') {
|
|
65
|
+
node = node.toJSON();
|
|
66
|
+
}
|
|
67
|
+
node = replacer.call(parent, key, node);
|
|
68
|
+
if (node === undefined) {
|
|
69
|
+
return;
|
|
70
|
+
}
|
|
71
|
+
if (typeof node !== 'object' || node === null) {
|
|
72
|
+
return JSON.stringify(node);
|
|
73
|
+
}
|
|
74
|
+
if (type.isArray(node)) {
|
|
75
|
+
const out = [];
|
|
76
|
+
for(let i = 0; i < node.length; i++){
|
|
77
|
+
const item = stringify(node, i, node[i], level + 1) || JSON.stringify(null);
|
|
78
|
+
out.push(indent + space + item);
|
|
79
|
+
}
|
|
80
|
+
return `[${out.join(',')}${indent}]`;
|
|
81
|
+
}
|
|
82
|
+
if (seen.indexOf(node) !== -1) {
|
|
83
|
+
if (cycles) return JSON.stringify('__cycle__');
|
|
84
|
+
throw new TypeError('Converting circular structure to JSON');
|
|
85
|
+
} else seen.push(node);
|
|
86
|
+
const keys = Object.keys(node).sort(cmp && cmp(node));
|
|
87
|
+
const out = [];
|
|
88
|
+
for(let i = 0; i < keys.length; i++){
|
|
89
|
+
const ky = keys[i];
|
|
90
|
+
const value = stringify(node, ky, node[ky], level + 1);
|
|
91
|
+
if (!value) continue;
|
|
92
|
+
const keyValue = JSON.stringify(ky) + colonSeparator + value;
|
|
93
|
+
out.push(indent + space + keyValue);
|
|
94
|
+
}
|
|
95
|
+
seen.splice(seen.indexOf(node), 1);
|
|
96
|
+
return `{${out.join(',')}${indent}}`;
|
|
97
|
+
})({
|
|
98
|
+
'': obj
|
|
99
|
+
}, '', obj, 0);
|
|
132
100
|
}
|
|
133
|
-
|
|
134
|
-
var _default = stableStringify;
|
|
135
|
-
exports.default = _default;
|
|
101
|
+
export default stableStringify;
|
package/dist/swap.js
CHANGED
|
@@ -1,14 +1,3 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.default = void 0;
|
|
7
|
-
|
|
8
|
-
var _type = _interopRequireDefault(require("./type"));
|
|
9
|
-
|
|
10
|
-
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
11
|
-
|
|
12
1
|
/*
|
|
13
2
|
Copyright 2020-2021 Lowdefy, Inc
|
|
14
3
|
|
|
@@ -23,14 +12,11 @@ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { de
|
|
|
23
12
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
24
13
|
See the License for the specific language governing permissions and
|
|
25
14
|
limitations under the License.
|
|
26
|
-
*/
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
arr.splice(from, 1, arr.splice(to, 1, arr[from])[0]);
|
|
15
|
+
*/ import type from './type.js';
|
|
16
|
+
const swap = (arr, from, to)=>{
|
|
17
|
+
if (!type.isArray(arr) || from < 0 || to < 0 || from >= arr.length || to >= arr.length) {
|
|
18
|
+
return;
|
|
19
|
+
}
|
|
20
|
+
arr.splice(from, 1, arr.splice(to, 1, arr[from])[0]);
|
|
33
21
|
};
|
|
34
|
-
|
|
35
|
-
var _default = swap;
|
|
36
|
-
exports.default = _default;
|
|
22
|
+
export default swap;
|