@bigbinary/neeto-commons-frontend 2.0.1 → 2.0.4
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 +1 -1
- package/initializers.cjs.js +452 -0
- package/initializers.d.ts +59 -0
- package/initializers.js +187 -119
- package/package.json +20 -1
- package/pure.cjs.js +409 -0
- package/pure.d.ts +183 -0
- package/pure.js +61 -90
- package/react-utils.cjs.js +1260 -0
- package/react-utils.d.ts +87 -0
- package/react-utils.js +124 -165
- package/utils.cjs.js +1325 -0
- package/utils.d.ts +43 -0
- package/utils.js +725 -44
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;
|
|
@@ -103,7 +99,7 @@ var capitalize = function capitalize(string) {
|
|
|
103
99
|
return string.charAt(0).toUpperCase() + string.slice(1);
|
|
104
100
|
};
|
|
105
101
|
var truncate = function truncate(string, length) {
|
|
106
|
-
return string.length > length ?
|
|
102
|
+
return string.length > length ? concat(slice(0, length, string), "...") : string;
|
|
107
103
|
};
|
|
108
104
|
|
|
109
105
|
var transformObjectDeep = function transformObjectDeep(object, keyValueTransformer) {
|
|
@@ -133,6 +129,22 @@ var keysToSnakeCase = function keysToSnakeCase(object) {
|
|
|
133
129
|
return [camelToSnakeCase(key), value];
|
|
134
130
|
});
|
|
135
131
|
};
|
|
132
|
+
var serializeKeysToSnakeCase = function serializeKeysToSnakeCase(object) {
|
|
133
|
+
if (Array.isArray(object)) {
|
|
134
|
+
return object.map(serializeKeysToSnakeCase);
|
|
135
|
+
} else if (object === null || _typeof(object) !== "object") {
|
|
136
|
+
return object;
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
return Object.fromEntries(Object.entries(object).map(function (_ref3) {
|
|
140
|
+
var _ref4 = _slicedToArray(_ref3, 2),
|
|
141
|
+
key = _ref4[0],
|
|
142
|
+
value = _ref4[1];
|
|
143
|
+
|
|
144
|
+
var val = typeof (value === null || value === void 0 ? void 0 : value.toJSON) === "function" ? value.toJSON() : value;
|
|
145
|
+
return [camelToSnakeCase(key), serializeKeysToSnakeCase(val)];
|
|
146
|
+
}));
|
|
147
|
+
};
|
|
136
148
|
var deepFreezeObject = function deepFreezeObject(object) {
|
|
137
149
|
if (object && _typeof(object) === "object" && !Object.isFrozen(object)) {
|
|
138
150
|
Object.keys(object).forEach(function (property) {
|
|
@@ -143,32 +155,32 @@ var deepFreezeObject = function deepFreezeObject(object) {
|
|
|
143
155
|
|
|
144
156
|
return object;
|
|
145
157
|
};
|
|
146
|
-
var matches =
|
|
158
|
+
var matches = curry(function (pattern, object) {
|
|
147
159
|
var __parent = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : object;
|
|
148
160
|
|
|
149
161
|
if (object === pattern) return true;
|
|
150
162
|
if (typeof pattern === "function" && pattern(object, __parent)) return true;
|
|
151
|
-
if (
|
|
163
|
+
if (isNil(pattern) || isNil(object)) return false;
|
|
152
164
|
if (_typeof(pattern) !== "object") return false;
|
|
153
|
-
return Object.entries(pattern).every(function (
|
|
154
|
-
var
|
|
155
|
-
key =
|
|
156
|
-
value =
|
|
165
|
+
return Object.entries(pattern).every(function (_ref5) {
|
|
166
|
+
var _ref6 = _slicedToArray(_ref5, 2),
|
|
167
|
+
key = _ref6[0],
|
|
168
|
+
value = _ref6[1];
|
|
157
169
|
|
|
158
170
|
return matches(value, object[key], __parent);
|
|
159
171
|
});
|
|
160
172
|
});
|
|
161
173
|
var filterNonNull = function filterNonNull(object) {
|
|
162
|
-
return Object.fromEntries(Object.entries(object).filter(function (
|
|
163
|
-
var _ref6 = _slicedToArray(_ref5, 2),
|
|
164
|
-
v = _ref6[1];
|
|
165
|
-
|
|
166
|
-
return !ramda.isNil(v);
|
|
167
|
-
}).map(function (_ref7) {
|
|
174
|
+
return Object.fromEntries(Object.entries(object).filter(function (_ref7) {
|
|
168
175
|
var _ref8 = _slicedToArray(_ref7, 2),
|
|
169
|
-
k = _ref8[0],
|
|
170
176
|
v = _ref8[1];
|
|
171
177
|
|
|
178
|
+
return !isNil(v);
|
|
179
|
+
}).map(function (_ref9) {
|
|
180
|
+
var _ref10 = _slicedToArray(_ref9, 2),
|
|
181
|
+
k = _ref10[0],
|
|
182
|
+
v = _ref10[1];
|
|
183
|
+
|
|
172
184
|
return [k, _typeof(v) === "object" && !Array.isArray(v) ? filterNonNull(v) : v];
|
|
173
185
|
}));
|
|
174
186
|
};
|
|
@@ -191,71 +203,71 @@ function _defineProperty(obj, key, value) {
|
|
|
191
203
|
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
204
|
|
|
193
205
|
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 =
|
|
206
|
+
var removeById = curry(function (id, array) {
|
|
195
207
|
return array.filter(function (item) {
|
|
196
208
|
return item.id !== id;
|
|
197
209
|
});
|
|
198
210
|
});
|
|
199
|
-
var findById =
|
|
211
|
+
var findById = curry(function (id, array) {
|
|
200
212
|
return array.find(function (item) {
|
|
201
213
|
return item.id === id;
|
|
202
214
|
});
|
|
203
215
|
});
|
|
204
|
-
var replaceById =
|
|
216
|
+
var replaceById = curry(function (id, newItem, array) {
|
|
205
217
|
return array.map(function (item) {
|
|
206
218
|
return item.id === id ? newItem : item;
|
|
207
219
|
});
|
|
208
220
|
});
|
|
209
|
-
var modifyById =
|
|
221
|
+
var modifyById = curry(function (id, modifier, array) {
|
|
210
222
|
return array.map(function (item) {
|
|
211
223
|
return item.id === id ? modifier(item) : item;
|
|
212
224
|
});
|
|
213
225
|
});
|
|
214
|
-
var findBy =
|
|
226
|
+
var findBy = curry(function (pattern, array) {
|
|
215
227
|
return array.find(matches(pattern));
|
|
216
228
|
});
|
|
217
|
-
var removeBy =
|
|
218
|
-
return array.filter(
|
|
229
|
+
var removeBy = curry(function (pattern, array) {
|
|
230
|
+
return array.filter(complement(matches(pattern)));
|
|
219
231
|
});
|
|
220
|
-
var replaceBy =
|
|
232
|
+
var replaceBy = curry(function (pattern, newItem, array) {
|
|
221
233
|
return array.map(function (item) {
|
|
222
234
|
return matches(pattern, item) ? newItem : item;
|
|
223
235
|
});
|
|
224
236
|
});
|
|
225
|
-
var modifyBy =
|
|
237
|
+
var modifyBy = curry(function (pattern, modifier, array) {
|
|
226
238
|
return array.map(function (item) {
|
|
227
239
|
return matches(pattern, item) ? modifier(item) : item;
|
|
228
240
|
});
|
|
229
241
|
});
|
|
230
|
-
var existsById =
|
|
242
|
+
var existsById = curry(function (id, array) {
|
|
231
243
|
return array.some(function (item) {
|
|
232
244
|
return item.id === id;
|
|
233
245
|
});
|
|
234
246
|
});
|
|
235
|
-
var existsBy =
|
|
247
|
+
var existsBy = curry(function (pattern, array) {
|
|
236
248
|
return array.some(matches(pattern));
|
|
237
249
|
});
|
|
238
|
-
var findLastBy =
|
|
239
|
-
return
|
|
250
|
+
var findLastBy = curry(function (pattern, array) {
|
|
251
|
+
return findLast(matches(pattern), array);
|
|
240
252
|
});
|
|
241
|
-
var findIndexById =
|
|
253
|
+
var findIndexById = curry(function (id, array) {
|
|
242
254
|
return array.findIndex(function (item) {
|
|
243
255
|
return item.id === id;
|
|
244
256
|
});
|
|
245
257
|
});
|
|
246
|
-
var findIndexBy =
|
|
258
|
+
var findIndexBy = curry(function (pattern, array) {
|
|
247
259
|
return array.findIndex(matches(pattern));
|
|
248
260
|
});
|
|
249
|
-
var findLastIndexBy =
|
|
250
|
-
return
|
|
261
|
+
var findLastIndexBy = curry(function (pattern, array) {
|
|
262
|
+
return findLastIndex(matches(pattern), array);
|
|
251
263
|
});
|
|
252
|
-
var filterBy =
|
|
264
|
+
var filterBy = curry(function (pattern, array) {
|
|
253
265
|
return array.filter(matches(pattern));
|
|
254
266
|
});
|
|
255
|
-
var countBy =
|
|
256
|
-
return
|
|
267
|
+
var countBy = curry(function (pattern, array) {
|
|
268
|
+
return count(matches(pattern), array);
|
|
257
269
|
});
|
|
258
|
-
var copyKeys =
|
|
270
|
+
var copyKeys = curry(function (keyMap, objectArray) {
|
|
259
271
|
return objectArray.map(function (object) {
|
|
260
272
|
var shallowCopy = _objectSpread({}, object);
|
|
261
273
|
|
|
@@ -266,7 +278,7 @@ var copyKeys = ramda.curry(function (keyMap, objectArray) {
|
|
|
266
278
|
return shallowCopy;
|
|
267
279
|
});
|
|
268
280
|
});
|
|
269
|
-
var renameKeys =
|
|
281
|
+
var renameKeys = curry(function (keyMap, objectArray) {
|
|
270
282
|
return objectArray.map(function (object) {
|
|
271
283
|
var shallowCopy = _objectSpread({}, object);
|
|
272
284
|
|
|
@@ -278,10 +290,10 @@ var renameKeys = ramda.curry(function (keyMap, objectArray) {
|
|
|
278
290
|
return shallowCopy;
|
|
279
291
|
});
|
|
280
292
|
});
|
|
281
|
-
var copyKeysDeep =
|
|
293
|
+
var copyKeysDeep = curry(function (keyMap, objectArray) {
|
|
282
294
|
var copyKeysSingleObject = function copyKeysSingleObject(object, keyMap) {
|
|
283
295
|
var root = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : object;
|
|
284
|
-
return _objectSpread(_objectSpread({}, object),
|
|
296
|
+
return _objectSpread(_objectSpread({}, object), fromPairs(toPairs(keyMap).map(function (_ref) {
|
|
285
297
|
var _ref2 = _slicedToArray(_ref, 2),
|
|
286
298
|
destination = _ref2[0],
|
|
287
299
|
source = _ref2[1];
|
|
@@ -289,7 +301,7 @@ var copyKeysDeep = ramda.curry(function (keyMap, objectArray) {
|
|
|
289
301
|
if (typeof source === "function") {
|
|
290
302
|
return [destination, source(object[destination], root)];
|
|
291
303
|
} else if (Array.isArray(source)) {
|
|
292
|
-
return [destination,
|
|
304
|
+
return [destination, path(source, root)];
|
|
293
305
|
} else if (_typeof(source) === "object") {
|
|
294
306
|
return [destination, copyKeysSingleObject(object[destination], source, root)];
|
|
295
307
|
}
|
|
@@ -339,54 +351,13 @@ var dynamicArray = function dynamicArray(count, elementGenerator) {
|
|
|
339
351
|
return elementGenerator(index);
|
|
340
352
|
});
|
|
341
353
|
};
|
|
342
|
-
var isNotNil =
|
|
343
|
-
var isNotEmpty =
|
|
344
|
-
var notEquals =
|
|
354
|
+
var isNotNil = complement(isNil);
|
|
355
|
+
var isNotEmpty = complement(isEmpty);
|
|
356
|
+
var notEquals = curry(function (x, y) {
|
|
345
357
|
return x !== y;
|
|
346
358
|
});
|
|
347
359
|
var isNot = notEquals;
|
|
348
|
-
var notEqualsDeep =
|
|
360
|
+
var notEqualsDeep = complement(equals);
|
|
349
361
|
var isNotEqualDeep = notEqualsDeep;
|
|
350
362
|
|
|
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;
|
|
363
|
+
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, randomPick, removeBy, removeById, renameKeys, replaceBy, replaceById, serializeKeysToSnakeCase, slugify, snakeToCamelCase, toLabelAndValue, transformObjectDeep, truncate };
|