@bigbinary/neeto-commons-frontend 2.0.12 → 2.0.14

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/pure.js CHANGED
@@ -1,4 +1,4 @@
1
- import { concat, slice, curry, isNil, complement, findLast, findLastIndex, count, fromPairs, toPairs, path, isEmpty, equals } from 'ramda';
1
+ import { curryN, isNil, complement, isEmpty, curry, equals, concat, slice, findLast, findLastIndex, count, fromPairs, toPairs, path } from 'ramda';
2
2
 
3
3
  function _arrayWithHoles(arr) {
4
4
  if (Array.isArray(arr)) return arr;
@@ -71,6 +71,67 @@ function _typeof(obj) {
71
71
  }, _typeof(obj);
72
72
  }
73
73
 
74
+ /**
75
+ * @template {Function} T
76
+ * @param {T} func
77
+ * @returns {T}
78
+ */
79
+
80
+ var nullSafe = function nullSafe(func) {
81
+ return (// @ts-ignore
82
+ curryN(func.length, function () {
83
+ var _ref;
84
+
85
+ var dataArg = (_ref = func.length - 1, _ref < 0 || arguments.length <= _ref ? undefined : arguments[_ref]);
86
+ return isNil(dataArg) ? dataArg : func.apply(void 0, arguments);
87
+ })
88
+ );
89
+ };
90
+ var noop = function noop() {};
91
+ var toLabelAndValue = function toLabelAndValue(string) {
92
+ return {
93
+ label: string,
94
+ value: string
95
+ };
96
+ };
97
+ var getRandomInt = function getRandomInt() {
98
+ var a = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : Number.MAX_SAFE_INTEGER;
99
+ var b = arguments.length > 1 ? arguments[1] : undefined;
100
+
101
+ if (b) {
102
+ a = Math.ceil(a);
103
+ b = Math.floor(b);
104
+ } else {
105
+ b = a;
106
+ a = 0;
107
+ }
108
+
109
+ return Math.floor(Math.random() * (b - a) + a);
110
+ };
111
+ var randomPick = function randomPick() {
112
+ for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
113
+ args[_key] = arguments[_key];
114
+ }
115
+
116
+ var randomNumber = getRandomInt(0, args.length);
117
+ return args[randomNumber];
118
+ };
119
+ var dynamicArray = function dynamicArray(count, elementGenerator) {
120
+ return Array.from({
121
+ length: count
122
+ }, function (_, index) {
123
+ return elementGenerator(index);
124
+ });
125
+ };
126
+ var isNotNil = /*#__PURE__*/complement(isNil);
127
+ var isNotEmpty = /*#__PURE__*/complement(isEmpty);
128
+ var notEquals = /*#__PURE__*/curry(function (x, y) {
129
+ return x !== y;
130
+ });
131
+ var isNot = notEquals;
132
+ var notEqualsDeep = /*#__PURE__*/complement(equals);
133
+ var isNotEqualDeep = notEqualsDeep;
134
+
74
135
  var slugify = function slugify(string) {
75
136
  return string.toString().toLowerCase().replace(/\s+/g, "-") // Replace spaces with -
76
137
  .replace(/&/g, "-and-") // Replace & with 'and'
@@ -101,6 +162,14 @@ var capitalize = function capitalize(string) {
101
162
  var truncate = function truncate(string, length) {
102
163
  return string.length > length ? concat(slice(0, length, string), "...") : string;
103
164
  };
165
+ var _slugify = nullSafe(slugify);
166
+ var _humanize = nullSafe(humanize);
167
+ var _snakeToCamelCase = nullSafe(snakeToCamelCase);
168
+ var _camelToSnakeCase = nullSafe(camelToSnakeCase);
169
+ var _capitalize = nullSafe(capitalize);
170
+ var _truncate = function _truncate(string, length) {
171
+ return isNil(string) ? string : truncate(string, length);
172
+ };
104
173
 
105
174
  var matchesImpl = function matchesImpl(pattern, object) {
106
175
  var __parent = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : object;
@@ -192,6 +261,7 @@ var filterNonNull = function filterNonNull(object) {
192
261
  return [k, _typeof(v) === "object" && !Array.isArray(v) ? filterNonNull(v) : v];
193
262
  }));
194
263
  };
