@bigbinary/neeto-commons-frontend 0.0.1 → 0.0.2
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/README.md +41 -9
- package/initializers.cjs.js +438 -0
- package/initializers.d.ts +59 -0
- package/initializers.js +307 -74
- package/package.json +26 -7
- package/pure.cjs.js +418 -0
- package/pure.d.ts +186 -0
- package/pure.js +78 -99
- package/{react.js → react-utils.cjs.js} +228 -65
- package/react-utils.d.ts +99 -0
- package/react-utils.js +1309 -0
- package/utils.cjs.js +2781 -0
- package/utils.d.ts +43 -0
- package/utils.js +2203 -46
package/pure.js
CHANGED
|
@@ -1,8 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
-
|
|
5
|
-
var ramda = require('ramda');
|
|
1
|
+
import { concat, slice, curry, isNil, complement, findLast, findLastIndex, count, fromPairs, toPairs, path, isEmpty, equals } from 'ramda';
|
|
6
2
|
|
|
7
3
|
function _arrayWithHoles(arr) {
|
|
8
4
|
if (Array.isArray(arr)) return arr;
|
|
@@ -102,27 +98,47 @@ var camelToSnakeCase = function camelToSnakeCase(string) {
|
|
|
102
98
|
var capitalize = function capitalize(string) {
|
|
103
99
|
return string.charAt(0).toUpperCase() + string.slice(1);
|
|
104
100
|
};
|
|
105
|
-
var truncate = function truncate() {
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
101
|
+
var truncate = function truncate(string, length) {
|
|
102
|
+
return string.length > length ? concat(slice(0, length, string), "...") : string;
|
|
103
|
+
};
|
|
104
|
+
|
|
105
|
+
var matchesImpl = function matchesImpl(pattern, object) {
|
|
106
|
+
var __parent = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : object;
|
|
107
|
+
|
|
108
|
+
if (object === pattern) return true;
|
|
109
|
+
if (typeof pattern === "function" && pattern(object, __parent)) return true;
|
|
110
|
+
if (isNil(pattern) || isNil(object)) return false;
|
|
111
|
+
if (_typeof(pattern) !== "object") return false;
|
|
112
|
+
return Object.entries(pattern).every(function (_ref) {
|
|
113
|
+
var _ref2 = _slicedToArray(_ref, 2),
|
|
114
|
+
key = _ref2[0],
|
|
115
|
+
value = _ref2[1];
|
|
116
|
+
|
|
117
|
+
return matchesImpl(value, object[key], __parent);
|
|
118
|
+
});
|
|
109
119
|
};
|
|
110
120
|
|
|
111
121
|
var transformObjectDeep = function transformObjectDeep(object, keyValueTransformer) {
|
|
122
|
+
var objectPreProcessor = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : undefined;
|
|
123
|
+
|
|
124
|
+
if (objectPreProcessor && typeof objectPreProcessor === "function") {
|
|
125
|
+
object = objectPreProcessor(object);
|
|
126
|
+
}
|
|
127
|
+
|
|
112
128
|
if (Array.isArray(object)) {
|
|
113
129
|
return object.map(function (obj) {
|
|
114
|
-
return transformObjectDeep(obj, keyValueTransformer);
|
|
130
|
+
return transformObjectDeep(obj, keyValueTransformer, objectPreProcessor);
|
|
115
131
|
});
|
|
116
132
|
} else if (object === null || _typeof(object) !== "object") {
|
|
117
133
|
return object;
|
|
118
134
|
}
|
|
119
135
|
|
|
120
|
-
return Object.fromEntries(Object.entries(object).map(function (
|
|
121
|
-
var
|
|
122
|
-
key =
|
|
123
|
-
value =
|
|
136
|
+
return Object.fromEntries(Object.entries(object).map(function (_ref3) {
|
|
137
|
+
var _ref4 = _slicedToArray(_ref3, 2),
|
|
138
|
+
key = _ref4[0],
|
|
139
|
+
value = _ref4[1];
|
|
124
140
|
|
|
125
|
-
return keyValueTransformer(key, transformObjectDeep(value, keyValueTransformer));
|
|
141
|
+
return keyValueTransformer(key, transformObjectDeep(value, keyValueTransformer, objectPreProcessor));
|
|
126
142
|
}));
|
|
127
143
|
};
|
|
128
144
|
var keysToCamelCase = function keysToCamelCase(object) {
|
|
@@ -135,6 +151,20 @@ var keysToSnakeCase = function keysToSnakeCase(object) {
|
|
|
135
151
|
return [camelToSnakeCase(key), value];
|
|
136
152
|
});
|
|
137
153
|
};
|
|
154
|
+
var serializeKeysToSnakeCase = function serializeKeysToSnakeCase(object) {
|
|
155
|
+
return transformObjectDeep(object, function (key, value) {
|
|
156
|
+
return [camelToSnakeCase(key), value];
|
|
157
|
+
}, function (object) {
|
|
158
|
+
return typeof (object === null || object === void 0 ? void 0 : object.toJSON) === "function" ? object.toJSON() : object;
|
|
159
|
+
});
|
|
160
|
+
};
|
|
161
|
+
var preprocessForSerialization = function preprocessForSerialization(object) {
|
|
162
|
+
return transformObjectDeep(object, function (key, value) {
|
|
163
|
+
return [key, value];
|
|
164
|
+
}, function (object) {
|
|
165
|
+
return typeof (object === null || object === void 0 ? void 0 : object.toJSON) === "function" ? object.toJSON() : object;
|
|
166
|
+
});
|
|
167
|
+
};
|
|
138
168
|
var deepFreezeObject = function deepFreezeObject(object) {
|
|
139
169
|
if (object && _typeof(object) === "object" && !Object.isFrozen(object)) {
|
|
140
170
|
Object.keys(object).forEach(function (property) {
|
|
@@ -145,25 +175,15 @@ var deepFreezeObject = function deepFreezeObject(object) {
|
|
|
145
175
|
|
|
146
176
|
return object;
|
|
147
177
|
};
|
|
148
|
-
var matches =
|
|
149
|
-
|
|
150
|
-
if (typeof pattern === "function" && pattern(object)) return true;
|
|
151
|
-
if (ramda.isNil(pattern) || ramda.isNil(object)) return false;
|
|
152
|
-
if (_typeof(pattern) !== "object") return false;
|
|
153
|
-
return Object.entries(pattern).every(function (_ref3) {
|
|
154
|
-
var _ref4 = _slicedToArray(_ref3, 2),
|
|
155
|
-
key = _ref4[0],
|
|
156
|
-
value = _ref4[1];
|
|
157
|
-
|
|
158
|
-
return matches(value, object[key]);
|
|
159
|
-
});
|
|
178
|
+
var matches = /*#__PURE__*/curry(function (pattern, object) {
|
|
179
|
+
return matchesImpl(pattern, object);
|
|
160
180
|
});
|
|
161
181
|
var filterNonNull = function filterNonNull(object) {
|
|
162
182
|
return Object.fromEntries(Object.entries(object).filter(function (_ref5) {
|
|
163
183
|
var _ref6 = _slicedToArray(_ref5, 2),
|
|
164
184
|
v = _ref6[1];
|
|
165
185
|
|
|
166
|
-
return !
|
|
186
|
+
return !isNil(v);
|
|
167
187
|
}).map(function (_ref7) {
|
|
168
188
|
var _ref8 = _slicedToArray(_ref7, 2),
|
|
169
189
|
k = _ref8[0],
|
|
@@ -191,71 +211,71 @@ function _defineProperty(obj, key, value) {
|
|
|
191
211
|
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
|
|
192
212
|
|
|
193
213
|
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
|
|
194
|
-
var removeById =
|
|
214
|
+
var removeById = /*#__PURE__*/curry(function (id, array) {
|
|
195
215
|
return array.filter(function (item) {
|
|
196
216
|
return item.id !== id;
|
|
197
217
|
});
|
|
198
218
|
});
|
|
199
|
-
var findById =
|
|
219
|
+
var findById = /*#__PURE__*/curry(function (id, array) {
|
|
200
220
|
return array.find(function (item) {
|
|
201
221
|
return item.id === id;
|
|
202
222
|
});
|
|
203
223
|
});
|
|
204
|
-
var replaceById =
|
|
224
|
+
var replaceById = /*#__PURE__*/curry(function (id, newItem, array) {
|
|
205
225
|
return array.map(function (item) {
|
|
206
226
|
return item.id === id ? newItem : item;
|
|
207
227
|
});
|
|
208
228
|
});
|
|
209
|
-
var modifyById =
|
|
229
|
+
var modifyById = /*#__PURE__*/curry(function (id, modifier, array) {
|
|
210
230
|
return array.map(function (item) {
|
|
211
231
|
return item.id === id ? modifier(item) : item;
|
|
212
232
|
});
|
|
213
233
|
});
|
|
214
|
-
var findBy =
|
|
234
|
+
var findBy = /*#__PURE__*/curry(function (pattern, array) {
|
|
215
235
|
return array.find(matches(pattern));
|
|
216
236
|
});
|
|
217
|
-
var removeBy =
|
|
218
|
-
return array.filter(
|
|
237
|
+
var removeBy = /*#__PURE__*/curry(function (pattern, array) {
|
|
238
|
+
return array.filter(complement(matches(pattern)));
|
|
219
239
|
});
|
|
220
|
-
var replaceBy =
|
|
240
|
+
var replaceBy = /*#__PURE__*/curry(function (pattern, newItem, array) {
|
|
221
241
|
return array.map(function (item) {
|
|
222
242
|
return matches(pattern, item) ? newItem : item;
|
|
223
243
|
});
|
|
224
244
|
});
|
|
225
|
-
var modifyBy =
|
|
245
|
+
var modifyBy = /*#__PURE__*/curry(function (pattern, modifier, array) {
|
|
226
246
|
return array.map(function (item) {
|
|
227
247
|
return matches(pattern, item) ? modifier(item) : item;
|
|
228
248
|
});
|
|
229
249
|
});
|
|
230
|
-
var existsById =
|
|
250
|
+
var existsById = /*#__PURE__*/curry(function (id, array) {
|
|
231
251
|
return array.some(function (item) {
|
|
232
252
|
return item.id === id;
|
|
233
253
|
});
|
|
234
254
|
});
|
|
235
|
-
var existsBy =
|
|
255
|
+
var existsBy = /*#__PURE__*/curry(function (pattern, array) {
|
|
236
256
|
return array.some(matches(pattern));
|
|
237
257
|
});
|
|
238
|
-
var findLastBy =
|
|
239
|
-
return
|
|
258
|
+
var findLastBy = /*#__PURE__*/curry(function (pattern, array) {
|
|
259
|
+
return findLast(matches(pattern), array);
|
|
240
260
|
});
|
|
241
|
-
var findIndexById =
|
|
261
|
+
var findIndexById = /*#__PURE__*/curry(function (id, array) {
|
|
242
262
|
return array.findIndex(function (item) {
|
|
243
263
|
return item.id === id;
|
|
244
264
|
});
|
|
245
265
|
});
|
|
246
|
-
var findIndexBy =
|
|
266
|
+
var findIndexBy = /*#__PURE__*/curry(function (pattern, array) {
|
|
247
267
|
return array.findIndex(matches(pattern));
|
|
248
268
|
});
|
|
249
|
-
var findLastIndexBy =
|
|
250
|
-
return
|
|
269
|
+
var findLastIndexBy = /*#__PURE__*/curry(function (pattern, array) {
|
|
270
|
+
return findLastIndex(matches(pattern), array);
|
|
251
271
|
});
|
|
252
|
-
var filterBy =
|
|
272
|
+
var filterBy = /*#__PURE__*/curry(function (pattern, array) {
|
|
253
273
|
return array.filter(matches(pattern));
|
|
254
274
|
});
|
|
255
|
-
var countBy =
|
|
256
|
-
return
|
|
275
|
+
var countBy = /*#__PURE__*/curry(function (pattern, array) {
|
|
276
|
+
return count(matches(pattern), array);
|
|
257
277
|
});
|
|
258
|
-
var copyKeys =
|
|
278
|
+
var copyKeys = /*#__PURE__*/curry(function (keyMap, objectArray) {
|
|
259
279
|
return objectArray.map(function (object) {
|
|
260
280
|
var shallowCopy = _objectSpread({}, object);
|
|
261
281
|
|
|
@@ -266,7 +286,7 @@ var copyKeys = ramda.curry(function (keyMap, objectArray) {
|
|
|
266
286
|
return shallowCopy;
|
|
267
287
|
});
|
|
268
288
|
});
|
|
269
|
-
var renameKeys =
|
|
289
|
+
var renameKeys = /*#__PURE__*/curry(function (keyMap, objectArray) {
|
|
270
290
|
return objectArray.map(function (object) {
|
|
271
291
|
var shallowCopy = _objectSpread({}, object);
|
|
272
292
|
|
|
@@ -278,10 +298,10 @@ var renameKeys = ramda.curry(function (keyMap, objectArray) {
|
|
|
278
298
|
return shallowCopy;
|
|
279
299
|
});
|
|
280
300
|
});
|
|
281
|
-
var copyKeysDeep =
|
|
301
|
+
var copyKeysDeep = /*#__PURE__*/curry(function (keyMap, objectArray) {
|
|
282
302
|
var copyKeysSingleObject = function copyKeysSingleObject(object, keyMap) {
|
|
283
303
|
var root = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : object;
|
|
284
|
-
return _objectSpread(_objectSpread({}, object),
|
|
304
|
+
return _objectSpread(_objectSpread({}, object), fromPairs(toPairs(keyMap).map(function (_ref) {
|
|
285
305
|
var _ref2 = _slicedToArray(_ref, 2),
|
|
286
306
|
destination = _ref2[0],
|
|
287
307
|
source = _ref2[1];
|
|
@@ -289,7 +309,7 @@ var copyKeysDeep = ramda.curry(function (keyMap, objectArray) {
|
|
|
289
309
|
if (typeof source === "function") {
|
|
290
310
|
return [destination, source(object[destination], root)];
|
|
291
311
|
} else if (Array.isArray(source)) {
|
|
292
|
-
return [destination,
|
|
312
|
+
return [destination, path(source, root)];
|
|
293
313
|
} else if (_typeof(source) === "object") {
|
|
294
314
|
return [destination, copyKeysSingleObject(object[destination], source, root)];
|
|
295
315
|
}
|
|
@@ -339,54 +359,13 @@ var dynamicArray = function dynamicArray(count, elementGenerator) {
|
|
|
339
359
|
return elementGenerator(index);
|
|
340
360
|
});
|
|
341
361
|
};
|
|
342
|
-
var isNotNil =
|
|
343
|
-
var isNotEmpty =
|
|
344
|
-
var notEquals =
|
|
362
|
+
var isNotNil = /*#__PURE__*/complement(isNil);
|
|
363
|
+
var isNotEmpty = /*#__PURE__*/complement(isEmpty);
|
|
364
|
+
var notEquals = /*#__PURE__*/curry(function (x, y) {
|
|
345
365
|
return x !== y;
|
|
346
366
|
});
|
|
347
367
|
var isNot = notEquals;
|
|
348
|
-
var notEqualsDeep =
|
|
368
|
+
var notEqualsDeep = /*#__PURE__*/complement(equals);
|
|
349
369
|
var isNotEqualDeep = notEqualsDeep;
|
|
350
370
|
|
|
351
|
-
|
|
352
|
-
exports.capitalize = capitalize;
|
|
353
|
-
exports.copyKeys = copyKeys;
|
|
354
|
-
exports.copyKeysDeep = copyKeysDeep;
|
|
355
|
-
exports.countBy = countBy;
|
|
356
|
-
exports.deepFreezeObject = deepFreezeObject;
|
|
357
|
-
exports.dynamicArray = dynamicArray;
|
|
358
|
-
exports.existsBy = existsBy;
|
|
359
|
-
exports.existsById = existsById;
|
|
360
|
-
exports.filterBy = filterBy;
|
|
361
|
-
exports.filterNonNull = filterNonNull;
|
|
362
|
-
exports.findBy = findBy;
|
|
363
|
-
exports.findById = findById;
|
|
364
|
-
exports.findIndexBy = findIndexBy;
|
|
365
|
-
exports.findIndexById = findIndexById;
|
|
366
|
-
exports.findLastBy = findLastBy;
|
|
367
|
-
exports.findLastIndexBy = findLastIndexBy;
|
|
368
|
-
exports.getRandomInt = getRandomInt;
|
|
369
|
-
exports.humanize = humanize;
|
|
370
|
-
exports.isNot = isNot;
|
|
371
|
-
exports.isNotEmpty = isNotEmpty;
|
|
372
|
-
exports.isNotEqualDeep = isNotEqualDeep;
|
|
373
|
-
exports.isNotNil = isNotNil;
|
|
374
|
-
exports.keysToCamelCase = keysToCamelCase;
|
|
375
|
-
exports.keysToSnakeCase = keysToSnakeCase;
|
|
376
|
-
exports.matches = matches;
|
|
377
|
-
exports.modifyBy = modifyBy;
|
|
378
|
-
exports.modifyById = modifyById;
|
|
379
|
-
exports.noop = noop;
|
|
380
|
-
exports.notEquals = notEquals;
|
|
381
|
-
exports.notEqualsDeep = notEqualsDeep;
|
|
382
|
-
exports.randomPick = randomPick;
|
|
383
|
-
exports.removeBy = removeBy;
|
|
384
|
-
exports.removeById = removeById;
|
|
385
|
-
exports.renameKeys = renameKeys;
|
|
386
|
-
exports.replaceBy = replaceBy;
|
|
387
|
-
exports.replaceById = replaceById;
|
|
388
|
-
exports.slugify = slugify;
|
|
389
|
-
exports.snakeToCamelCase = snakeToCamelCase;
|
|
390
|
-
exports.toLabelAndValue = toLabelAndValue;
|
|
391
|
-
exports.transformObjectDeep = transformObjectDeep;
|
|
392
|
-
exports.truncate = truncate;
|
|
371
|
+
export { camelToSnakeCase, capitalize, copyKeys, copyKeysDeep, countBy, deepFreezeObject, dynamicArray, existsBy, existsById, filterBy, filterNonNull, findBy, findById, findIndexBy, findIndexById, findLastBy, findLastIndexBy, getRandomInt, humanize, isNot, isNotEmpty, isNotEqualDeep, isNotNil, keysToCamelCase, keysToSnakeCase, matches, modifyBy, modifyById, noop, notEquals, notEqualsDeep, preprocessForSerialization, randomPick, removeBy, removeById, renameKeys, replaceBy, replaceById, serializeKeysToSnakeCase, slugify, snakeToCamelCase, toLabelAndValue, transformObjectDeep, truncate };
|