@lowdefy/helpers 3.23.2 → 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.
@@ -1,23 +1,4 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.default = void 0;
7
-
8
- var _type = _interopRequireDefault(require("./type"));
9
-
10
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
11
-
12
- /* eslint-disable no-continue */
13
-
14
- /* eslint-disable no-plusplus */
15
-
16
- /* eslint-disable consistent-return */
17
-
18
- /* eslint-disable no-param-reassign */
19
-
20
- /*
1
+ /* eslint-disable no-continue */ /* eslint-disable no-plusplus */ /* eslint-disable consistent-return */ /* eslint-disable no-param-reassign */ /*
21
2
  Copyright 2020-2021 Lowdefy, Inc
22
3
 
23
4
  Licensed under the Apache License, Version 2.0 (the "License");
@@ -31,8 +12,7 @@ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { de
31
12
  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
32
13
  See the License for the specific language governing permissions and
33
14
  limitations under the License.
34
- */
35
- // Derived from source:
15
+ */ // Derived from source:
36
16
  // https://github.com/substack/json-stable-stringify
37
17
  // https://github.com/substack/json-stable-stringify/LICENCE
38
18
  // This software is released under the MIT license:
@@ -50,86 +30,71 @@ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { de
50
30
  // COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
51
31
  // IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
52
32
  // CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
33
+ import type from './type.js';
53
34
  function stableStringify(obj, opts) {
54
- if (!opts) opts = {};
55
- if (typeof opts === 'function') opts = {
56
- cmp: opts
57
- };
58
- var space = opts.space || '';
59
- if (typeof space === 'number') space = Array(space + 1).join(' ');
60
- var cycles = typeof opts.cycles === 'boolean' ? opts.cycles : false;
61
-
62
- var replacer = opts.replacer || ((key, value) => value);
63
-
64
- var cmp = opts.cmp && (f => {
65
- return node => {
66
- return (a, b) => {
67
- var aobj = {
68
- key: a,
69
- value: node[a]
70
- };
71
- var bobj = {
72
- key: b,
73
- value: node[b]
74
- };
75
- return f(aobj, bobj);
76
- };
35
+ if (!opts) opts = {};
36
+ if (typeof opts === 'function') opts = {
37
+ cmp: opts
77
38
  };
78
- })(opts.cmp);
79
-
80
- var seen = [];
81
- return function stringify(parent, key, node, level) {
82
- var indent = space ? "\n".concat(new Array(level + 1).join(space)) : '';
83
- var colonSeparator = space ? ': ' : ':';
84
-
85
- if (node && node.toJSON && typeof node.toJSON === 'function') {
86
- node = node.toJSON();
87
- }
88
-
89
- node = replacer.call(parent, key, node);
90
-
91
- if (node === undefined) {
92
- return;
93
- }
94
-
95
- if (typeof node !== 'object' || node === null) {
96
- return JSON.stringify(node);
97
- }
98
-
99
- if (_type.default.isArray(node)) {
100
- var _out = [];
101
-
102
- for (var i = 0; i < node.length; i++) {
103
- var item = stringify(node, i, node[i], level + 1) || JSON.stringify(null);
104
-
105
- _out.push(indent + space + item);
106
- }
107
-
108
- return "[".concat(_out.join(',')).concat(indent, "]");
109
- }
110
-
111
- if (seen.indexOf(node) !== -1) {
112
- if (cycles) return JSON.stringify('__cycle__');
113
- throw new TypeError('Converting circular structure to JSON');
114
- } else seen.push(node);
115
-
116
- var keys = Object.keys(node).sort(cmp && cmp(node));
117
- var out = [];
118
-
119
- for (var _i = 0; _i < keys.length; _i++) {
120
- var ky = keys[_i];
121
- var value = stringify(node, ky, node[ky], level + 1);
122
- if (!value) continue;
123
- var keyValue = JSON.stringify(ky) + colonSeparator + value;
124
- out.push(indent + space + keyValue);
125
- }
126
-
127
- seen.splice(seen.indexOf(node), 1);
128
- return "{".concat(out.join(',')).concat(indent, "}");
129
- }({
130
- '': obj
131
- }, '', obj, 0);
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
+ );
44
+ const cmp = opts.cmp && ((f)=>{
45
+ return (node)=>{
46
+ return (a, b)=>{
47
+ const aobj = {
48
+ key: a,
49
+ value: node[a]
50
+ };
51
+ const bobj = {
52
+ key: b,
53
+ value: node[b]
54
+ };
55
+ return f(aobj, bobj);
56
+ };
57
+ };
58
+ })(opts.cmp);
59
+ const seen = [];
60
+ return (function stringify(parent, key, node, level) {
61
+ const indent = space ? `\n${new Array(level + 1).join(space)}` : '';
62
+ const colonSeparator = space ? ': ' : ':';
63
+ if (node && node.toJSON && typeof node.toJSON === 'function') {
64
+ node = node.toJSON();
65
+ }
66
+ node = replacer.call(parent, key, node);
67
+ if (node === undefined) {
68
+ return;
69
+ }
70
+ if (typeof node !== 'object' || node === null) {
71
+ return JSON.stringify(node);
72
+ }
73
+ if (type.isArray(node)) {
74
+ const out = [];
75
+ for(let i = 0; i < node.length; i++){
76
+ const item = stringify(node, i, node[i], level + 1) || JSON.stringify(null);
77
+ out.push(indent + space + item);
78
+ }
79
+ return `[${out.join(',')}${indent}]`;
80
+ }
81
+ if (seen.indexOf(node) !== -1) {
82
+ if (cycles) return JSON.stringify('__cycle__');
83
+ throw new TypeError('Converting circular structure to JSON');
84
+ } else seen.push(node);
85
+ const keys = Object.keys(node).sort(cmp && cmp(node));
86
+ const out = [];
87
+ for(let i = 0; i < keys.length; i++){
88
+ const ky = keys[i];
89
+ const value = stringify(node, ky, node[ky], level + 1);
90
+ if (!value) continue;
91
+ const keyValue = JSON.stringify(ky) + colonSeparator + value;
92
+ out.push(indent + space + keyValue);
93
+ }
94
+ seen.splice(seen.indexOf(node), 1);
95
+ return `{${out.join(',')}${indent}}`;
96
+ })({
97
+ '': obj
98
+ }, '', obj, 0);
132
99
  }
133
-
134
- var _default = stableStringify;
135
- exports.default = _default;
100
+ export default stableStringify;
package/dist/swap.js CHANGED
@@ -1,14 +1,3 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.default = void 0;
7
-
8
- var _type = _interopRequireDefault(require("./type"));
9
-
10
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
11
-
12
1
  /*
13
2
  Copyright 2020-2021 Lowdefy, Inc
14
3
 
@@ -23,14 +12,11 @@ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { de
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
- var swap = (arr, from, to) => {
28
- if (!_type.default.isArray(arr) || from < 0 || to < 0 || from >= arr.length || to >= arr.length) {
29
- return;
30
- }
31
-
32
- arr.splice(from, 1, arr.splice(to, 1, arr[from])[0]);
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]);
33
21
  };
34
-
35
- var _default = swap;
36
- exports.default = _default;
22
+ export default swap;