264
+ var _filterNonNull = nullSafe(filterNonNull);
195
265
 
196
266
  function _defineProperty(obj, key, value) {
197
267
  if (key in obj) {
@@ -322,50 +392,24 @@ var copyKeysDeep = /*#__PURE__*/curry(function (keyMap, objectArray) {
322
392
  return copyKeysSingleObject(object, keyMap);
323
393
  });
324
394
  });
325
-
326
- var noop = function noop() {};
327
- var toLabelAndValue = function toLabelAndValue(string) {
328
- return {
329
- label: string,
330
- value: string
331
- };
332
- };
333
- var getRandomInt = function getRandomInt() {
334
- var a = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : Number.MAX_SAFE_INTEGER;
335
- var b = arguments.length > 1 ? arguments[1] : undefined;
336
-
337
- if (b) {
338
- a = Math.ceil(a);
339
- b = Math.floor(b);
340
- } else {
341
- b = a;
342
- a = 0;
343
- }
344
-
345
- return Math.floor(Math.random() * (b - a) + a);
346
- };
347
- var randomPick = function randomPick() {
348
- for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
349
- args[_key] = arguments[_key];
350
- }
351
-
352
- var randomNumber = getRandomInt(0, args.length);
353
- return args[randomNumber];
354
- };
355
- var dynamicArray = function dynamicArray(count, elementGenerator) {
356
- return Array.from({
357
- length: count
358
- }, function (_, index) {
359
- return elementGenerator(index);
360
- });
361
- };
362
- var isNotNil = /*#__PURE__*/complement(isNil);
363
- var isNotEmpty = /*#__PURE__*/complement(isEmpty);
364
- var notEquals = /*#__PURE__*/curry(function (x, y) {
365
- return x !== y;
366
- });
367
- var isNot = notEquals;
368
- var notEqualsDeep = /*#__PURE__*/complement(equals);
369
- var isNotEqualDeep = notEqualsDeep;
370
-
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 };
395
+ var _removeById = /*#__PURE__*/nullSafe(removeById);
396
+ var _findById = /*#__PURE__*/nullSafe(findById);
397
+ var _replaceById = /*#__PURE__*/nullSafe(replaceById);
398
+ var _modifyById = /*#__PURE__*/nullSafe(modifyById);
399
+ var _findBy = /*#__PURE__*/nullSafe(findBy);
400
+ var _removeBy = /*#__PURE__*/nullSafe(removeBy);
401
+ var _replaceBy = /*#__PURE__*/nullSafe(replaceBy);
402
+ var _modifyBy = /*#__PURE__*/nullSafe(modifyBy);
403
+ var _existsById = /*#__PURE__*/nullSafe(existsById);
404
+ var _existsBy = /*#__PURE__*/nullSafe(existsBy);
405
+ var _findLastBy = /*#__PURE__*/nullSafe(findLastBy);
406
+ var _findIndexById = /*#__PURE__*/nullSafe(findIndexById);
407
+ var _findIndexBy = /*#__PURE__*/nullSafe(findIndexBy);
408
+ var _findLastIndexBy = /*#__PURE__*/nullSafe(findLastIndexBy);
409
+ var _filterBy = /*#__PURE__*/nullSafe(filterBy);
410
+ var _countBy = /*#__PURE__*/nullSafe(countBy);
411
+ var _copyKeys = /*#__PURE__*/nullSafe(copyKeys);
412
+ var _renameKeys = /*#__PURE__*/nullSafe(renameKeys);
413
+ var _copyKeysDeep = /*#__PURE__*/nullSafe(copyKeysDeep);
414
+
415
+ export { _camelToSnakeCase, _capitalize, _copyKeys, _copyKeysDeep, _countBy, _existsBy, _existsById, _filterBy, _filterNonNull, _findBy, _findById, _findIndexBy, _findIndexById, _findLastBy, _findLastIndexBy, _humanize, _modifyBy, _modifyById, _removeBy, _removeById, _renameKeys, _replaceBy, _replaceById, _slugify, _snakeToCamelCase, _truncate, 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, nullSafe, preprocessForSerialization, randomPick, removeBy, removeById, renameKeys, replaceBy, replaceById, serializeKeysToSnakeCase, slugify, snakeToCamelCase, toLabelAndValue, transformObjectDeep, truncate };