@lowdefy/helpers 0.0.0-experimental-20231123101256
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/LICENSE +201 -0
- package/README.md +181 -0
- package/dist/LRUCache.js +46 -0
- package/dist/applyArrayIndices.js +30 -0
- package/dist/cachedPromises.js +27 -0
- package/dist/get.js +133 -0
- package/dist/index.js +29 -0
- package/dist/mergeObjects.js +25 -0
- package/dist/omit.js +22 -0
- package/dist/serializer.js +166 -0
- package/dist/set.js +121 -0
- package/dist/stableStringify.js +99 -0
- package/dist/swap.js +22 -0
- package/dist/type.js +201 -0
- package/dist/unset.js +104 -0
- package/dist/urlQuery.js +42 -0
- package/dist/wait.js +18 -0
- package/package.json +52 -0
package/dist/unset.js
ADDED
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
/* eslint-disable no-param-reassign */ /*
|
|
2
|
+
Copyright 2020-2023 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
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
/*
|
|
2
|
+
Copyright 2020-2023 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 serializer from './serializer.js';
|
|
16
|
+
import type from './type.js';
|
|
17
|
+
const parse = (str)=>{
|
|
18
|
+
const parsed = new URLSearchParams(str);
|
|
19
|
+
const deserialized = {};
|
|
20
|
+
parsed.forEach((value, key)=>{
|
|
21
|
+
try {
|
|
22
|
+
deserialized[key] = serializer.deserializeFromString(value);
|
|
23
|
+
} catch (error) {
|
|
24
|
+
deserialized[key] = value;
|
|
25
|
+
}
|
|
26
|
+
});
|
|
27
|
+
return deserialized;
|
|
28
|
+
};
|
|
29
|
+
const stringify = (object)=>{
|
|
30
|
+
if (!type.isObject(object)) {
|
|
31
|
+
return '';
|
|
32
|
+
}
|
|
33
|
+
const toSerialize = {};
|
|
34
|
+
Object.keys(object).forEach((key)=>{
|
|
35
|
+
toSerialize[key] = type.isString(object[key]) ? object[key] : serializer.serializeToString(object[key]);
|
|
36
|
+
});
|
|
37
|
+
return new URLSearchParams(toSerialize).toString();
|
|
38
|
+
};
|
|
39
|
+
export default {
|
|
40
|
+
stringify,
|
|
41
|
+
parse
|
|
42
|
+
};
|
package/dist/wait.js
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/*
|
|
2
|
+
Copyright 2020-2023 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 wait(ms) {
|
|
16
|
+
return new Promise((resolve)=>setTimeout(resolve, ms));
|
|
17
|
+
}
|
|
18
|
+
export default wait;
|
package/package.json
ADDED
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@lowdefy/helpers",
|
|
3
|
+
"version": "0.0.0-experimental-20231123101256",
|
|
4
|
+
"license": "Apache-2.0",
|
|
5
|
+
"description": "",
|
|
6
|
+
"homepage": "https://lowdefy.com",
|
|
7
|
+
"keywords": [
|
|
8
|
+
"lowdefy",
|
|
9
|
+
"utils"
|
|
10
|
+
],
|
|
11
|
+
"bugs": {
|
|
12
|
+
"url": "https://github.com/lowdefy/lowdefy/issues"
|
|
13
|
+
},
|
|
14
|
+
"contributors": [
|
|
15
|
+
{
|
|
16
|
+
"name": "Sam Tolmay",
|
|
17
|
+
"url": "https://github.com/SamTolmay"
|
|
18
|
+
},
|
|
19
|
+
{
|
|
20
|
+
"name": "Gerrie van Wyk",
|
|
21
|
+
"url": "https://github.com/Gervwyk"
|
|
22
|
+
}
|
|
23
|
+
],
|
|
24
|
+
"repository": {
|
|
25
|
+
"type": "git",
|
|
26
|
+
"url": "https://github.com/lowdefy/lowdefy.git"
|
|
27
|
+
},
|
|
28
|
+
"type": "module",
|
|
29
|
+
"exports": "./dist/index.js",
|
|
30
|
+
"files": [
|
|
31
|
+
"dist/*"
|
|
32
|
+
],
|
|
33
|
+
"dependencies": {
|
|
34
|
+
"lodash.merge": "4.6.2"
|
|
35
|
+
},
|
|
36
|
+
"devDependencies": {
|
|
37
|
+
"@jest/globals": "28.1.3",
|
|
38
|
+
"@swc/cli": "0.1.63",
|
|
39
|
+
"@swc/core": "1.3.99",
|
|
40
|
+
"@swc/jest": "0.2.29",
|
|
41
|
+
"jest": "28.1.3",
|
|
42
|
+
"jest-diff": "28.1.3"
|
|
43
|
+
},
|
|
44
|
+
"publishConfig": {
|
|
45
|
+
"access": "public"
|
|
46
|
+
},
|
|
47
|
+
"scripts": {
|
|
48
|
+
"build": "swc src --out-dir dist --config-file ../../../.swcrc --delete-dir-on-start",
|
|
49
|
+
"clean": "rm -rf dist",
|
|
50
|
+
"test": "node --experimental-vm-modules node_modules/jest/bin/jest.js"
|
|
51
|
+
}
|
|
52
|
+
}
|