@lowdefy/helpers 4.0.0-rc.8 → 4.0.0
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/LRUCache.js +2 -2
- package/dist/applyArrayIndices.js +1 -1
- package/dist/cachedPromises.js +2 -2
- package/dist/get.js +1 -1
- package/dist/index.js +1 -1
- package/dist/mergeObjects.js +1 -1
- package/dist/omit.js +1 -1
- package/dist/serializer.js +25 -31
- package/dist/set.js +2 -2
- package/dist/stableStringify.js +8 -8
- package/dist/swap.js +1 -1
- package/dist/type.js +2 -2
- package/dist/unset.js +1 -1
- package/dist/urlQuery.js +8 -10
- package/dist/wait.js +2 -2
- package/package.json +14 -17
package/dist/LRUCache.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/*
|
|
2
|
-
Copyright 2020-
|
|
2
|
+
Copyright 2020-2024 Lowdefy, Inc
|
|
3
3
|
|
|
4
4
|
Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
5
|
you may not use this file except in compliance with the License.
|
|
@@ -38,7 +38,7 @@ let LRUCache = class LRUCache {
|
|
|
38
38
|
first() {
|
|
39
39
|
return this.cache.keys().next().value;
|
|
40
40
|
}
|
|
41
|
-
constructor({ maxSize =100
|
|
41
|
+
constructor({ maxSize = 100 } = {}){
|
|
42
42
|
this.maxSize = maxSize;
|
|
43
43
|
this.cache = new Map();
|
|
44
44
|
}
|
package/dist/cachedPromises.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/*
|
|
2
|
-
Copyright 2020-
|
|
2
|
+
Copyright 2020-2024 Lowdefy, Inc
|
|
3
3
|
|
|
4
4
|
Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
5
|
you may not use this file except in compliance with the License.
|
|
@@ -12,7 +12,7 @@
|
|
|
12
12
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
13
|
See the License for the specific language governing permissions and
|
|
14
14
|
limitations under the License.
|
|
15
|
-
*/ function createCachedPromises({ getter
|
|
15
|
+
*/ function createCachedPromises({ getter, cache }) {
|
|
16
16
|
function cachedPromises(key) {
|
|
17
17
|
const cached = cache.get(key);
|
|
18
18
|
if (cached) {
|
package/dist/get.js
CHANGED
package/dist/index.js
CHANGED
package/dist/mergeObjects.js
CHANGED
package/dist/omit.js
CHANGED
package/dist/serializer.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/* eslint-disable no-param-reassign */ /*
|
|
2
|
-
Copyright 2020-
|
|
2
|
+
Copyright 2020-2024 Lowdefy, Inc
|
|
3
3
|
|
|
4
4
|
Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
5
|
you may not use this file except in compliance with the License.
|
|
@@ -16,11 +16,11 @@
|
|
|
16
16
|
import stableStringify from './stableStringify.js';
|
|
17
17
|
const makeReplacer = (customReplacer, isoStringDates)=>(key, value)=>{
|
|
18
18
|
let dateReplacer = (date)=>({
|
|
19
|
-
|
|
19
|
+
'~d': date.valueOf()
|
|
20
20
|
});
|
|
21
21
|
if (isoStringDates) {
|
|
22
22
|
dateReplacer = (date)=>({
|
|
23
|
-
|
|
23
|
+
'~d': date.toISOString()
|
|
24
24
|
});
|
|
25
25
|
}
|
|
26
26
|
let newValue = value;
|
|
@@ -29,7 +29,7 @@ const makeReplacer = (customReplacer, isoStringDates)=>(key, value)=>{
|
|
|
29
29
|
}
|
|
30
30
|
if (type.isError(newValue)) {
|
|
31
31
|
return {
|
|
32
|
-
|
|
32
|
+
'~e': {
|
|
33
33
|
name: newValue.name,
|
|
34
34
|
message: newValue.message,
|
|
35
35
|
value: newValue.toString()
|
|
@@ -46,17 +46,17 @@ const makeReplacer = (customReplacer, isoStringDates)=>(key, value)=>{
|
|
|
46
46
|
newValue[k] = dateReplacer(newValue[k]);
|
|
47
47
|
}
|
|
48
48
|
});
|
|
49
|
-
if (newValue
|
|
50
|
-
Object.defineProperty(newValue, '
|
|
51
|
-
value: newValue
|
|
49
|
+
if (newValue['~r']) {
|
|
50
|
+
Object.defineProperty(newValue, '~r', {
|
|
51
|
+
value: newValue['~r'],
|
|
52
52
|
enumerable: true,
|
|
53
53
|
writable: true,
|
|
54
54
|
configurable: true
|
|
55
55
|
});
|
|
56
56
|
}
|
|
57
|
-
if (newValue
|
|
58
|
-
Object.defineProperty(newValue, '
|
|
59
|
-
value: newValue
|
|
57
|
+
if (newValue['~k']) {
|
|
58
|
+
Object.defineProperty(newValue, '~k', {
|
|
59
|
+
value: newValue['~k'],
|
|
60
60
|
enumerable: true,
|
|
61
61
|
writable: true,
|
|
62
62
|
configurable: true
|
|
@@ -77,17 +77,17 @@ const makeReplacer = (customReplacer, isoStringDates)=>(key, value)=>{
|
|
|
77
77
|
const makeReviver = (customReviver)=>(key, value)=>{
|
|
78
78
|
let newValue = value;
|
|
79
79
|
if (type.isObject(newValue)) {
|
|
80
|
-
if (newValue
|
|
81
|
-
Object.defineProperty(newValue, '
|
|
82
|
-
value: newValue
|
|
80
|
+
if (newValue['~r']) {
|
|
81
|
+
Object.defineProperty(newValue, '~r', {
|
|
82
|
+
value: newValue['~r'],
|
|
83
83
|
enumerable: false,
|
|
84
84
|
writable: true,
|
|
85
85
|
configurable: true
|
|
86
86
|
});
|
|
87
87
|
}
|
|
88
|
-
if (newValue
|
|
89
|
-
Object.defineProperty(newValue, '
|
|
90
|
-
value: newValue
|
|
88
|
+
if (newValue['~k']) {
|
|
89
|
+
Object.defineProperty(newValue, '~k', {
|
|
90
|
+
value: newValue['~k'],
|
|
91
91
|
enumerable: false,
|
|
92
92
|
writable: true,
|
|
93
93
|
configurable: true
|
|
@@ -98,19 +98,13 @@ const makeReviver = (customReviver)=>(key, value)=>{
|
|
|
98
98
|
newValue = customReviver(key, value);
|
|
99
99
|
}
|
|
100
100
|
if (type.isObject(newValue)) {
|
|
101
|
-
if (!type.isUndefined(newValue
|
|
102
|
-
const error = new Error(newValue.
|
|
103
|
-
error.name = newValue.
|
|
101
|
+
if (!type.isUndefined(newValue['~e'])) {
|
|
102
|
+
const error = new Error(newValue['~e'].message);
|
|
103
|
+
error.name = newValue['~e'].name;
|
|
104
104
|
return error;
|
|
105
105
|
}
|
|
106
|
-
if (!type.isUndefined(newValue
|
|
107
|
-
|
|
108
|
-
return new Date(newValue._date);
|
|
109
|
-
}
|
|
110
|
-
if (newValue._date === 'now') {
|
|
111
|
-
return newValue;
|
|
112
|
-
}
|
|
113
|
-
const result = new Date(newValue._date);
|
|
106
|
+
if (!type.isUndefined(newValue['~d'])) {
|
|
107
|
+
const result = new Date(newValue['~d']);
|
|
114
108
|
if (!type.isDate(result)) {
|
|
115
109
|
return newValue;
|
|
116
110
|
}
|
|
@@ -124,11 +118,11 @@ const serialize = (json, options = {})=>{
|
|
|
124
118
|
if (type.isDate(json)) {
|
|
125
119
|
if (options.isoStringDates) {
|
|
126
120
|
return {
|
|
127
|
-
|
|
121
|
+
'~d': json.toISOString()
|
|
128
122
|
};
|
|
129
123
|
}
|
|
130
124
|
return {
|
|
131
|
-
|
|
125
|
+
'~d': json.valueOf()
|
|
132
126
|
};
|
|
133
127
|
}
|
|
134
128
|
return JSON.parse(JSON.stringify(json, makeReplacer(options.replacer, options.isoStringDates)));
|
|
@@ -137,9 +131,9 @@ const serializeToString = (json, options = {})=>{
|
|
|
137
131
|
if (type.isUndefined(json)) return json;
|
|
138
132
|
if (type.isDate(json)) {
|
|
139
133
|
if (options.isoStringDates) {
|
|
140
|
-
return `{ "
|
|
134
|
+
return `{ "~d": "${json.toISOString()}" }`;
|
|
141
135
|
}
|
|
142
|
-
return `{ "
|
|
136
|
+
return `{ "~d": ${json.valueOf()} }`;
|
|
143
137
|
}
|
|
144
138
|
if (options.stable) {
|
|
145
139
|
return stableStringify(json, {
|
package/dist/set.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/* eslint-disable no-plusplus */ /* eslint-disable no-use-before-define */ /* eslint-disable no-param-reassign */ /*
|
|
2
|
-
Copyright 2020-
|
|
2
|
+
Copyright 2020-2024 Lowdefy, Inc
|
|
3
3
|
|
|
4
4
|
Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
5
|
you may not use this file except in compliance with the License.
|
|
@@ -56,7 +56,7 @@ function set(target, path, value, options) {
|
|
|
56
56
|
if (!type.isArray(path) && !type.isString(path)) {
|
|
57
57
|
return target;
|
|
58
58
|
}
|
|
59
|
-
let { merge
|
|
59
|
+
let { merge } = opts;
|
|
60
60
|
if (merge && typeof merge !== 'function') {
|
|
61
61
|
merge = Object.assign;
|
|
62
62
|
}
|
package/dist/stableStringify.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/* eslint-disable no-continue */ /* eslint-disable no-plusplus */ /* eslint-disable consistent-return */ /* eslint-disable no-param-reassign */ /*
|
|
2
|
-
Copyright 2020-
|
|
2
|
+
Copyright 2020-2024 Lowdefy, Inc
|
|
3
3
|
|
|
4
4
|
Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
5
|
you may not use this file except in compliance with the License.
|
|
@@ -59,7 +59,7 @@ function stableStringify(obj, opts) {
|
|
|
59
59
|
return function stringify(parent, key, node, level) {
|
|
60
60
|
const indent = space ? `\n${new Array(level + 1).join(space)}` : '';
|
|
61
61
|
const colonSeparator = space ? ': ' : ':';
|
|
62
|
-
if (node
|
|
62
|
+
if (node?.toJSON && typeof node.toJSON === 'function') {
|
|
63
63
|
node = node.toJSON();
|
|
64
64
|
}
|
|
65
65
|
node = replacer.call(parent, key, node);
|
|
@@ -81,17 +81,17 @@ function stableStringify(obj, opts) {
|
|
|
81
81
|
if (cycles) return JSON.stringify('__cycle__');
|
|
82
82
|
throw new TypeError('Converting circular structure to JSON');
|
|
83
83
|
} else seen.push(node);
|
|
84
|
-
const keys = Object.keys(node).sort(cmp
|
|
85
|
-
const
|
|
86
|
-
for(let
|
|
87
|
-
const ky = keys[
|
|
84
|
+
const keys = Object.keys(node).sort(cmp?.(node));
|
|
85
|
+
const out = [];
|
|
86
|
+
for(let i = 0; i < keys.length; i++){
|
|
87
|
+
const ky = keys[i];
|
|
88
88
|
const value = stringify(node, ky, node[ky], level + 1);
|
|
89
89
|
if (!value) continue;
|
|
90
90
|
const keyValue = JSON.stringify(ky) + colonSeparator + value;
|
|
91
|
-
|
|
91
|
+
out.push(indent + space + keyValue);
|
|
92
92
|
}
|
|
93
93
|
seen.splice(seen.indexOf(node), 1);
|
|
94
|
-
return `{${
|
|
94
|
+
return `{${out.join(',')}${indent}}`;
|
|
95
95
|
}({
|
|
96
96
|
'': obj
|
|
97
97
|
}, '', obj, 0);
|
package/dist/swap.js
CHANGED
package/dist/type.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/* eslint-disable indent */ /* eslint-disable default-case */ /*
|
|
2
|
-
Copyright 2020-
|
|
2
|
+
Copyright 2020-2024 Lowdefy, Inc
|
|
3
3
|
|
|
4
4
|
Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
5
|
you may not use this file except in compliance with the License.
|
|
@@ -15,7 +15,7 @@
|
|
|
15
15
|
*/ // Derived from source:
|
|
16
16
|
// because both js typeof and instance of sucks! use this.
|
|
17
17
|
// https://ultimatecourses.com/blog/understanding-javascript-types-and-reliable-type-checking
|
|
18
|
-
const { toString
|
|
18
|
+
const { toString } = Object.prototype;
|
|
19
19
|
function ctorName(val) {
|
|
20
20
|
return val.constructor ? val.constructor.name : null;
|
|
21
21
|
}
|
package/dist/unset.js
CHANGED
package/dist/urlQuery.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/*
|
|
2
|
-
Copyright 2020-
|
|
2
|
+
Copyright 2020-2024 Lowdefy, Inc
|
|
3
3
|
|
|
4
4
|
Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
5
|
you may not use this file except in compliance with the License.
|
|
@@ -12,18 +12,16 @@
|
|
|
12
12
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
13
|
See the License for the specific language governing permissions and
|
|
14
14
|
limitations under the License.
|
|
15
|
-
*/
|
|
16
|
-
import queryString from 'query-string';
|
|
17
|
-
import serializer from './serializer.js';
|
|
15
|
+
*/ import serializer from './serializer.js';
|
|
18
16
|
import type from './type.js';
|
|
19
17
|
const parse = (str)=>{
|
|
20
|
-
const parsed =
|
|
18
|
+
const parsed = new URLSearchParams(str);
|
|
21
19
|
const deserialized = {};
|
|
22
|
-
|
|
20
|
+
parsed.forEach((value, key)=>{
|
|
23
21
|
try {
|
|
24
|
-
deserialized[key] = serializer.deserializeFromString(
|
|
22
|
+
deserialized[key] = serializer.deserializeFromString(value);
|
|
25
23
|
} catch (error) {
|
|
26
|
-
deserialized[key] =
|
|
24
|
+
deserialized[key] = value;
|
|
27
25
|
}
|
|
28
26
|
});
|
|
29
27
|
return deserialized;
|
|
@@ -34,9 +32,9 @@ const stringify = (object)=>{
|
|
|
34
32
|
}
|
|
35
33
|
const toSerialize = {};
|
|
36
34
|
Object.keys(object).forEach((key)=>{
|
|
37
|
-
toSerialize[key] = serializer.serializeToString(object[key]);
|
|
35
|
+
toSerialize[key] = type.isString(object[key]) ? object[key] : serializer.serializeToString(object[key]);
|
|
38
36
|
});
|
|
39
|
-
return
|
|
37
|
+
return new URLSearchParams(toSerialize).toString();
|
|
40
38
|
};
|
|
41
39
|
export default {
|
|
42
40
|
stringify,
|
package/dist/wait.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/*
|
|
2
|
-
Copyright 2020-
|
|
2
|
+
Copyright 2020-2024 Lowdefy, Inc
|
|
3
3
|
|
|
4
4
|
Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
5
|
you may not use this file except in compliance with the License.
|
|
@@ -12,7 +12,7 @@
|
|
|
12
12
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
13
|
See the License for the specific language governing permissions and
|
|
14
14
|
limitations under the License.
|
|
15
|
-
*/
|
|
15
|
+
*/ function wait(ms) {
|
|
16
16
|
return new Promise((resolve)=>setTimeout(resolve, ms));
|
|
17
17
|
}
|
|
18
18
|
export default wait;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lowdefy/helpers",
|
|
3
|
-
"version": "4.0.0
|
|
3
|
+
"version": "4.0.0",
|
|
4
4
|
"license": "Apache-2.0",
|
|
5
5
|
"description": "",
|
|
6
6
|
"homepage": "https://lowdefy.com",
|
|
@@ -30,26 +30,23 @@
|
|
|
30
30
|
"files": [
|
|
31
31
|
"dist/*"
|
|
32
32
|
],
|
|
33
|
-
"scripts": {
|
|
34
|
-
"build": "swc src --out-dir dist --config-file ../../../.swcrc --delete-dir-on-start",
|
|
35
|
-
"clean": "rm -rf dist",
|
|
36
|
-
"prepublishOnly": "pnpm build",
|
|
37
|
-
"test": "node --experimental-vm-modules node_modules/jest/bin/jest.js"
|
|
38
|
-
},
|
|
39
33
|
"dependencies": {
|
|
40
|
-
"lodash.merge": "4.6.2"
|
|
41
|
-
"query-string": "8.1.0"
|
|
34
|
+
"lodash.merge": "4.6.2"
|
|
42
35
|
},
|
|
43
36
|
"devDependencies": {
|
|
44
|
-
"@jest/globals": "28.1.
|
|
45
|
-
"@swc/cli": "0.1.
|
|
46
|
-
"@swc/core": "1.3.
|
|
47
|
-
"@swc/jest": "0.2.
|
|
48
|
-
"jest": "28.1.
|
|
49
|
-
"jest-diff": "28.1.
|
|
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"
|
|
50
43
|
},
|
|
51
44
|
"publishConfig": {
|
|
52
45
|
"access": "public"
|
|
53
46
|
},
|
|
54
|
-
"
|
|
55
|
-
|
|
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
|
+
}
|