@lowdefy/helpers 3.23.2 → 4.0.0-alpha.6
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 +28 -95
- package/dist/mergeObjects.js +11 -25
- package/dist/omit.js +7 -20
- package/dist/serializer.js +129 -162
- package/dist/set.js +75 -123
- package/dist/stableStringify.js +67 -102
- package/dist/swap.js +7 -21
- package/dist/type.js +162 -232
- package/dist/unset.js +67 -102
- package/dist/urlQuery.js +27 -44
- package/dist/wait.js +19 -0
- package/package.json +14 -13
package/dist/serializer.js
CHANGED
|
@@ -1,173 +1,140 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
return
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
return item;
|
|
65
|
-
});
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
return newValue;
|
|
69
|
-
};
|
|
70
|
-
|
|
71
|
-
var makeReviver = customReviver => (key, value) => {
|
|
72
|
-
var newValue = value;
|
|
73
|
-
|
|
74
|
-
if (customReviver) {
|
|
75
|
-
newValue = customReviver(key, value);
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
if (_type.default.isObject(newValue) && !_type.default.isUndefined(newValue._error)) {
|
|
79
|
-
var error = new Error(newValue._error.message);
|
|
80
|
-
error.name = newValue._error.name;
|
|
81
|
-
return error;
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
if (_type.default.isObject(newValue) && !_type.default.isUndefined(newValue._date)) {
|
|
85
|
-
if (_type.default.isInt(newValue._date)) {
|
|
86
|
-
return new Date(newValue._date);
|
|
1
|
+
/* eslint-disable no-param-reassign */ /*
|
|
2
|
+
Copyright 2020-2021 Lowdefy, Inc
|
|
3
|
+
|
|
4
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
+
you may not use this file except in compliance with the License.
|
|
6
|
+
You may obtain a copy of the License at
|
|
7
|
+
|
|
8
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
|
|
10
|
+
Unless required by applicable law or agreed to in writing, software
|
|
11
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
+
See the License for the specific language governing permissions and
|
|
14
|
+
limitations under the License.
|
|
15
|
+
*/ import type from './type.js';
|
|
16
|
+
import stableStringify from './stableStringify.js';
|
|
17
|
+
const makeReplacer = (customReplacer, isoStringDates)=>(key, value)=>{
|
|
18
|
+
let dateReplacer = (date)=>({
|
|
19
|
+
_date: date.valueOf()
|
|
20
|
+
})
|
|
21
|
+
;
|
|
22
|
+
if (isoStringDates) {
|
|
23
|
+
dateReplacer = (date)=>({
|
|
24
|
+
_date: date.toISOString()
|
|
25
|
+
})
|
|
26
|
+
;
|
|
27
|
+
}
|
|
28
|
+
let newValue = value;
|
|
29
|
+
if (customReplacer) {
|
|
30
|
+
newValue = customReplacer(key, value);
|
|
31
|
+
}
|
|
32
|
+
if (type.isError(newValue)) {
|
|
33
|
+
return {
|
|
34
|
+
_error: {
|
|
35
|
+
name: newValue.name,
|
|
36
|
+
message: newValue.message,
|
|
37
|
+
value: newValue.toString()
|
|
38
|
+
}
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
if (type.isObject(newValue)) {
|
|
42
|
+
Object.keys(newValue).forEach((k)=>{
|
|
43
|
+
if (type.isDate(newValue[k])) {
|
|
44
|
+
// shallow copy original value before reassigning a value in order not to mutate original value
|
|
45
|
+
newValue = {
|
|
46
|
+
...newValue
|
|
47
|
+
};
|
|
48
|
+
newValue[k] = dateReplacer(newValue[k]);
|
|
49
|
+
}
|
|
50
|
+
});
|
|
51
|
+
return newValue;
|
|
52
|
+
}
|
|
53
|
+
if (type.isArray(newValue)) {
|
|
54
|
+
return newValue.map((item)=>{
|
|
55
|
+
if (type.isDate(item)) {
|
|
56
|
+
return dateReplacer(item);
|
|
57
|
+
}
|
|
58
|
+
return item;
|
|
59
|
+
});
|
|
60
|
+
}
|
|
61
|
+
return newValue;
|
|
87
62
|
}
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
63
|
+
;
|
|
64
|
+
const makeReviver = (customReviver)=>(key, value)=>{
|
|
65
|
+
let newValue = value;
|
|
66
|
+
if (customReviver) {
|
|
67
|
+
newValue = customReviver(key, value);
|
|
68
|
+
}
|
|
69
|
+
if (type.isObject(newValue) && !type.isUndefined(newValue._error)) {
|
|
70
|
+
const error = new Error(newValue._error.message);
|
|
71
|
+
error.name = newValue._error.name;
|
|
72
|
+
return error;
|
|
73
|
+
}
|
|
74
|
+
if (type.isObject(newValue) && !type.isUndefined(newValue._date)) {
|
|
75
|
+
if (type.isInt(newValue._date)) {
|
|
76
|
+
return new Date(newValue._date);
|
|
77
|
+
}
|
|
78
|
+
if (newValue._date === 'now') {
|
|
79
|
+
return newValue;
|
|
80
|
+
}
|
|
81
|
+
const result = new Date(newValue._date);
|
|
82
|
+
if (!type.isDate(result)) {
|
|
83
|
+
return newValue;
|
|
84
|
+
}
|
|
85
|
+
return result;
|
|
86
|
+
}
|
|
87
|
+
return newValue;
|
|
91
88
|
}
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
if (
|
|
96
|
-
|
|
89
|
+
;
|
|
90
|
+
const serialize = (json, options = {})=>{
|
|
91
|
+
if (type.isUndefined(json)) return json;
|
|
92
|
+
if (type.isDate(json)) {
|
|
93
|
+
if (options.isoStringDates) {
|
|
94
|
+
return {
|
|
95
|
+
_date: json.toISOString()
|
|
96
|
+
};
|
|
97
|
+
}
|
|
98
|
+
return {
|
|
99
|
+
_date: json.valueOf()
|
|
100
|
+
};
|
|
97
101
|
}
|
|
98
|
-
|
|
99
|
-
return result;
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
return newValue;
|
|
102
|
+
return JSON.parse(JSON.stringify(json, makeReplacer(options.replacer, options.isoStringDates)));
|
|
103
103
|
};
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
return {
|
|
112
|
-
_date: json.toISOString()
|
|
113
|
-
};
|
|
104
|
+
const serializeToString = (json, options = {})=>{
|
|
105
|
+
if (type.isUndefined(json)) return json;
|
|
106
|
+
if (type.isDate(json)) {
|
|
107
|
+
if (options.isoStringDates) {
|
|
108
|
+
return `{ "_date": "${json.toISOString()}" }`;
|
|
109
|
+
}
|
|
110
|
+
return `{ "_date": ${json.valueOf()} }`;
|
|
114
111
|
}
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
return JSON.parse(JSON.stringify(json, makeReplacer(options.replacer, options.isoStringDates)));
|
|
122
|
-
};
|
|
123
|
-
|
|
124
|
-
var serializeToString = function serializeToString(json) {
|
|
125
|
-
var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
126
|
-
if (_type.default.isUndefined(json)) return json;
|
|
127
|
-
|
|
128
|
-
if (_type.default.isDate(json)) {
|
|
129
|
-
if (options.isoStringDates) {
|
|
130
|
-
return "{ \"_date\": \"".concat(json.toISOString(), "\" }");
|
|
112
|
+
if (options.stable) {
|
|
113
|
+
return stableStringify(json, {
|
|
114
|
+
replacer: makeReplacer(options.replacer),
|
|
115
|
+
space: options.space
|
|
116
|
+
});
|
|
131
117
|
}
|
|
132
|
-
|
|
133
|
-
return "{ \"_date\": ".concat(json.valueOf(), " }");
|
|
134
|
-
}
|
|
135
|
-
|
|
136
|
-
if (options.stable) {
|
|
137
|
-
return (0, _stableStringify.default)(json, {
|
|
138
|
-
replacer: makeReplacer(options.replacer),
|
|
139
|
-
space: options.space
|
|
140
|
-
});
|
|
141
|
-
}
|
|
142
|
-
|
|
143
|
-
return JSON.stringify(json, makeReplacer(options.replacer, options.isoStringDates), options.space);
|
|
118
|
+
return JSON.stringify(json, makeReplacer(options.replacer, options.isoStringDates), options.space);
|
|
144
119
|
};
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
if (_type.default.isUndefined(json)) return json;
|
|
149
|
-
return JSON.parse(JSON.stringify(json), makeReviver(options.reviver));
|
|
120
|
+
const deserialize = (json, options = {})=>{
|
|
121
|
+
if (type.isUndefined(json)) return json;
|
|
122
|
+
return JSON.parse(JSON.stringify(json), makeReviver(options.reviver));
|
|
150
123
|
};
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
if (_type.default.isUndefined(str)) return str;
|
|
155
|
-
return JSON.parse(str, makeReviver(options.reviver));
|
|
124
|
+
const deserializeFromString = (str, options = {})=>{
|
|
125
|
+
if (type.isUndefined(str)) return str;
|
|
126
|
+
return JSON.parse(str, makeReviver(options.reviver));
|
|
156
127
|
};
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
if (_type.default.isDate(json)) return new Date(json.valueOf());
|
|
162
|
-
return JSON.parse(JSON.stringify(json, makeReplacer(options.replacer)), makeReviver(options.reviver));
|
|
128
|
+
const copy = (json, options = {})=>{
|
|
129
|
+
if (type.isUndefined(json)) return undefined;
|
|
130
|
+
if (type.isDate(json)) return new Date(json.valueOf());
|
|
131
|
+
return JSON.parse(JSON.stringify(json, makeReplacer(options.replacer)), makeReviver(options.reviver));
|
|
163
132
|
};
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
deserializeFromString
|
|
133
|
+
const serializer = {
|
|
134
|
+
copy,
|
|
135
|
+
serialize,
|
|
136
|
+
serializeToString,
|
|
137
|
+
deserialize,
|
|
138
|
+
deserializeFromString
|
|
171
139
|
};
|
|
172
|
-
|
|
173
|
-
exports.default = _default;
|
|
140
|
+
export default serializer;
|
package/dist/set.js
CHANGED
|
@@ -1,22 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.split = split;
|
|
7
|
-
exports.default = void 0;
|
|
8
|
-
|
|
9
|
-
var _type = _interopRequireDefault(require("./type"));
|
|
10
|
-
|
|
11
|
-
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
12
|
-
|
|
13
|
-
/* eslint-disable no-plusplus */
|
|
14
|
-
|
|
15
|
-
/* eslint-disable no-use-before-define */
|
|
16
|
-
|
|
17
|
-
/* eslint-disable no-param-reassign */
|
|
18
|
-
|
|
19
|
-
/*
|
|
1
|
+
/* eslint-disable no-plusplus */ /* eslint-disable no-use-before-define */ /* eslint-disable no-param-reassign */ /*
|
|
20
2
|
Copyright 2020-2021 Lowdefy, Inc
|
|
21
3
|
|
|
22
4
|
Licensed under the Apache License, Version 2.0 (the "License");
|
|
@@ -30,8 +12,7 @@ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { de
|
|
|
30
12
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
31
13
|
See the License for the specific language governing permissions and
|
|
32
14
|
limitations under the License.
|
|
33
|
-
*/
|
|
34
|
-
// Derived from source:
|
|
15
|
+
*/ // Derived from source:
|
|
35
16
|
// https://github.com/jonschlinkert/set-value/blob/master/index.js
|
|
36
17
|
// https://www.npmjs.com/package/set-value
|
|
37
18
|
// The MIT License (MIT)
|
|
@@ -51,119 +32,90 @@ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { de
|
|
|
51
32
|
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
52
33
|
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
53
34
|
// THE SOFTWARE.
|
|
35
|
+
import type from './type.js';
|
|
54
36
|
function isValidKey(key) {
|
|
55
|
-
|
|
37
|
+
return key !== '__proto__' && key !== 'constructor' && key !== 'prototype';
|
|
56
38
|
}
|
|
57
|
-
|
|
58
39
|
function isObjectOrFunction(val) {
|
|
59
|
-
|
|
40
|
+
return val !== null && (typeof val === 'object' || typeof val === 'function');
|
|
60
41
|
}
|
|
61
|
-
|
|
62
42
|
function result(target, path, value, merge) {
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
|
|
43
|
+
if (merge && isObjectOrFunction(target[path]) && isObjectOrFunction(value)) {
|
|
44
|
+
target[path] = merge({}, target[path], value);
|
|
45
|
+
} else {
|
|
46
|
+
target[path] = value;
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
// eslint-disable-next-line no-use-before-define
|
|
71
50
|
set.memo = {};
|
|
72
|
-
|
|
73
51
|
function set(target, path, value, options) {
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
var opts = options || {};
|
|
79
|
-
|
|
80
|
-
if (!_type.default.isArray(path) && !_type.default.isString(path)) {
|
|
81
|
-
return target;
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
var {
|
|
85
|
-
merge
|
|
86
|
-
} = opts;
|
|
87
|
-
|
|
88
|
-
if (merge && typeof merge !== 'function') {
|
|
89
|
-
merge = Object.assign;
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
var keys = (_type.default.isArray(path) ? path : split(path, opts)).filter(isValidKey);
|
|
93
|
-
var len = keys.length;
|
|
94
|
-
var orig = target;
|
|
95
|
-
|
|
96
|
-
if (!options && keys.length === 1) {
|
|
97
|
-
result(target, keys[0], value, merge);
|
|
98
|
-
return target;
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
for (var i = 0; i < len; i++) {
|
|
102
|
-
var prop = keys[i];
|
|
103
|
-
var propUp = keys[i + 1]; // changed to set an array value where the array was undefined be assigning value
|
|
104
|
-
|
|
105
|
-
if (!isObjectOrFunction(target[prop]) && !_type.default.isInt(parseInt(propUp, 10))) {
|
|
106
|
-
// changed
|
|
107
|
-
target[prop] = {};
|
|
108
|
-
} else if (!isObjectOrFunction(target[prop]) && _type.default.isInt(parseInt(propUp, 10))) {
|
|
109
|
-
// added
|
|
110
|
-
target[prop] = []; // added
|
|
52
|
+
if (!type.isObject(target)) {
|
|
53
|
+
return target;
|
|
111
54
|
}
|
|
112
|
-
|
|
113
|
-
if (
|
|
114
|
-
|
|
115
|
-
break;
|
|
55
|
+
const opts = options || {};
|
|
56
|
+
if (!type.isArray(path) && !type.isString(path)) {
|
|
57
|
+
return target;
|
|
116
58
|
}
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
59
|
+
let { merge } = opts;
|
|
60
|
+
if (merge && typeof merge !== 'function') {
|
|
61
|
+
merge = Object.assign;
|
|
62
|
+
}
|
|
63
|
+
const keys = (type.isArray(path) ? path : split(path, opts)).filter(isValidKey);
|
|
64
|
+
const len = keys.length;
|
|
65
|
+
const orig = target;
|
|
66
|
+
if (!options && keys.length === 1) {
|
|
67
|
+
result(target, keys[0], value, merge);
|
|
68
|
+
return target;
|
|
69
|
+
}
|
|
70
|
+
for(let i = 0; i < len; i++){
|
|
71
|
+
const prop = keys[i];
|
|
72
|
+
const propUp = keys[i + 1]; // changed to set an array value where the array was undefined be assigning value
|
|
73
|
+
if (!isObjectOrFunction(target[prop]) && !type.isInt(parseInt(propUp, 10))) {
|
|
74
|
+
// changed
|
|
75
|
+
target[prop] = {};
|
|
76
|
+
} else if (!isObjectOrFunction(target[prop]) && type.isInt(parseInt(propUp, 10))) {
|
|
77
|
+
// added
|
|
78
|
+
target[prop] = []; // added
|
|
79
|
+
}
|
|
80
|
+
if (i === len - 1) {
|
|
81
|
+
result(target, prop, value, merge);
|
|
82
|
+
break;
|
|
83
|
+
}
|
|
84
|
+
target = target[prop];
|
|
85
|
+
}
|
|
86
|
+
return orig;
|
|
122
87
|
}
|
|
123
|
-
|
|
124
88
|
function createKey(pattern, options) {
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
id += ";".concat(key, "=").concat(String(options[key]));
|
|
136
|
-
}
|
|
137
|
-
|
|
138
|
-
return id;
|
|
89
|
+
let id = pattern;
|
|
90
|
+
if (typeof options === 'undefined') {
|
|
91
|
+
return `${id}`;
|
|
92
|
+
}
|
|
93
|
+
const keys = Object.keys(options);
|
|
94
|
+
for(let i = 0; i < keys.length; i++){
|
|
95
|
+
const key = keys[i];
|
|
96
|
+
id += `;${key}=${String(options[key])}`;
|
|
97
|
+
}
|
|
98
|
+
return id;
|
|
139
99
|
}
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
} else {
|
|
151
|
-
keys = path.split(char);
|
|
152
|
-
}
|
|
153
|
-
|
|
154
|
-
for (var i = 0; i < keys.length; i++) {
|
|
155
|
-
var prop = keys[i];
|
|
156
|
-
|
|
157
|
-
while (prop && prop.slice(-1) === '\\' && keys[i + 1]) {
|
|
158
|
-
prop = prop.slice(0, -1) + char + keys[++i];
|
|
100
|
+
export function split(path, options) {
|
|
101
|
+
const id = createKey(path, options);
|
|
102
|
+
if (set.memo[id]) return set.memo[id];
|
|
103
|
+
const char = options && options.separator ? options.separator : '.';
|
|
104
|
+
let keys = [];
|
|
105
|
+
const res = [];
|
|
106
|
+
if (options && typeof options.split === 'function') {
|
|
107
|
+
keys = options.split(path);
|
|
108
|
+
} else {
|
|
109
|
+
keys = path.split(char);
|
|
159
110
|
}
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
111
|
+
for(let i = 0; i < keys.length; i++){
|
|
112
|
+
let prop = keys[i];
|
|
113
|
+
while(prop && prop.slice(-1) === '\\' && keys[i + 1]){
|
|
114
|
+
prop = prop.slice(0, -1) + char + keys[++i];
|
|
115
|
+
}
|
|
116
|
+
res.push(prop);
|
|
117
|
+
}
|
|
118
|
+
set.memo[id] = res;
|
|
119
|
+
return res;
|
|
166
120
|
}
|
|
167
|
-
|
|
168
|
-
var _default = set;
|
|
169
|
-
exports.default = _default;
|
|
121
|
+
export default set;
|