@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/type.js
CHANGED
|
@@ -1,15 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.default = void 0;
|
|
7
|
-
|
|
8
|
-
/* eslint-disable indent */
|
|
9
|
-
|
|
10
|
-
/* eslint-disable default-case */
|
|
11
|
-
|
|
12
|
-
/*
|
|
1
|
+
/* eslint-disable indent */ /* eslint-disable default-case */ /*
|
|
13
2
|
Copyright 2020-2021 Lowdefy, Inc
|
|
14
3
|
|
|
15
4
|
Licensed under the Apache License, Version 2.0 (the "License");
|
|
@@ -23,263 +12,205 @@ exports.default = void 0;
|
|
|
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
|
-
// Derived from source:
|
|
15
|
+
*/ // Derived from source:
|
|
28
16
|
// because both js typeof and instance of sucks! use this.
|
|
29
17
|
// https://ultimatecourses.com/blog/understanding-javascript-types-and-reliable-type-checking
|
|
30
|
-
|
|
31
|
-
toString
|
|
32
|
-
} = Object.prototype;
|
|
33
|
-
|
|
18
|
+
const { toString } = Object.prototype;
|
|
34
19
|
function ctorName(val) {
|
|
35
|
-
|
|
20
|
+
return val.constructor ? val.constructor.name : null;
|
|
36
21
|
}
|
|
37
|
-
|
|
38
22
|
function isArray(val) {
|
|
39
|
-
|
|
40
|
-
|
|
23
|
+
if (Array.isArray) return Array.isArray(val);
|
|
24
|
+
return val instanceof Array;
|
|
41
25
|
}
|
|
42
|
-
|
|
43
26
|
function isError(val) {
|
|
44
|
-
|
|
27
|
+
return !!val && (val instanceof Error || typeof val.message === 'string' && val.constructor && typeof val.constructor.stackTraceLimit === 'number');
|
|
45
28
|
}
|
|
46
|
-
|
|
47
29
|
function isDate(val) {
|
|
48
|
-
|
|
49
|
-
|
|
30
|
+
if (val instanceof Date && !Number.isNaN(val.getTime())) return true;
|
|
31
|
+
return val && typeof val.toDateString === 'function' && typeof val.getDate === 'function' && typeof val.setDate === 'function' && !Number.isNaN(val.getTime());
|
|
50
32
|
}
|
|
51
|
-
|
|
52
33
|
function isRegexp(val) {
|
|
53
|
-
|
|
54
|
-
|
|
34
|
+
if (val instanceof RegExp) return true;
|
|
35
|
+
return typeof val.flags === 'string' && typeof val.ignoreCase === 'boolean' && typeof val.multiline === 'boolean' && typeof val.global === 'boolean';
|
|
55
36
|
}
|
|
56
|
-
|
|
57
37
|
function isGeneratorFn(name) {
|
|
58
|
-
|
|
38
|
+
return ctorName(name) === 'GeneratorFunction';
|
|
59
39
|
}
|
|
60
|
-
|
|
61
40
|
function isGeneratorObj(val) {
|
|
62
|
-
|
|
41
|
+
return typeof val.throw === 'function' && typeof val.return === 'function' && typeof val.next === 'function';
|
|
63
42
|
}
|
|
64
|
-
|
|
65
43
|
function isArguments(val) {
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
44
|
+
try {
|
|
45
|
+
if (typeof val.length === 'number' && typeof val.callee === 'function') {
|
|
46
|
+
return true;
|
|
47
|
+
}
|
|
48
|
+
} catch (err) {
|
|
49
|
+
if (err.message.indexOf('callee') !== -1) {
|
|
50
|
+
return true;
|
|
51
|
+
}
|
|
73
52
|
}
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
return false;
|
|
53
|
+
return false;
|
|
77
54
|
}
|
|
78
55
|
/**
|
|
79
56
|
* If you need to support Safari 5-7 (8-10 yr-old browser),
|
|
80
57
|
* take a look at https://github.com/feross/is-buffer
|
|
81
|
-
*/
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
return val.constructor.isBuffer(val);
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
return false;
|
|
58
|
+
*/ function isBuffer(val) {
|
|
59
|
+
if (val.constructor && typeof val.constructor.isBuffer === 'function') {
|
|
60
|
+
return val.constructor.isBuffer(val);
|
|
61
|
+
}
|
|
62
|
+
return false;
|
|
90
63
|
}
|
|
91
|
-
|
|
92
64
|
function kindOf(val) {
|
|
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
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
//
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
return '
|
|
166
|
-
} // Non-plain objects
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
type = toString.call(val);
|
|
170
|
-
|
|
171
|
-
switch (type) {
|
|
172
|
-
case '[object Object]':
|
|
173
|
-
return 'object';
|
|
174
|
-
// iterators
|
|
175
|
-
|
|
176
|
-
case '[object Map Iterator]':
|
|
177
|
-
return 'mapiterator';
|
|
178
|
-
|
|
179
|
-
case '[object Set Iterator]':
|
|
180
|
-
return 'setiterator';
|
|
181
|
-
|
|
182
|
-
case '[object String Iterator]':
|
|
183
|
-
return 'stringiterator';
|
|
184
|
-
|
|
185
|
-
case '[object Array Iterator]':
|
|
186
|
-
return 'arrayiterator';
|
|
187
|
-
} // other
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
return type.slice(8, -1).toLowerCase().replace(/\s/g, '');
|
|
65
|
+
// eslint-disable-next-line no-void
|
|
66
|
+
if (val === void 0) return 'undefined';
|
|
67
|
+
if (val === null) return 'null';
|
|
68
|
+
let type = typeof val;
|
|
69
|
+
if (type === 'boolean') return 'boolean';
|
|
70
|
+
if (type === 'string') return 'string';
|
|
71
|
+
if (type === 'number') return 'number';
|
|
72
|
+
if (type === 'symbol') return 'symbol';
|
|
73
|
+
if (type === 'function') {
|
|
74
|
+
return isGeneratorFn(val) ? 'generatorfunction' : 'function';
|
|
75
|
+
}
|
|
76
|
+
if (isArray(val)) return 'array';
|
|
77
|
+
if (isDate(val)) return 'date';
|
|
78
|
+
if (isError(val)) return 'error';
|
|
79
|
+
if (isRegexp(val)) return 'regexp';
|
|
80
|
+
if (isArguments(val)) return 'arguments';
|
|
81
|
+
if (isBuffer(val)) return 'buffer';
|
|
82
|
+
switch(ctorName(val)){
|
|
83
|
+
case 'Symbol':
|
|
84
|
+
return 'symbol';
|
|
85
|
+
case 'Promise':
|
|
86
|
+
return 'promise';
|
|
87
|
+
// Set, Map, WeakSet, WeakMap
|
|
88
|
+
case 'WeakMap':
|
|
89
|
+
return 'weakmap';
|
|
90
|
+
case 'WeakSet':
|
|
91
|
+
return 'weakset';
|
|
92
|
+
case 'Map':
|
|
93
|
+
return 'map';
|
|
94
|
+
case 'Set':
|
|
95
|
+
return 'set';
|
|
96
|
+
// 8-bit typed arrays
|
|
97
|
+
case 'Int8Array':
|
|
98
|
+
return 'int8array';
|
|
99
|
+
case 'Uint8Array':
|
|
100
|
+
return 'uint8array';
|
|
101
|
+
case 'Uint8ClampedArray':
|
|
102
|
+
return 'uint8clampedarray';
|
|
103
|
+
// 16-bit typed arrays
|
|
104
|
+
case 'Int16Array':
|
|
105
|
+
return 'int16array';
|
|
106
|
+
case 'Uint16Array':
|
|
107
|
+
return 'uint16array';
|
|
108
|
+
// 32-bit typed arrays
|
|
109
|
+
case 'Int32Array':
|
|
110
|
+
return 'int32array';
|
|
111
|
+
case 'Uint32Array':
|
|
112
|
+
return 'uint32array';
|
|
113
|
+
case 'Float32Array':
|
|
114
|
+
return 'float32array';
|
|
115
|
+
case 'Float64Array':
|
|
116
|
+
return 'float64array';
|
|
117
|
+
}
|
|
118
|
+
if (isGeneratorObj(val)) {
|
|
119
|
+
return 'generator';
|
|
120
|
+
}
|
|
121
|
+
// Non-plain objects
|
|
122
|
+
type = toString.call(val);
|
|
123
|
+
switch(type){
|
|
124
|
+
case '[object Object]':
|
|
125
|
+
return 'object';
|
|
126
|
+
// iterators
|
|
127
|
+
case '[object Map Iterator]':
|
|
128
|
+
return 'mapiterator';
|
|
129
|
+
case '[object Set Iterator]':
|
|
130
|
+
return 'setiterator';
|
|
131
|
+
case '[object String Iterator]':
|
|
132
|
+
return 'stringiterator';
|
|
133
|
+
case '[object Array Iterator]':
|
|
134
|
+
return 'arrayiterator';
|
|
135
|
+
}
|
|
136
|
+
// other
|
|
137
|
+
return type.slice(8, -1).toLowerCase().replace(/\s/g, '');
|
|
191
138
|
}
|
|
192
|
-
|
|
193
|
-
var reISO = /^(\d{4})-(\d{2})-(\d{2})T(\d{2}):(\d{2}):(\d{2}(?:\.\d*))(?:Z|(\+|-)([\d|:]*))?$/;
|
|
194
|
-
|
|
139
|
+
const reISO = /^(\d{4})-(\d{2})-(\d{2})T(\d{2}):(\d{2}):(\d{2}(?:\.\d*))(?:Z|(\+|-)([\d|:]*))?$/;
|
|
195
140
|
function isDateString(val) {
|
|
196
|
-
|
|
141
|
+
return reISO.test(val);
|
|
197
142
|
}
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
143
|
+
const type1 = {
|
|
144
|
+
};
|
|
145
|
+
type1.typeOf = kindOf;
|
|
146
|
+
type1.isArray = isArray;
|
|
147
|
+
type1.isDate = isDate;
|
|
148
|
+
type1.isError = isError;
|
|
149
|
+
type1.isDateString = isDateString;
|
|
150
|
+
type1.isObject = (value)=>kindOf(value) === 'object'
|
|
151
|
+
;
|
|
152
|
+
type1.isString = (value)=>typeof value === 'string'
|
|
153
|
+
;
|
|
154
|
+
type1.isRegExp = (value)=>kindOf(value) === 'regexp'
|
|
155
|
+
;
|
|
156
|
+
type1.isFunction = (value)=>kindOf(value) === 'function'
|
|
157
|
+
;
|
|
158
|
+
type1.isBoolean = (value)=>typeof value === 'boolean'
|
|
159
|
+
;
|
|
160
|
+
type1.isNumber = (value)=>typeof value === 'number' && Number.isFinite(value)
|
|
161
|
+
;
|
|
162
|
+
type1.isNumeric = (value)=>!Number.isNaN(Number(value))
|
|
163
|
+
;
|
|
164
|
+
type1.isInt = (value)=>Number.isInteger(value) === true
|
|
165
|
+
;
|
|
166
|
+
type1.isSet = (value)=>kindOf(value) === 'set'
|
|
167
|
+
;
|
|
168
|
+
type1.isNull = (value)=>kindOf(value) === 'null'
|
|
169
|
+
;
|
|
170
|
+
type1.isUndefined = (value)=>kindOf(value) === 'undefined'
|
|
171
|
+
;
|
|
172
|
+
type1.isNone = (value)=>kindOf(value) === 'undefined' || kindOf(value) === 'null'
|
|
173
|
+
;
|
|
174
|
+
type1.isPrimitive = (value)=>kindOf(value) === 'undefined' || kindOf(value) === 'null' || kindOf(value) === 'string' || kindOf(value) === 'number' || kindOf(value) === 'boolean' || kindOf(value) === 'date'
|
|
175
|
+
;
|
|
176
|
+
type1.isEmptyObject = (value)=>kindOf(value) === 'object' && Object.keys(value).length === 0
|
|
177
|
+
;
|
|
178
|
+
// Lowdefy operator types
|
|
236
179
|
function isName(value) {
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
180
|
+
if (!type1.isString(value)) return false;
|
|
181
|
+
const noLeadingNumeric = value.split('.').reduce((acc, val)=>acc && !type1.isNumeric(val.charAt(0))
|
|
182
|
+
, true);
|
|
183
|
+
const noLeadTrailStop = value.charAt(0) !== '.' && value.charAt(value.length - 1) !== '.';
|
|
184
|
+
const noLowdefy = !value.toLowerCase().startsWith('lowdefy');
|
|
185
|
+
return /^[a-zA-Z0-9_.]+$/g.test(value) && noLeadTrailStop && noLeadingNumeric && noLowdefy;
|
|
242
186
|
}
|
|
243
|
-
|
|
244
187
|
function isOpRequest(val) {
|
|
245
|
-
|
|
246
|
-
}
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
type.isName = isName;
|
|
251
|
-
|
|
188
|
+
return kindOf(val) === 'object' && '_request' in val && isName(val._request);
|
|
189
|
+
}
|
|
190
|
+
// Lowdefy
|
|
191
|
+
type1.isOpRequest = isOpRequest;
|
|
192
|
+
type1.isName = isName;
|
|
252
193
|
function enforceType(typeName, value) {
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
return type.isObject(value) ? value : null;
|
|
274
|
-
|
|
275
|
-
case 'any':
|
|
276
|
-
return !type.isUndefined(value) ? value : null;
|
|
277
|
-
|
|
278
|
-
default:
|
|
279
|
-
return null;
|
|
280
|
-
}
|
|
194
|
+
switch(typeName){
|
|
195
|
+
case 'string':
|
|
196
|
+
return type1.isString(value) && value !== '' ? value : null;
|
|
197
|
+
case 'number':
|
|
198
|
+
return type1.isNumber(value) ? value : null;
|
|
199
|
+
case 'boolean':
|
|
200
|
+
return type1.isBoolean(value) ? value : false;
|
|
201
|
+
case 'date':
|
|
202
|
+
return type1.isDate(value) ? value : null;
|
|
203
|
+
case 'array':
|
|
204
|
+
return type1.isArray(value) ? value : [];
|
|
205
|
+
case 'primitive':
|
|
206
|
+
return type1.isString(value) && value !== '' || type1.isNumber(value) || type1.isDate(value) || type1.isBoolean(value) ? value : null;
|
|
207
|
+
case 'object':
|
|
208
|
+
return type1.isObject(value) ? value : null;
|
|
209
|
+
case 'any':
|
|
210
|
+
return !type1.isUndefined(value) ? value : null;
|
|
211
|
+
default:
|
|
212
|
+
return null;
|
|
213
|
+
}
|
|
281
214
|
}
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
var _default = type;
|
|
285
|
-
exports.default = _default;
|
|
215
|
+
type1.enforceType = enforceType;
|
|
216
|
+
export default type1;
|
package/dist/unset.js
CHANGED
|
@@ -1,19 +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
|
-
var _get = _interopRequireDefault(require("./get"));
|
|
11
|
-
|
|
12
|
-
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
13
|
-
|
|
14
|
-
/* eslint-disable no-param-reassign */
|
|
15
|
-
|
|
16
|
-
/*
|
|
1
|
+
/* eslint-disable no-param-reassign */ /*
|
|
17
2
|
Copyright 2020-2021 Lowdefy, Inc
|
|
18
3
|
|
|
19
4
|
Licensed under the Apache License, Version 2.0 (the "License");
|
|
@@ -27,8 +12,7 @@ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { de
|
|
|
27
12
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
28
13
|
See the License for the specific language governing permissions and
|
|
29
14
|
limitations under the License.
|
|
30
|
-
*/
|
|
31
|
-
// Derived from source:
|
|
15
|
+
*/ // Derived from source:
|
|
32
16
|
// https://github.com/jonschlinkert/unset-value/blob/master/index.js
|
|
33
17
|
// https://github.com/jonschlinkert/unset-value/issues/3
|
|
34
18
|
// The MIT License (MIT)
|
|
@@ -48,92 +32,73 @@ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { de
|
|
|
48
32
|
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
49
33
|
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
50
34
|
// THE SOFTWARE.
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
default:
|
|
95
|
-
{
|
|
96
|
-
return true;
|
|
97
|
-
}
|
|
98
|
-
}
|
|
35
|
+
import type from './type.js';
|
|
36
|
+
import get from './get.js';
|
|
37
|
+
const hasValues = (val)=>{
|
|
38
|
+
switch(type.typeOf(val)){
|
|
39
|
+
case 'boolean':
|
|
40
|
+
case 'date':
|
|
41
|
+
case 'function':
|
|
42
|
+
case 'null':
|
|
43
|
+
case 'number':
|
|
44
|
+
return true;
|
|
45
|
+
case 'undefined':
|
|
46
|
+
return false;
|
|
47
|
+
case 'regexp':
|
|
48
|
+
return val.source !== '(?:)' && val.source !== '';
|
|
49
|
+
case 'buffer':
|
|
50
|
+
return val.toString() !== '';
|
|
51
|
+
case 'error':
|
|
52
|
+
return val.message !== '';
|
|
53
|
+
case 'string':
|
|
54
|
+
case 'arguments':
|
|
55
|
+
return val.length !== 0;
|
|
56
|
+
case 'file':
|
|
57
|
+
case 'map':
|
|
58
|
+
case 'set':
|
|
59
|
+
return val.size !== 0;
|
|
60
|
+
case 'array':
|
|
61
|
+
case 'object':
|
|
62
|
+
// eslint-disable-next-line no-restricted-syntax
|
|
63
|
+
// CHANGED - we are assuming that an empty object and array is a value.
|
|
64
|
+
// for (const key of Object.keys(val)) {
|
|
65
|
+
// if (hasValues(val[key])) {
|
|
66
|
+
// return true;
|
|
67
|
+
// }
|
|
68
|
+
// }
|
|
69
|
+
// return false;
|
|
70
|
+
return true;
|
|
71
|
+
// everything else
|
|
72
|
+
default:
|
|
73
|
+
{
|
|
74
|
+
return true;
|
|
75
|
+
}
|
|
76
|
+
}
|
|
99
77
|
};
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
return false;
|
|
78
|
+
const hasValue = (obj, path, options)=>{
|
|
79
|
+
if (type.isObject(obj) && (type.isString(path) || type.isArray(path))) {
|
|
80
|
+
return hasValues(get(obj, path, options));
|
|
81
|
+
}
|
|
82
|
+
return false;
|
|
107
83
|
};
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
throw new TypeError('expected an object.');
|
|
113
|
-
}
|
|
114
|
-
|
|
115
|
-
if (Object.prototype.hasOwnProperty.call(obj, prop)) {
|
|
116
|
-
delete obj[prop];
|
|
117
|
-
return true;
|
|
118
|
-
}
|
|
119
|
-
|
|
120
|
-
if (hasValue(obj, prop)) {
|
|
121
|
-
var segs = prop.split('.');
|
|
122
|
-
var last = segs.pop();
|
|
123
|
-
|
|
124
|
-
while (segs.length && segs[segs.length - 1].slice(-1) === '\\') {
|
|
125
|
-
last = "".concat(segs.pop().slice(0, -1), ".").concat(last);
|
|
84
|
+
const unset = (obj, prop)=>{
|
|
85
|
+
// support array refence in the form a.0 , a.0.b or a[0] , a[0].b
|
|
86
|
+
if (!type.isObject(obj)) {
|
|
87
|
+
throw new TypeError('expected an object.');
|
|
126
88
|
}
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
89
|
+
if (Object.prototype.hasOwnProperty.call(obj, prop)) {
|
|
90
|
+
delete obj[prop];
|
|
91
|
+
return true;
|
|
130
92
|
}
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
93
|
+
if (hasValue(obj, prop)) {
|
|
94
|
+
const segs = prop.split('.');
|
|
95
|
+
let last = segs.pop();
|
|
96
|
+
while(segs.length && segs[segs.length - 1].slice(-1) === '\\'){
|
|
97
|
+
last = `${segs.pop().slice(0, -1)}.${last}`;
|
|
98
|
+
}
|
|
99
|
+
while(segs.length)obj = obj[segs.shift()];
|
|
100
|
+
return delete obj[last];
|
|
101
|
+
}
|
|
102
|
+
return true;
|
|
136
103
|
};
|
|
137
|
-
|
|
138
|
-
var _default = unset;
|
|
139
|
-
exports.default = _default;
|
|
104
|
+
export default unset;
|