@lowdefy/helpers 4.0.0-alpha.5 → 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/index.js +2 -1
- package/dist/serializer.js +5 -10
- package/dist/set.js +4 -8
- package/dist/stableStringify.js +1 -2
- package/dist/type.js +43 -44
- package/dist/urlQuery.js +2 -4
- package/dist/wait.js +19 -0
- package/package.json +5 -5
package/dist/index.js
CHANGED
|
@@ -24,4 +24,5 @@ import swap from './swap.js';
|
|
|
24
24
|
import type from './type.js';
|
|
25
25
|
import unset from './unset.js';
|
|
26
26
|
import urlQuery from './urlQuery.js';
|
|
27
|
-
|
|
27
|
+
import wait from './wait.js';
|
|
28
|
+
export { applyArrayIndices, cachedPromises, get, mergeObjects, omit, serializer, set, stableStringify, swap, type, unset, urlQuery, wait };
|
package/dist/serializer.js
CHANGED
|
@@ -87,8 +87,7 @@ const makeReviver = (customReviver)=>(key, value)=>{
|
|
|
87
87
|
return newValue;
|
|
88
88
|
}
|
|
89
89
|
;
|
|
90
|
-
const serialize = (json, options = {
|
|
91
|
-
})=>{
|
|
90
|
+
const serialize = (json, options = {})=>{
|
|
92
91
|
if (type.isUndefined(json)) return json;
|
|
93
92
|
if (type.isDate(json)) {
|
|
94
93
|
if (options.isoStringDates) {
|
|
@@ -102,8 +101,7 @@ const serialize = (json, options = {
|
|
|
102
101
|
}
|
|
103
102
|
return JSON.parse(JSON.stringify(json, makeReplacer(options.replacer, options.isoStringDates)));
|
|
104
103
|
};
|
|
105
|
-
const serializeToString = (json, options = {
|
|
106
|
-
})=>{
|
|
104
|
+
const serializeToString = (json, options = {})=>{
|
|
107
105
|
if (type.isUndefined(json)) return json;
|
|
108
106
|
if (type.isDate(json)) {
|
|
109
107
|
if (options.isoStringDates) {
|
|
@@ -119,18 +117,15 @@ const serializeToString = (json, options = {
|
|
|
119
117
|
}
|
|
120
118
|
return JSON.stringify(json, makeReplacer(options.replacer, options.isoStringDates), options.space);
|
|
121
119
|
};
|
|
122
|
-
const deserialize = (json, options = {
|
|
123
|
-
})=>{
|
|
120
|
+
const deserialize = (json, options = {})=>{
|
|
124
121
|
if (type.isUndefined(json)) return json;
|
|
125
122
|
return JSON.parse(JSON.stringify(json), makeReviver(options.reviver));
|
|
126
123
|
};
|
|
127
|
-
const deserializeFromString = (str, options = {
|
|
128
|
-
})=>{
|
|
124
|
+
const deserializeFromString = (str, options = {})=>{
|
|
129
125
|
if (type.isUndefined(str)) return str;
|
|
130
126
|
return JSON.parse(str, makeReviver(options.reviver));
|
|
131
127
|
};
|
|
132
|
-
const copy = (json, options = {
|
|
133
|
-
})=>{
|
|
128
|
+
const copy = (json, options = {})=>{
|
|
134
129
|
if (type.isUndefined(json)) return undefined;
|
|
135
130
|
if (type.isDate(json)) return new Date(json.valueOf());
|
|
136
131
|
return JSON.parse(JSON.stringify(json, makeReplacer(options.replacer)), makeReviver(options.reviver));
|
package/dist/set.js
CHANGED
|
@@ -41,21 +41,18 @@ function isObjectOrFunction(val) {
|
|
|
41
41
|
}
|
|
42
42
|
function result(target, path, value, merge) {
|
|
43
43
|
if (merge && isObjectOrFunction(target[path]) && isObjectOrFunction(value)) {
|
|
44
|
-
target[path] = merge({
|
|
45
|
-
}, target[path], value);
|
|
44
|
+
target[path] = merge({}, target[path], value);
|
|
46
45
|
} else {
|
|
47
46
|
target[path] = value;
|
|
48
47
|
}
|
|
49
48
|
}
|
|
50
49
|
// eslint-disable-next-line no-use-before-define
|
|
51
|
-
set.memo = {
|
|
52
|
-
};
|
|
50
|
+
set.memo = {};
|
|
53
51
|
function set(target, path, value, options) {
|
|
54
52
|
if (!type.isObject(target)) {
|
|
55
53
|
return target;
|
|
56
54
|
}
|
|
57
|
-
const opts = options || {
|
|
58
|
-
};
|
|
55
|
+
const opts = options || {};
|
|
59
56
|
if (!type.isArray(path) && !type.isString(path)) {
|
|
60
57
|
return target;
|
|
61
58
|
}
|
|
@@ -75,8 +72,7 @@ function set(target, path, value, options) {
|
|
|
75
72
|
const propUp = keys[i + 1]; // changed to set an array value where the array was undefined be assigning value
|
|
76
73
|
if (!isObjectOrFunction(target[prop]) && !type.isInt(parseInt(propUp, 10))) {
|
|
77
74
|
// changed
|
|
78
|
-
target[prop] = {
|
|
79
|
-
};
|
|
75
|
+
target[prop] = {};
|
|
80
76
|
} else if (!isObjectOrFunction(target[prop]) && type.isInt(parseInt(propUp, 10))) {
|
|
81
77
|
// added
|
|
82
78
|
target[prop] = []; // added
|
package/dist/stableStringify.js
CHANGED
|
@@ -32,8 +32,7 @@
|
|
|
32
32
|
// CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
33
33
|
import type from './type.js';
|
|
34
34
|
function stableStringify(obj, opts) {
|
|
35
|
-
if (!opts) opts = {
|
|
36
|
-
};
|
|
35
|
+
if (!opts) opts = {};
|
|
37
36
|
if (typeof opts === 'function') opts = {
|
|
38
37
|
cmp: opts
|
|
39
38
|
};
|
package/dist/type.js
CHANGED
|
@@ -65,12 +65,12 @@ function kindOf(val) {
|
|
|
65
65
|
// eslint-disable-next-line no-void
|
|
66
66
|
if (val === void 0) return 'undefined';
|
|
67
67
|
if (val === null) return 'null';
|
|
68
|
-
let
|
|
69
|
-
if (
|
|
70
|
-
if (
|
|
71
|
-
if (
|
|
72
|
-
if (
|
|
73
|
-
if (
|
|
68
|
+
let type1 = typeof val;
|
|
69
|
+
if (type1 === 'boolean') return 'boolean';
|
|
70
|
+
if (type1 === 'string') return 'string';
|
|
71
|
+
if (type1 === 'number') return 'number';
|
|
72
|
+
if (type1 === 'symbol') return 'symbol';
|
|
73
|
+
if (type1 === 'function') {
|
|
74
74
|
return isGeneratorFn(val) ? 'generatorfunction' : 'function';
|
|
75
75
|
}
|
|
76
76
|
if (isArray(val)) return 'array';
|
|
@@ -119,8 +119,8 @@ function kindOf(val) {
|
|
|
119
119
|
return 'generator';
|
|
120
120
|
}
|
|
121
121
|
// Non-plain objects
|
|
122
|
-
|
|
123
|
-
switch(
|
|
122
|
+
type1 = toString.call(val);
|
|
123
|
+
switch(type1){
|
|
124
124
|
case '[object Object]':
|
|
125
125
|
return 'object';
|
|
126
126
|
// iterators
|
|
@@ -134,51 +134,50 @@ function kindOf(val) {
|
|
|
134
134
|
return 'arrayiterator';
|
|
135
135
|
}
|
|
136
136
|
// other
|
|
137
|
-
return
|
|
137
|
+
return type1.slice(8, -1).toLowerCase().replace(/\s/g, '');
|
|
138
138
|
}
|
|
139
139
|
const reISO = /^(\d{4})-(\d{2})-(\d{2})T(\d{2}):(\d{2}):(\d{2}(?:\.\d*))(?:Z|(\+|-)([\d|:]*))?$/;
|
|
140
140
|
function isDateString(val) {
|
|
141
141
|
return reISO.test(val);
|
|
142
142
|
}
|
|
143
|
-
const
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
type1.isObject = (value)=>kindOf(value) === 'object'
|
|
143
|
+
const type = {};
|
|
144
|
+
type.typeOf = kindOf;
|
|
145
|
+
type.isArray = isArray;
|
|
146
|
+
type.isDate = isDate;
|
|
147
|
+
type.isError = isError;
|
|
148
|
+
type.isDateString = isDateString;
|
|
149
|
+
type.isObject = (value)=>kindOf(value) === 'object'
|
|
151
150
|
;
|
|
152
|
-
|
|
151
|
+
type.isString = (value)=>typeof value === 'string'
|
|
153
152
|
;
|
|
154
|
-
|
|
153
|
+
type.isRegExp = (value)=>kindOf(value) === 'regexp'
|
|
155
154
|
;
|
|
156
|
-
|
|
155
|
+
type.isFunction = (value)=>kindOf(value) === 'function'
|
|
157
156
|
;
|
|
158
|
-
|
|
157
|
+
type.isBoolean = (value)=>typeof value === 'boolean'
|
|
159
158
|
;
|
|
160
|
-
|
|
159
|
+
type.isNumber = (value)=>typeof value === 'number' && Number.isFinite(value)
|
|
161
160
|
;
|
|
162
|
-
|
|
161
|
+
type.isNumeric = (value)=>!Number.isNaN(Number(value))
|
|
163
162
|
;
|
|
164
|
-
|
|
163
|
+
type.isInt = (value)=>Number.isInteger(value) === true
|
|
165
164
|
;
|
|
166
|
-
|
|
165
|
+
type.isSet = (value)=>kindOf(value) === 'set'
|
|
167
166
|
;
|
|
168
|
-
|
|
167
|
+
type.isNull = (value)=>kindOf(value) === 'null'
|
|
169
168
|
;
|
|
170
|
-
|
|
169
|
+
type.isUndefined = (value)=>kindOf(value) === 'undefined'
|
|
171
170
|
;
|
|
172
|
-
|
|
171
|
+
type.isNone = (value)=>kindOf(value) === 'undefined' || kindOf(value) === 'null'
|
|
173
172
|
;
|
|
174
|
-
|
|
173
|
+
type.isPrimitive = (value)=>kindOf(value) === 'undefined' || kindOf(value) === 'null' || kindOf(value) === 'string' || kindOf(value) === 'number' || kindOf(value) === 'boolean' || kindOf(value) === 'date'
|
|
175
174
|
;
|
|
176
|
-
|
|
175
|
+
type.isEmptyObject = (value)=>kindOf(value) === 'object' && Object.keys(value).length === 0
|
|
177
176
|
;
|
|
178
177
|
// Lowdefy operator types
|
|
179
178
|
function isName(value) {
|
|
180
|
-
if (!
|
|
181
|
-
const noLeadingNumeric = value.split('.').reduce((acc, val)=>acc && !
|
|
179
|
+
if (!type.isString(value)) return false;
|
|
180
|
+
const noLeadingNumeric = value.split('.').reduce((acc, val)=>acc && !type.isNumeric(val.charAt(0))
|
|
182
181
|
, true);
|
|
183
182
|
const noLeadTrailStop = value.charAt(0) !== '.' && value.charAt(value.length - 1) !== '.';
|
|
184
183
|
const noLowdefy = !value.toLowerCase().startsWith('lowdefy');
|
|
@@ -188,29 +187,29 @@ function isOpRequest(val) {
|
|
|
188
187
|
return kindOf(val) === 'object' && '_request' in val && isName(val._request);
|
|
189
188
|
}
|
|
190
189
|
// Lowdefy
|
|
191
|
-
|
|
192
|
-
|
|
190
|
+
type.isOpRequest = isOpRequest;
|
|
191
|
+
type.isName = isName;
|
|
193
192
|
function enforceType(typeName, value) {
|
|
194
193
|
switch(typeName){
|
|
195
194
|
case 'string':
|
|
196
|
-
return
|
|
195
|
+
return type.isString(value) && value !== '' ? value : null;
|
|
197
196
|
case 'number':
|
|
198
|
-
return
|
|
197
|
+
return type.isNumber(value) ? value : null;
|
|
199
198
|
case 'boolean':
|
|
200
|
-
return
|
|
199
|
+
return type.isBoolean(value) ? value : false;
|
|
201
200
|
case 'date':
|
|
202
|
-
return
|
|
201
|
+
return type.isDate(value) ? value : null;
|
|
203
202
|
case 'array':
|
|
204
|
-
return
|
|
203
|
+
return type.isArray(value) ? value : [];
|
|
205
204
|
case 'primitive':
|
|
206
|
-
return
|
|
205
|
+
return type.isString(value) && value !== '' || type.isNumber(value) || type.isDate(value) || type.isBoolean(value) ? value : null;
|
|
207
206
|
case 'object':
|
|
208
|
-
return
|
|
207
|
+
return type.isObject(value) ? value : null;
|
|
209
208
|
case 'any':
|
|
210
|
-
return !
|
|
209
|
+
return !type.isUndefined(value) ? value : null;
|
|
211
210
|
default:
|
|
212
211
|
return null;
|
|
213
212
|
}
|
|
214
213
|
}
|
|
215
|
-
|
|
216
|
-
export default
|
|
214
|
+
type.enforceType = enforceType;
|
|
215
|
+
export default type;
|
package/dist/urlQuery.js
CHANGED
|
@@ -18,8 +18,7 @@ import serializer from './serializer.js';
|
|
|
18
18
|
import type from './type.js';
|
|
19
19
|
const parse = (str)=>{
|
|
20
20
|
const parsed = queryString.parse(str);
|
|
21
|
-
const deserialized = {
|
|
22
|
-
};
|
|
21
|
+
const deserialized = {};
|
|
23
22
|
Object.keys(parsed).forEach((key)=>{
|
|
24
23
|
try {
|
|
25
24
|
deserialized[key] = serializer.deserializeFromString(parsed[key]);
|
|
@@ -33,8 +32,7 @@ const stringify = (object)=>{
|
|
|
33
32
|
if (!type.isObject(object)) {
|
|
34
33
|
return '';
|
|
35
34
|
}
|
|
36
|
-
const toSerialize = {
|
|
37
|
-
};
|
|
35
|
+
const toSerialize = {};
|
|
38
36
|
Object.keys(object).forEach((key)=>{
|
|
39
37
|
toSerialize[key] = serializer.serializeToString(object[key]);
|
|
40
38
|
});
|
package/dist/wait.js
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/*
|
|
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
|
+
*/ async function wait(ms) {
|
|
16
|
+
return new Promise((resolve)=>setTimeout(resolve, ms)
|
|
17
|
+
);
|
|
18
|
+
}
|
|
19
|
+
export default wait;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lowdefy/helpers",
|
|
3
|
-
"version": "4.0.0-alpha.
|
|
3
|
+
"version": "4.0.0-alpha.6",
|
|
4
4
|
"licence": "Apache-2.0",
|
|
5
5
|
"description": "",
|
|
6
6
|
"homepage": "https://lowdefy.com",
|
|
@@ -42,14 +42,14 @@
|
|
|
42
42
|
"query-string": "7.0.1"
|
|
43
43
|
},
|
|
44
44
|
"devDependencies": {
|
|
45
|
-
"@swc/cli": "0.1.
|
|
46
|
-
"@swc/core": "1.2.
|
|
47
|
-
"@swc/jest": "0.2.
|
|
45
|
+
"@swc/cli": "0.1.55",
|
|
46
|
+
"@swc/core": "1.2.130",
|
|
47
|
+
"@swc/jest": "0.2.17",
|
|
48
48
|
"jest": "27.3.1",
|
|
49
49
|
"jest-diff": "27.3.1"
|
|
50
50
|
},
|
|
51
51
|
"publishConfig": {
|
|
52
52
|
"access": "public"
|
|
53
53
|
},
|
|
54
|
-
"gitHead": "
|
|
54
|
+
"gitHead": "2530e31af795b6a3c75ac8f72c8dbe0ab5d1251b"
|
|
55
55
|
}
|