@lowdefy/helpers 4.0.0-alpha.26 → 4.0.0-alpha.29
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/package.json +4 -5
- package/dist/applyArrayIndices.js +0 -30
- package/dist/cachedPromises.js +0 -27
- package/dist/get.js +0 -133
- package/dist/index.js +0 -28
- package/dist/mergeObjects.js +0 -25
- package/dist/omit.js +0 -22
- package/dist/serializer.js +0 -136
- package/dist/set.js +0 -121
- package/dist/stableStringify.js +0 -99
- package/dist/swap.js +0 -22
- package/dist/type.js +0 -200
- package/dist/unset.js +0 -104
- package/dist/urlQuery.js +0 -44
- package/dist/wait.js +0 -18
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.29",
|
|
4
4
|
"license": "Apache-2.0",
|
|
5
5
|
"description": "",
|
|
6
6
|
"homepage": "https://lowdefy.com",
|
|
@@ -31,10 +31,9 @@
|
|
|
31
31
|
"dist/*"
|
|
32
32
|
],
|
|
33
33
|
"scripts": {
|
|
34
|
-
"build": "
|
|
34
|
+
"build": "swc src --out-dir dist --config-file ../../../.swcrc --delete-dir-on-start",
|
|
35
35
|
"clean": "rm -rf dist",
|
|
36
|
-
"
|
|
37
|
-
"swc": "swc src --out-dir dist --config-file ../../../.swcrc --delete-dir-on-start",
|
|
36
|
+
"prepublishOnly": "pnpm build",
|
|
38
37
|
"test": "jest --coverage"
|
|
39
38
|
},
|
|
40
39
|
"dependencies": {
|
|
@@ -51,5 +50,5 @@
|
|
|
51
50
|
"publishConfig": {
|
|
52
51
|
"access": "public"
|
|
53
52
|
},
|
|
54
|
-
"gitHead": "
|
|
53
|
+
"gitHead": "621a191ebc0a1569ee6669dc74c12f8be5a8c7f3"
|
|
55
54
|
}
|
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
/*
|
|
2
|
-
Copyright 2020-2022 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
|
-
const applyArrayIndices = (arrayIndices, name)=>{
|
|
17
|
-
if (!type.isArray(arrayIndices)) return name;
|
|
18
|
-
if (arrayIndices.length === 0) return name;
|
|
19
|
-
if (type.isNumber(name)) return name;
|
|
20
|
-
const copy = JSON.parse(JSON.stringify(arrayIndices));
|
|
21
|
-
const index = copy.shift();
|
|
22
|
-
let newName;
|
|
23
|
-
if (name.includes('$')) {
|
|
24
|
-
newName = name.replace('$', index.toString()); // lgtm [js/incomplete-sanitization]
|
|
25
|
-
} else {
|
|
26
|
-
newName = name;
|
|
27
|
-
}
|
|
28
|
-
return applyArrayIndices(copy, newName);
|
|
29
|
-
};
|
|
30
|
-
export default applyArrayIndices;
|
package/dist/cachedPromises.js
DELETED
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
/*
|
|
2
|
-
Copyright 2020-2022 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
|
-
*/ function createCachedPromises(getter) {
|
|
16
|
-
const cache = new Map();
|
|
17
|
-
function cachedPromises(key) {
|
|
18
|
-
if (cache.has(key)) {
|
|
19
|
-
return Promise.resolve(cache.get(key));
|
|
20
|
-
}
|
|
21
|
-
const promise = getter(key);
|
|
22
|
-
cache.set(key, promise);
|
|
23
|
-
return Promise.resolve(promise);
|
|
24
|
-
}
|
|
25
|
-
return cachedPromises;
|
|
26
|
-
}
|
|
27
|
-
export default createCachedPromises;
|
package/dist/get.js
DELETED
|
@@ -1,133 +0,0 @@
|
|
|
1
|
-
/* eslint-disable no-param-reassign */ /*
|
|
2
|
-
Copyright 2020-2022 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
|
-
*/ // Derived from source:
|
|
16
|
-
// https://github.com/jonschlinkert/get-value/blob/master/index.js
|
|
17
|
-
// https://www.npmjs.com/package/get-value
|
|
18
|
-
// The MIT License (MIT)
|
|
19
|
-
// Copyright (c) 2014-2018, Jon Schlinkert.
|
|
20
|
-
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
21
|
-
// of this software and associated documentation files (the "Software"), to deal
|
|
22
|
-
// in the Software without restriction, including without limitation the rights
|
|
23
|
-
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
24
|
-
// copies of the Software, and to permit persons to whom the Software is
|
|
25
|
-
// furnished to do so, subject to the following conditions:
|
|
26
|
-
// The above copyright notice and this permission notice shall be included in
|
|
27
|
-
// all copies or substantial portions of the Software.
|
|
28
|
-
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
29
|
-
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
30
|
-
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
31
|
-
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
32
|
-
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
33
|
-
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
34
|
-
// THE SOFTWARE.
|
|
35
|
-
import typeTest from './type.js';
|
|
36
|
-
import serializer from './serializer.js';
|
|
37
|
-
function join(segs, joinChar, options) {
|
|
38
|
-
if (typeof options.join === 'function') {
|
|
39
|
-
return options.join(segs);
|
|
40
|
-
}
|
|
41
|
-
return segs[0] + joinChar + segs[1];
|
|
42
|
-
}
|
|
43
|
-
function split(path, splitChar, options) {
|
|
44
|
-
if (typeof options.split === 'function') {
|
|
45
|
-
return options.split(path);
|
|
46
|
-
}
|
|
47
|
-
return path.split(splitChar);
|
|
48
|
-
}
|
|
49
|
-
function isValid(key, target, options) {
|
|
50
|
-
if (typeof options.isValid === 'function') {
|
|
51
|
-
return options.isValid(key, target);
|
|
52
|
-
}
|
|
53
|
-
return true;
|
|
54
|
-
}
|
|
55
|
-
function isValidObject(val) {
|
|
56
|
-
return typeTest.isObject(val) || Array.isArray(val) || typeof val === 'function';
|
|
57
|
-
}
|
|
58
|
-
function getter(target, path, options) {
|
|
59
|
-
if (typeTest.isNone(path) || !isValidObject(target)) {
|
|
60
|
-
return typeof options.default !== 'undefined' ? options.default : undefined;
|
|
61
|
-
}
|
|
62
|
-
if (typeof path === 'number') {
|
|
63
|
-
path = String(path);
|
|
64
|
-
}
|
|
65
|
-
const isArray = Array.isArray(path);
|
|
66
|
-
const isString = typeof path === 'string';
|
|
67
|
-
const splitChar = options.separator || '.';
|
|
68
|
-
const joinChar = options.joinChar || (typeof splitChar === 'string' ? splitChar : '.');
|
|
69
|
-
if (isString && path in target) {
|
|
70
|
-
return isValid(path, target, options) ? target[path] : options.default;
|
|
71
|
-
}
|
|
72
|
-
const segs = isArray ? path : split(path, splitChar, options);
|
|
73
|
-
const len = segs.length;
|
|
74
|
-
let idx = 0;
|
|
75
|
-
do {
|
|
76
|
-
let prop = segs[idx];
|
|
77
|
-
if (typeof prop === 'number') {
|
|
78
|
-
prop = String(prop);
|
|
79
|
-
}
|
|
80
|
-
while(prop && prop.slice(-1) === '\\'){
|
|
81
|
-
idx += 1;
|
|
82
|
-
prop = join([
|
|
83
|
-
prop.slice(0, -1),
|
|
84
|
-
segs[idx] || ''
|
|
85
|
-
], joinChar, options);
|
|
86
|
-
}
|
|
87
|
-
if (prop in target) {
|
|
88
|
-
if (!isValid(prop, target, options)) {
|
|
89
|
-
return options.default;
|
|
90
|
-
}
|
|
91
|
-
target = target[prop];
|
|
92
|
-
} else {
|
|
93
|
-
let hasProp = false;
|
|
94
|
-
let n = idx + 1;
|
|
95
|
-
while(n < len){
|
|
96
|
-
prop = join([
|
|
97
|
-
prop,
|
|
98
|
-
segs[n]
|
|
99
|
-
], joinChar, options);
|
|
100
|
-
n += 1;
|
|
101
|
-
hasProp = prop in target;
|
|
102
|
-
if (hasProp) {
|
|
103
|
-
if (!isValid(prop, target, options)) {
|
|
104
|
-
return options.default;
|
|
105
|
-
}
|
|
106
|
-
target = target[prop];
|
|
107
|
-
idx = n - 1;
|
|
108
|
-
break;
|
|
109
|
-
}
|
|
110
|
-
}
|
|
111
|
-
if (!hasProp) {
|
|
112
|
-
return options.default;
|
|
113
|
-
}
|
|
114
|
-
}
|
|
115
|
-
// eslint-disable-next-line no-plusplus
|
|
116
|
-
}while (++idx < len && isValidObject(target))
|
|
117
|
-
if (idx === len) {
|
|
118
|
-
return target;
|
|
119
|
-
}
|
|
120
|
-
return options.default;
|
|
121
|
-
}
|
|
122
|
-
function get(target, path, options) {
|
|
123
|
-
if (!typeTest.isObject(options)) {
|
|
124
|
-
options = {
|
|
125
|
-
default: options
|
|
126
|
-
};
|
|
127
|
-
}
|
|
128
|
-
if (options.copy) {
|
|
129
|
-
return serializer.copy(getter(target, path, options));
|
|
130
|
-
}
|
|
131
|
-
return getter(target, path, options);
|
|
132
|
-
}
|
|
133
|
-
export default get;
|
package/dist/index.js
DELETED
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
/*
|
|
2
|
-
Copyright 2020-2022 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 applyArrayIndices from './applyArrayIndices.js';
|
|
16
|
-
import cachedPromises from './cachedPromises.js';
|
|
17
|
-
import get from './get.js';
|
|
18
|
-
import mergeObjects from './mergeObjects.js';
|
|
19
|
-
import omit from './omit.js';
|
|
20
|
-
import serializer from './serializer.js';
|
|
21
|
-
import set from './set.js';
|
|
22
|
-
import stableStringify from './stableStringify.js';
|
|
23
|
-
import swap from './swap.js';
|
|
24
|
-
import type from './type.js';
|
|
25
|
-
import unset from './unset.js';
|
|
26
|
-
import urlQuery from './urlQuery.js';
|
|
27
|
-
import wait from './wait.js';
|
|
28
|
-
export { applyArrayIndices, cachedPromises, get, mergeObjects, omit, serializer, set, stableStringify, swap, type, unset, urlQuery, wait };
|
package/dist/mergeObjects.js
DELETED
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
/*
|
|
2
|
-
Copyright 2020-2022 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
|
-
*/ // TODO: do we want this lodash dep in helpers?
|
|
16
|
-
import merge from 'lodash.merge';
|
|
17
|
-
import type from './type.js';
|
|
18
|
-
const mergeObjects = (objects)=>{
|
|
19
|
-
let merged = objects;
|
|
20
|
-
if (type.isArray(objects)) {
|
|
21
|
-
merged = merge(...objects.filter((obj)=>type.isObject(obj)));
|
|
22
|
-
}
|
|
23
|
-
return merged;
|
|
24
|
-
};
|
|
25
|
-
export default mergeObjects;
|
package/dist/omit.js
DELETED
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
/*
|
|
2
|
-
Copyright 2020-2022 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 unset from './unset.js';
|
|
16
|
-
const omit = (obj, list)=>{
|
|
17
|
-
list.forEach((item)=>{
|
|
18
|
-
unset(obj, item);
|
|
19
|
-
});
|
|
20
|
-
return obj;
|
|
21
|
-
};
|
|
22
|
-
export default omit;
|
package/dist/serializer.js
DELETED
|
@@ -1,136 +0,0 @@
|
|
|
1
|
-
/* eslint-disable no-param-reassign */ /*
|
|
2
|
-
Copyright 2020-2022 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
|
-
if (isoStringDates) {
|
|
22
|
-
dateReplacer = (date)=>({
|
|
23
|
-
_date: date.toISOString()
|
|
24
|
-
});
|
|
25
|
-
}
|
|
26
|
-
let newValue = value;
|
|
27
|
-
if (customReplacer) {
|
|
28
|
-
newValue = customReplacer(key, value);
|
|
29
|
-
}
|
|
30
|
-
if (type.isError(newValue)) {
|
|
31
|
-
return {
|
|
32
|
-
_error: {
|
|
33
|
-
name: newValue.name,
|
|
34
|
-
message: newValue.message,
|
|
35
|
-
value: newValue.toString()
|
|
36
|
-
}
|
|
37
|
-
};
|
|
38
|
-
}
|
|
39
|
-
if (type.isObject(newValue)) {
|
|
40
|
-
Object.keys(newValue).forEach((k)=>{
|
|
41
|
-
if (type.isDate(newValue[k])) {
|
|
42
|
-
// shallow copy original value before reassigning a value in order not to mutate original value
|
|
43
|
-
newValue = {
|
|
44
|
-
...newValue
|
|
45
|
-
};
|
|
46
|
-
newValue[k] = dateReplacer(newValue[k]);
|
|
47
|
-
}
|
|
48
|
-
});
|
|
49
|
-
return newValue;
|
|
50
|
-
}
|
|
51
|
-
if (type.isArray(newValue)) {
|
|
52
|
-
return newValue.map((item)=>{
|
|
53
|
-
if (type.isDate(item)) {
|
|
54
|
-
return dateReplacer(item);
|
|
55
|
-
}
|
|
56
|
-
return item;
|
|
57
|
-
});
|
|
58
|
-
}
|
|
59
|
-
return newValue;
|
|
60
|
-
};
|
|
61
|
-
const makeReviver = (customReviver)=>(key, value)=>{
|
|
62
|
-
let newValue = value;
|
|
63
|
-
if (customReviver) {
|
|
64
|
-
newValue = customReviver(key, value);
|
|
65
|
-
}
|
|
66
|
-
if (type.isObject(newValue) && !type.isUndefined(newValue._error)) {
|
|
67
|
-
const error = new Error(newValue._error.message);
|
|
68
|
-
error.name = newValue._error.name;
|
|
69
|
-
return error;
|
|
70
|
-
}
|
|
71
|
-
if (type.isObject(newValue) && !type.isUndefined(newValue._date)) {
|
|
72
|
-
if (type.isInt(newValue._date)) {
|
|
73
|
-
return new Date(newValue._date);
|
|
74
|
-
}
|
|
75
|
-
if (newValue._date === 'now') {
|
|
76
|
-
return newValue;
|
|
77
|
-
}
|
|
78
|
-
const result = new Date(newValue._date);
|
|
79
|
-
if (!type.isDate(result)) {
|
|
80
|
-
return newValue;
|
|
81
|
-
}
|
|
82
|
-
return result;
|
|
83
|
-
}
|
|
84
|
-
return newValue;
|
|
85
|
-
};
|
|
86
|
-
const serialize = (json, options = {})=>{
|
|
87
|
-
if (type.isUndefined(json)) return json;
|
|
88
|
-
if (type.isDate(json)) {
|
|
89
|
-
if (options.isoStringDates) {
|
|
90
|
-
return {
|
|
91
|
-
_date: json.toISOString()
|
|
92
|
-
};
|
|
93
|
-
}
|
|
94
|
-
return {
|
|
95
|
-
_date: json.valueOf()
|
|
96
|
-
};
|
|
97
|
-
}
|
|
98
|
-
return JSON.parse(JSON.stringify(json, makeReplacer(options.replacer, options.isoStringDates)));
|
|
99
|
-
};
|
|
100
|
-
const serializeToString = (json, options = {})=>{
|
|
101
|
-
if (type.isUndefined(json)) return json;
|
|
102
|
-
if (type.isDate(json)) {
|
|
103
|
-
if (options.isoStringDates) {
|
|
104
|
-
return `{ "_date": "${json.toISOString()}" }`;
|
|
105
|
-
}
|
|
106
|
-
return `{ "_date": ${json.valueOf()} }`;
|
|
107
|
-
}
|
|
108
|
-
if (options.stable) {
|
|
109
|
-
return stableStringify(json, {
|
|
110
|
-
replacer: makeReplacer(options.replacer),
|
|
111
|
-
space: options.space
|
|
112
|
-
});
|
|
113
|
-
}
|
|
114
|
-
return JSON.stringify(json, makeReplacer(options.replacer, options.isoStringDates), options.space);
|
|
115
|
-
};
|
|
116
|
-
const deserialize = (json, options = {})=>{
|
|
117
|
-
if (type.isUndefined(json)) return json;
|
|
118
|
-
return JSON.parse(JSON.stringify(json), makeReviver(options.reviver));
|
|
119
|
-
};
|
|
120
|
-
const deserializeFromString = (str, options = {})=>{
|
|
121
|
-
if (type.isUndefined(str)) return str;
|
|
122
|
-
return JSON.parse(str, makeReviver(options.reviver));
|
|
123
|
-
};
|
|
124
|
-
const copy = (json, options = {})=>{
|
|
125
|
-
if (type.isUndefined(json)) return undefined;
|
|
126
|
-
if (type.isDate(json)) return new Date(json.valueOf());
|
|
127
|
-
return JSON.parse(JSON.stringify(json, makeReplacer(options.replacer)), makeReviver(options.reviver));
|
|
128
|
-
};
|
|
129
|
-
const serializer = {
|
|
130
|
-
copy,
|
|
131
|
-
serialize,
|
|
132
|
-
serializeToString,
|
|
133
|
-
deserialize,
|
|
134
|
-
deserializeFromString
|
|
135
|
-
};
|
|
136
|
-
export default serializer;
|
package/dist/set.js
DELETED
|
@@ -1,121 +0,0 @@
|
|
|
1
|
-
/* eslint-disable no-plusplus */ /* eslint-disable no-use-before-define */ /* eslint-disable no-param-reassign */ /*
|
|
2
|
-
Copyright 2020-2022 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
|
-
*/ // Derived from source:
|
|
16
|
-
// https://github.com/jonschlinkert/set-value/blob/master/index.js
|
|
17
|
-
// https://www.npmjs.com/package/set-value
|
|
18
|
-
// The MIT License (MIT)
|
|
19
|
-
// Copyright (c) 2014-2018, Jon Schlinkert.
|
|
20
|
-
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
21
|
-
// of this software and associated documentation files (the "Software"), to deal
|
|
22
|
-
// in the Software without restriction, including without limitation the rights
|
|
23
|
-
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
24
|
-
// copies of the Software, and to permit persons to whom the Software is
|
|
25
|
-
// furnished to do so, subject to the following conditions:
|
|
26
|
-
// The above copyright notice and this permission notice shall be included in
|
|
27
|
-
// all copies or substantial portions of the Software.
|
|
28
|
-
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
29
|
-
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
30
|
-
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
31
|
-
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
32
|
-
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
33
|
-
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
34
|
-
// THE SOFTWARE.
|
|
35
|
-
import type from './type.js';
|
|
36
|
-
function isValidKey(key) {
|
|
37
|
-
return key !== '__proto__' && key !== 'constructor' && key !== 'prototype';
|
|
38
|
-
}
|
|
39
|
-
function isObjectOrFunction(val) {
|
|
40
|
-
return val !== null && (typeof val === 'object' || typeof val === 'function');
|
|
41
|
-
}
|
|
42
|
-
function result(target, path, value, merge) {
|
|
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
|
|
50
|
-
set.memo = {};
|
|
51
|
-
function set(target, path, value, options) {
|
|
52
|
-
if (!type.isObject(target)) {
|
|
53
|
-
return target;
|
|
54
|
-
}
|
|
55
|
-
const opts = options || {};
|
|
56
|
-
if (!type.isArray(path) && !type.isString(path)) {
|
|
57
|
-
return target;
|
|
58
|
-
}
|
|
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;
|
|
87
|
-
}
|
|
88
|
-
function createKey(pattern, options) {
|
|
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;
|
|
99
|
-
}
|
|
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);
|
|
110
|
-
}
|
|
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;
|
|
120
|
-
}
|
|
121
|
-
export default set;
|
package/dist/stableStringify.js
DELETED
|
@@ -1,99 +0,0 @@
|
|
|
1
|
-
/* eslint-disable no-continue */ /* eslint-disable no-plusplus */ /* eslint-disable consistent-return */ /* eslint-disable no-param-reassign */ /*
|
|
2
|
-
Copyright 2020-2022 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
|
-
*/ // Derived from source:
|
|
16
|
-
// https://github.com/substack/json-stable-stringify
|
|
17
|
-
// https://github.com/substack/json-stable-stringify/LICENCE
|
|
18
|
-
// This software is released under the MIT license:
|
|
19
|
-
// Permission is hereby granted, free of charge, to any person obtaining a copy of
|
|
20
|
-
// this software and associated documentation files (the "Software"), to deal in
|
|
21
|
-
// the Software without restriction, including without limitation the rights to
|
|
22
|
-
// use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
|
|
23
|
-
// the Software, and to permit persons to whom the Software is furnished to do so,
|
|
24
|
-
// subject to the following conditions:
|
|
25
|
-
// The above copyright notice and this permission notice shall be included in all
|
|
26
|
-
// copies or substantial portions of the Software.
|
|
27
|
-
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
28
|
-
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
|
|
29
|
-
// FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
|
30
|
-
// COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
|
|
31
|
-
// IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
|
32
|
-
// CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
33
|
-
import type from './type.js';
|
|
34
|
-
function stableStringify(obj, opts) {
|
|
35
|
-
if (!opts) opts = {};
|
|
36
|
-
if (typeof opts === 'function') opts = {
|
|
37
|
-
cmp: opts
|
|
38
|
-
};
|
|
39
|
-
let space = opts.space || '';
|
|
40
|
-
if (typeof space === 'number') space = Array(space + 1).join(' ');
|
|
41
|
-
const cycles = typeof opts.cycles === 'boolean' ? opts.cycles : false;
|
|
42
|
-
const replacer = opts.replacer || ((key, value)=>value);
|
|
43
|
-
const cmp = opts.cmp && ((f)=>{
|
|
44
|
-
return (node)=>{
|
|
45
|
-
return (a, b)=>{
|
|
46
|
-
const aobj = {
|
|
47
|
-
key: a,
|
|
48
|
-
value: node[a]
|
|
49
|
-
};
|
|
50
|
-
const bobj = {
|
|
51
|
-
key: b,
|
|
52
|
-
value: node[b]
|
|
53
|
-
};
|
|
54
|
-
return f(aobj, bobj);
|
|
55
|
-
};
|
|
56
|
-
};
|
|
57
|
-
})(opts.cmp);
|
|
58
|
-
const seen = [];
|
|
59
|
-
return function stringify(parent, key, node, level) {
|
|
60
|
-
const indent = space ? `\n${new Array(level + 1).join(space)}` : '';
|
|
61
|
-
const colonSeparator = space ? ': ' : ':';
|
|
62
|
-
if (node && node.toJSON && typeof node.toJSON === 'function') {
|
|
63
|
-
node = node.toJSON();
|
|
64
|
-
}
|
|
65
|
-
node = replacer.call(parent, key, node);
|
|
66
|
-
if (node === undefined) {
|
|
67
|
-
return;
|
|
68
|
-
}
|
|
69
|
-
if (typeof node !== 'object' || node === null) {
|
|
70
|
-
return JSON.stringify(node);
|
|
71
|
-
}
|
|
72
|
-
if (type.isArray(node)) {
|
|
73
|
-
const out = [];
|
|
74
|
-
for(let i = 0; i < node.length; i++){
|
|
75
|
-
const item = stringify(node, i, node[i], level + 1) || JSON.stringify(null);
|
|
76
|
-
out.push(indent + space + item);
|
|
77
|
-
}
|
|
78
|
-
return `[${out.join(',')}${indent}]`;
|
|
79
|
-
}
|
|
80
|
-
if (seen.indexOf(node) !== -1) {
|
|
81
|
-
if (cycles) return JSON.stringify('__cycle__');
|
|
82
|
-
throw new TypeError('Converting circular structure to JSON');
|
|
83
|
-
} else seen.push(node);
|
|
84
|
-
const keys = Object.keys(node).sort(cmp && cmp(node));
|
|
85
|
-
const out = [];
|
|
86
|
-
for(let i = 0; i < keys.length; i++){
|
|
87
|
-
const ky = keys[i];
|
|
88
|
-
const value = stringify(node, ky, node[ky], level + 1);
|
|
89
|
-
if (!value) continue;
|
|
90
|
-
const keyValue = JSON.stringify(ky) + colonSeparator + value;
|
|
91
|
-
out.push(indent + space + keyValue);
|
|
92
|
-
}
|
|
93
|
-
seen.splice(seen.indexOf(node), 1);
|
|
94
|
-
return `{${out.join(',')}${indent}}`;
|
|
95
|
-
}({
|
|
96
|
-
'': obj
|
|
97
|
-
}, '', obj, 0);
|
|
98
|
-
}
|
|
99
|
-
export default stableStringify;
|
package/dist/swap.js
DELETED
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
/*
|
|
2
|
-
Copyright 2020-2022 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
|
-
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]);
|
|
21
|
-
};
|
|
22
|
-
export default swap;
|
package/dist/type.js
DELETED
|
@@ -1,200 +0,0 @@
|
|
|
1
|
-
/* eslint-disable indent */ /* eslint-disable default-case */ /*
|
|
2
|
-
Copyright 2020-2022 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
|
-
*/ // Derived from source:
|
|
16
|
-
// because both js typeof and instance of sucks! use this.
|
|
17
|
-
// https://ultimatecourses.com/blog/understanding-javascript-types-and-reliable-type-checking
|
|
18
|
-
const { toString } = Object.prototype;
|
|
19
|
-
function ctorName(val) {
|
|
20
|
-
return val.constructor ? val.constructor.name : null;
|
|
21
|
-
}
|
|
22
|
-
function isArray(val) {
|
|
23
|
-
if (Array.isArray) return Array.isArray(val);
|
|
24
|
-
return val instanceof Array;
|
|
25
|
-
}
|
|
26
|
-
function isError(val) {
|
|
27
|
-
return !!val && (val instanceof Error || typeof val.message === 'string' && val.constructor && typeof val.constructor.stackTraceLimit === 'number');
|
|
28
|
-
}
|
|
29
|
-
function isDate(val) {
|
|
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());
|
|
32
|
-
}
|
|
33
|
-
function isRegexp(val) {
|
|
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';
|
|
36
|
-
}
|
|
37
|
-
function isGeneratorFn(name) {
|
|
38
|
-
return ctorName(name) === 'GeneratorFunction';
|
|
39
|
-
}
|
|
40
|
-
function isGeneratorObj(val) {
|
|
41
|
-
return typeof val.throw === 'function' && typeof val.return === 'function' && typeof val.next === 'function';
|
|
42
|
-
}
|
|
43
|
-
function isArguments(val) {
|
|
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
|
-
}
|
|
52
|
-
}
|
|
53
|
-
return false;
|
|
54
|
-
}
|
|
55
|
-
/**
|
|
56
|
-
* If you need to support Safari 5-7 (8-10 yr-old browser),
|
|
57
|
-
* take a look at https://github.com/feross/is-buffer
|
|
58
|
-
*/ function isBuffer(val) {
|
|
59
|
-
if (val.constructor && typeof val.constructor.isBuffer === 'function') {
|
|
60
|
-
return val.constructor.isBuffer(val);
|
|
61
|
-
}
|
|
62
|
-
return false;
|
|
63
|
-
}
|
|
64
|
-
function kindOf(val) {
|
|
65
|
-
// eslint-disable-next-line no-void
|
|
66
|
-
if (val === void 0) return 'undefined';
|
|
67
|
-
if (val === null) return 'null';
|
|
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
|
-
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
|
-
type1 = toString.call(val);
|
|
123
|
-
switch(type1){
|
|
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 type1.slice(8, -1).toLowerCase().replace(/\s/g, '');
|
|
138
|
-
}
|
|
139
|
-
const reISO = /^(\d{4})-(\d{2})-(\d{2})T(\d{2}):(\d{2}):(\d{2}(?:\.\d*))(?:Z|(\+|-)([\d|:]*))?$/;
|
|
140
|
-
function isDateString(val) {
|
|
141
|
-
return reISO.test(val);
|
|
142
|
-
}
|
|
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';
|
|
150
|
-
type.isString = (value)=>typeof value === 'string';
|
|
151
|
-
type.isRegExp = (value)=>kindOf(value) === 'regexp';
|
|
152
|
-
type.isFunction = (value)=>kindOf(value) === 'function';
|
|
153
|
-
type.isBoolean = (value)=>typeof value === 'boolean';
|
|
154
|
-
type.isNumber = (value)=>typeof value === 'number' && Number.isFinite(value);
|
|
155
|
-
type.isNumeric = (value)=>!Number.isNaN(Number(value));
|
|
156
|
-
type.isInt = (value)=>Number.isInteger(value) === true;
|
|
157
|
-
type.isSet = (value)=>kindOf(value) === 'set';
|
|
158
|
-
type.isNull = (value)=>kindOf(value) === 'null';
|
|
159
|
-
type.isUndefined = (value)=>kindOf(value) === 'undefined';
|
|
160
|
-
type.isNone = (value)=>kindOf(value) === 'undefined' || kindOf(value) === 'null';
|
|
161
|
-
type.isPrimitive = (value)=>kindOf(value) === 'undefined' || kindOf(value) === 'null' || kindOf(value) === 'string' || kindOf(value) === 'number' || kindOf(value) === 'boolean' || kindOf(value) === 'date';
|
|
162
|
-
type.isEmptyObject = (value)=>kindOf(value) === 'object' && Object.keys(value).length === 0;
|
|
163
|
-
// Lowdefy operator types
|
|
164
|
-
function isName(value) {
|
|
165
|
-
if (!type.isString(value)) return false;
|
|
166
|
-
const noLeadingNumeric = value.split('.').reduce((acc, val)=>acc && !type.isNumeric(val.charAt(0)), true);
|
|
167
|
-
const noLeadTrailStop = value.charAt(0) !== '.' && value.charAt(value.length - 1) !== '.';
|
|
168
|
-
const noLowdefy = !value.toLowerCase().startsWith('lowdefy');
|
|
169
|
-
return /^[a-zA-Z0-9_.]+$/g.test(value) && noLeadTrailStop && noLeadingNumeric && noLowdefy;
|
|
170
|
-
}
|
|
171
|
-
function isOpRequest(val) {
|
|
172
|
-
return kindOf(val) === 'object' && '_request' in val && isName(val._request);
|
|
173
|
-
}
|
|
174
|
-
// Lowdefy
|
|
175
|
-
type.isOpRequest = isOpRequest;
|
|
176
|
-
type.isName = isName;
|
|
177
|
-
function enforceType(typeName, value) {
|
|
178
|
-
switch(typeName){
|
|
179
|
-
case 'string':
|
|
180
|
-
return type.isString(value) && value !== '' ? value : null;
|
|
181
|
-
case 'number':
|
|
182
|
-
return type.isNumber(value) ? value : null;
|
|
183
|
-
case 'boolean':
|
|
184
|
-
return type.isBoolean(value) ? value : false;
|
|
185
|
-
case 'date':
|
|
186
|
-
return type.isDate(value) ? value : null;
|
|
187
|
-
case 'array':
|
|
188
|
-
return type.isArray(value) ? value : [];
|
|
189
|
-
case 'primitive':
|
|
190
|
-
return type.isString(value) && value !== '' || type.isNumber(value) || type.isDate(value) || type.isBoolean(value) ? value : null;
|
|
191
|
-
case 'object':
|
|
192
|
-
return type.isObject(value) ? value : null;
|
|
193
|
-
case 'any':
|
|
194
|
-
return !type.isUndefined(value) ? value : null;
|
|
195
|
-
default:
|
|
196
|
-
return null;
|
|
197
|
-
}
|
|
198
|
-
}
|
|
199
|
-
type.enforceType = enforceType;
|
|
200
|
-
export default type;
|
package/dist/unset.js
DELETED
|
@@ -1,104 +0,0 @@
|
|
|
1
|
-
/* eslint-disable no-param-reassign */ /*
|
|
2
|
-
Copyright 2020-2022 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
|
-
*/ // Derived from source:
|
|
16
|
-
// https://github.com/jonschlinkert/unset-value/blob/master/index.js
|
|
17
|
-
// https://github.com/jonschlinkert/unset-value/issues/3
|
|
18
|
-
// The MIT License (MIT)
|
|
19
|
-
// Copyright (c) 2015, 2017, Jon Schlinkert
|
|
20
|
-
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
21
|
-
// of this software and associated documentation files (the "Software"), to deal
|
|
22
|
-
// in the Software without restriction, including without limitation the rights
|
|
23
|
-
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
24
|
-
// copies of the Software, and to permit persons to whom the Software is
|
|
25
|
-
// furnished to do so, subject to the following conditions:
|
|
26
|
-
// The above copyright notice and this permission notice shall be included in
|
|
27
|
-
// all copies or substantial portions of the Software.
|
|
28
|
-
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
29
|
-
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
30
|
-
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
31
|
-
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
32
|
-
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
33
|
-
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
34
|
-
// THE SOFTWARE.
|
|
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
|
-
}
|
|
77
|
-
};
|
|
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;
|
|
83
|
-
};
|
|
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.');
|
|
88
|
-
}
|
|
89
|
-
if (Object.prototype.hasOwnProperty.call(obj, prop)) {
|
|
90
|
-
delete obj[prop];
|
|
91
|
-
return true;
|
|
92
|
-
}
|
|
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;
|
|
103
|
-
};
|
|
104
|
-
export default unset;
|
package/dist/urlQuery.js
DELETED
|
@@ -1,44 +0,0 @@
|
|
|
1
|
-
/*
|
|
2
|
-
Copyright 2020-2022 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
|
-
*/ // TODO: do we want this query-string dep in helpers?
|
|
16
|
-
import queryString from 'query-string';
|
|
17
|
-
import serializer from './serializer.js';
|
|
18
|
-
import type from './type.js';
|
|
19
|
-
const parse = (str)=>{
|
|
20
|
-
const parsed = queryString.parse(str);
|
|
21
|
-
const deserialized = {};
|
|
22
|
-
Object.keys(parsed).forEach((key)=>{
|
|
23
|
-
try {
|
|
24
|
-
deserialized[key] = serializer.deserializeFromString(parsed[key]);
|
|
25
|
-
} catch (error) {
|
|
26
|
-
deserialized[key] = parsed[key];
|
|
27
|
-
}
|
|
28
|
-
});
|
|
29
|
-
return deserialized;
|
|
30
|
-
};
|
|
31
|
-
const stringify = (object)=>{
|
|
32
|
-
if (!type.isObject(object)) {
|
|
33
|
-
return '';
|
|
34
|
-
}
|
|
35
|
-
const toSerialize = {};
|
|
36
|
-
Object.keys(object).forEach((key)=>{
|
|
37
|
-
toSerialize[key] = serializer.serializeToString(object[key]);
|
|
38
|
-
});
|
|
39
|
-
return queryString.stringify(toSerialize);
|
|
40
|
-
};
|
|
41
|
-
export default {
|
|
42
|
-
stringify,
|
|
43
|
-
parse
|
|
44
|
-
};
|
package/dist/wait.js
DELETED
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
/*
|
|
2
|
-
Copyright 2020-2022 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
|
-
export default wait;
|