@lowdefy/helpers 3.23.0 → 4.0.0-alpha.5

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,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,23 +12,19 @@ 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 applyArrayIndices = (arrayIndices, name) => {
28
- if (!_type.default.isArray(arrayIndices)) return name;
29
- if (arrayIndices.length === 0) return name;
30
- if (_type.default.isNumber(name)) return name;
31
- var copy = JSON.parse(JSON.stringify(arrayIndices));
32
- var index = copy.shift();
33
- var newName;
34
-
35
- if (name.includes('$')) {
36
- newName = name.replace('$', index.toString()); // lgtm [js/incomplete-sanitization]
37
- } else {
38
- newName = name;
39
- }
40
-
41
- return applyArrayIndices(copy, newName);
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);
42
29
  };
43
-
44
- var _default = applyArrayIndices;
45
- exports.default = _default;
30
+ export default applyArrayIndices;
@@ -0,0 +1,27 @@
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
+ */ function cachedPromises(getter) {
16
+ const cache = new Map();
17
+ function getCachedPromise(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 getCachedPromise;
26
+ }
27
+ export default cachedPromises;
package/dist/get.js CHANGED
@@ -1,19 +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
- var _serializer = _interopRequireDefault(require("./serializer"));
11
-
12
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
13
-
14
- /* eslint-disable no-param-reassign */
15
-
16
- /*
1
+ /* eslint-disable no-param-reassign */ /*
17
2
  Copyright 2020-2021 Lowdefy, Inc
18
3
 
19
4
  Licensed under the Apache License, Version 2.0 (the "License");
@@ -27,8 +12,7 @@ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { de
27
12
  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
28
13
  See the License for the specific language governing permissions and
29
14
  limitations under the License.
30
- */
31
- // Derived from source:
15
+ */ // Derived from source:
32
16
  // https://github.com/jonschlinkert/get-value/blob/master/index.js
33
17
  // https://www.npmjs.com/package/get-value
34
18
  // The MIT License (MIT)
@@ -48,121 +32,102 @@ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { de
48
32
  // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
49
33
  // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
50
34
  // THE SOFTWARE.
35
+ import typeTest from './type.js';
36
+ import serializer from './serializer.js';
51
37
  function join(segs, joinChar, options) {
52
- if (typeof options.join === 'function') {
53
- return options.join(segs);
54
- }
55
-
56
- return segs[0] + joinChar + segs[1];
38
+ if (typeof options.join === 'function') {
39
+ return options.join(segs);
40
+ }
41
+ return segs[0] + joinChar + segs[1];
57
42
  }
58
-
59
43
  function split(path, splitChar, options) {
60
- if (typeof options.split === 'function') {
61
- return options.split(path);
62
- }
63
-
64
- return path.split(splitChar);
44
+ if (typeof options.split === 'function') {
45
+ return options.split(path);
46
+ }
47
+ return path.split(splitChar);
65
48
  }
66
-
67
49
  function isValid(key, target, options) {
68
- if (typeof options.isValid === 'function') {
69
- return options.isValid(key, target);
70
- }
71
-
72
- return true;
50
+ if (typeof options.isValid === 'function') {
51
+ return options.isValid(key, target);
52
+ }
53
+ return true;
73
54
  }
74
-
75
55
  function isValidObject(val) {
76
- return _type.default.isObject(val) || Array.isArray(val) || typeof val === 'function';
56
+ return typeTest.isObject(val) || Array.isArray(val) || typeof val === 'function';
77
57
  }
78
-
79
58
  function getter(target, path, options) {
80
- if (_type.default.isNone(path) || !isValidObject(target)) {
81
- return typeof options.default !== 'undefined' ? options.default : undefined;
82
- }
83
-
84
- if (typeof path === 'number') {
85
- path = String(path);
86
- }
87
-
88
- var isArray = Array.isArray(path);
89
- var isString = typeof path === 'string';
90
- var splitChar = options.separator || '.';
91
- var joinChar = options.joinChar || (typeof splitChar === 'string' ? splitChar : '.');
92
-
93
- if (isString && path in target) {
94
- return isValid(path, target, options) ? target[path] : options.default;
95
- }
96
-
97
- var segs = isArray ? path : split(path, splitChar, options);
98
- var len = segs.length;
99
- var idx = 0;
100
-
101
- do {
102
- var prop = segs[idx];
103
-
104
- if (typeof prop === 'number') {
105
- prop = String(prop);
59
+ if (typeTest.isNone(path) || !isValidObject(target)) {
60
+ return typeof options.default !== 'undefined' ? options.default : undefined;
106
61
  }
107
-
108
- while (prop && prop.slice(-1) === '\\') {
109
- idx += 1;
110
- prop = join([prop.slice(0, -1), segs[idx] || ''], joinChar, options);
62
+ if (typeof path === 'number') {
63
+ path = String(path);
111
64
  }
112
-
113
- if (prop in target) {
114
- if (!isValid(prop, target, options)) {
115
- return options.default;
116
- }
117
-
118
- target = target[prop];
119
- } else {
120
- var hasProp = false;
121
- var n = idx + 1;
122
-
123
- while (n < len) {
124
- prop = join([prop, segs[n]], joinChar, options);
125
- n += 1;
126
- hasProp = prop in target;
127
-
128
- if (hasProp) {
129
- if (!isValid(prop, target, options)) {
130
- return options.default;
131
- }
132
-
133
- target = target[prop];
134
- idx = n - 1;
135
- break;
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);
136
79
  }
137
- }
138
-
139
- if (!hasProp) {
140
- return options.default;
141
- }
142
- } // eslint-disable-next-line no-plusplus
143
-
144
- } while (++idx < len && isValidObject(target));
145
-
146
- if (idx === len) {
147
- return target;
148
- }
149
-
150
- return options.default;
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;
151
121
  }
152
-
153
122
  function get(target, path, options) {
154
- if (!_type.default.isObject(options)) {
155
- options = {
156
- default: options
157
- };
158
- }
159
-
160
- if (options.copy) {
161
- return _serializer.default.copy(getter(target, path, options));
162
- }
163
-
164
- return getter(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);
165
132
  }
166
-
167
- var _default = get;
168
- exports.default = _default;
133
+ export default get;
package/dist/index.js CHANGED
@@ -1,95 +1,27 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- Object.defineProperty(exports, "applyArrayIndices", {
7
- enumerable: true,
8
- get: function get() {
9
- return _applyArrayIndices.default;
10
- }
11
- });
12
- Object.defineProperty(exports, "get", {
13
- enumerable: true,
14
- get: function get() {
15
- return _get.default;
16
- }
17
- });
18
- Object.defineProperty(exports, "mergeObjects", {
19
- enumerable: true,
20
- get: function get() {
21
- return _mergeObjects.default;
22
- }
23
- });
24
- Object.defineProperty(exports, "omit", {
25
- enumerable: true,
26
- get: function get() {
27
- return _omit.default;
28
- }
29
- });
30
- Object.defineProperty(exports, "serializer", {
31
- enumerable: true,
32
- get: function get() {
33
- return _serializer.default;
34
- }
35
- });
36
- Object.defineProperty(exports, "set", {
37
- enumerable: true,
38
- get: function get() {
39
- return _set.default;
40
- }
41
- });
42
- Object.defineProperty(exports, "stableStringify", {
43
- enumerable: true,
44
- get: function get() {
45
- return _stableStringify.default;
46
- }
47
- });
48
- Object.defineProperty(exports, "swap", {
49
- enumerable: true,
50
- get: function get() {
51
- return _swap.default;
52
- }
53
- });
54
- Object.defineProperty(exports, "type", {
55
- enumerable: true,
56
- get: function get() {
57
- return _type.default;
58
- }
59
- });
60
- Object.defineProperty(exports, "unset", {
61
- enumerable: true,
62
- get: function get() {
63
- return _unset.default;
64
- }
65
- });
66
- Object.defineProperty(exports, "urlQuery", {
67
- enumerable: true,
68
- get: function get() {
69
- return _urlQuery.default;
70
- }
71
- });
72
-
73
- var _applyArrayIndices = _interopRequireDefault(require("./applyArrayIndices"));
74
-
75
- var _get = _interopRequireDefault(require("./get"));
76
-
77
- var _mergeObjects = _interopRequireDefault(require("./mergeObjects"));
78
-
79
- var _omit = _interopRequireDefault(require("./omit"));
80
-
81
- var _serializer = _interopRequireDefault(require("./serializer"));
82
-
83
- var _set = _interopRequireDefault(require("./set"));
84
-
85
- var _stableStringify = _interopRequireDefault(require("./stableStringify"));
86
-
87
- var _swap = _interopRequireDefault(require("./swap"));
88
-
89
- var _type = _interopRequireDefault(require("./type"));
90
-
91
- var _unset = _interopRequireDefault(require("./unset"));
92
-
93
- var _urlQuery = _interopRequireDefault(require("./urlQuery"));
94
-
95
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
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
+ */ 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
+ export { applyArrayIndices, cachedPromises, get, mergeObjects, omit, serializer, set, stableStringify, swap, type, unset, urlQuery };
@@ -1,16 +1,3 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.default = void 0;
7
-
8
- var _lodash = _interopRequireDefault(require("lodash.merge"));
9
-
10
- var _type = _interopRequireDefault(require("./type"));
11
-
12
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
13
-
14
1
  /*
15
2
  Copyright 2020-2021 Lowdefy, Inc
16
3
 
@@ -25,16 +12,15 @@ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { de
25
12
  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
26
13
  See the License for the specific language governing permissions and
27
14
  limitations under the License.
28
- */
29
- var mergeObjects = objects => {
30
- var merged = objects;
31
-
32
- if (_type.default.isArray(objects)) {
33
- merged = (0, _lodash.default)(...objects.filter(obj => _type.default.isObject(obj)));
34
- }
35
-
36
- return merged;
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
+ }
24
+ return merged;
37
25
  };
38
-
39
- var _default = mergeObjects;
40
- exports.default = _default;
26
+ export default mergeObjects;
package/dist/omit.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 _unset = _interopRequireDefault(require("./unset"));
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,13 +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 omit = (obj, list) => {
28
- list.forEach(item => {
29
- (0, _unset.default)(obj, item);
30
- });
31
- return obj;
15
+ */ import unset from './unset.js';
16
+ const omit = (obj, list)=>{
17
+ list.forEach((item)=>{
18
+ unset(obj, item);
19
+ });
20
+ return obj;
32
21
  };
33
-
34
- var _default = omit;
35
- exports.default = _default;
22
+ export default omit;