@bigbinary/neeto-commons-frontend 2.0.11 → 2.0.13

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 CHANGED
@@ -7,7 +7,7 @@ The commons frontend library for Neeto Applications.
7
7
  Install from npm:
8
8
 
9
9
  ```bash
10
- yarn add "@bigbinary/neeto-commons-frontend@2.0.11"
10
+ yarn add "@bigbinary/neeto-commons-frontend@2.0.13"
11
11
  ```
12
12
 
13
13
  This package relies on the host project's tailwind configuration. So add
@@ -7,12 +7,14 @@ var axios = require('axios');
7
7
  var i18next = require('i18next');
8
8
  var ramda = require('ramda');
9
9
  var reactI18next = require('react-i18next');
10
+ var Logger = require('js-logger');
10
11
  var mixpanel = require('mixpanel-browser');
11
12
 
12
13
  function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
13
14
 
14
15
  var axios__default = /*#__PURE__*/_interopDefaultLegacy(axios);
15
16
  var i18next__default = /*#__PURE__*/_interopDefaultLegacy(i18next);
17
+ var Logger__default = /*#__PURE__*/_interopDefaultLegacy(Logger);
16
18
  var mixpanel__default = /*#__PURE__*/_interopDefaultLegacy(mixpanel);
17
19
 
18
20
  function _typeof(obj) {
@@ -101,6 +103,37 @@ function _slicedToArray(arr, i) {
101
103
  return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest();
102
104
  }
103
105
 
106
+ /**
107
+ * @template {Function} T
108
+ * @param {T} func
109
+ * @returns {T}
110
+ */
111
+
112
+ var nullSafe = function nullSafe(func) {
113
+ return (// @ts-ignore
114
+ ramda.curryN(func.length, function () {
115
+ var _ref;
116
+
117
+ var dataArg = (_ref = func.length - 1, _ref < 0 || arguments.length <= _ref ? undefined : arguments[_ref]);
118
+ return ramda.isNil(dataArg) ? dataArg : func.apply(void 0, arguments);
119
+ })
120
+ );
121
+ };
122
+
123
+ var slugify = function slugify(string) {
124
+ return string.toString().toLowerCase().replace(/\s+/g, "-") // Replace spaces with -
125
+ .replace(/&/g, "-and-") // Replace & with 'and'
126
+ .replace(/[^\w-]+/g, "") // Remove all non-word characters
127
+ .replace(/--+/g, "-") // Replace multiple - with single -
128
+ .replace(/^-+/, "") // Trim - from start of text
129
+ .replace(/-+$/, "");
130
+ }; // Trim - from end of text
131
+
132
+ var humanize = function humanize(string) {
133
+ string = string.replace(/[_-]+/g, " ").replace(/\s{2,}/g, " ").replace(/([a-z\d])([A-Z])/g, "$1" + " " + "$2").replace(/([A-Z]+)([A-Z][a-z\d]+)/g, "$1" + " " + "$2").toLowerCase().trim();
134
+ string = string.charAt(0).toUpperCase() + string.slice(1);
135
+ return string;
136
+ };
104
137
  var snakeToCamelCase = function snakeToCamelCase(string) {
105
138
  return string.replace(/(_\w)/g, function (letter) {
106
139
  return letter[1].toUpperCase();
@@ -111,6 +144,14 @@ var camelToSnakeCase = function camelToSnakeCase(string) {
111
144
  return "_".concat(letter.toLowerCase());
112
145
  });
113
146
  };
147
+ var capitalize = function capitalize(string) {
148
+ return string.charAt(0).toUpperCase() + string.slice(1);
149
+ };
150
+ nullSafe(slugify);
151
+ nullSafe(humanize);
152
+ nullSafe(snakeToCamelCase);
153
+ nullSafe(camelToSnakeCase);
154
+ nullSafe(capitalize);
114
155
 
115
156
  var transformObjectDeep = function transformObjectDeep(object, keyValueTransformer) {
116
157
  var objectPreProcessor = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : undefined;
@@ -157,6 +198,21 @@ var deepFreezeObject = function deepFreezeObject(object) {
157
198
 
158
199
  return object;
159
200
  };
201
+ var filterNonNull = function filterNonNull(object) {
202
+ return Object.fromEntries(Object.entries(object).filter(function (_ref5) {
203
+ var _ref6 = _slicedToArray(_ref5, 2),
204
+ v = _ref6[1];
205
+
206
+ return !ramda.isNil(v);
207
+ }).map(function (_ref7) {
208
+ var _ref8 = _slicedToArray(_ref7, 2),
209
+ k = _ref8[0],
210
+ v = _ref8[1];
211
+
212
+ return [k, _typeof(v) === "object" && !Array.isArray(v) ? filterNonNull(v) : v];
213
+ }));
214
+ };
215
+ nullSafe(filterNonNull);
160
216
 
161
217
  var HEADERS_KEYS = {
162
218
  xAuthEmail: "X-Auth-Email",
@@ -428,6 +484,17 @@ var initializeI18n = function initializeI18n(resources) {
428
484
  });
429
485
  };
430
486
 
487
+ function initializeLogger() {
488
+ /* eslint react-hooks/rules-of-hooks: "off" */
489
+ Logger__default["default"].useDefaults();
490
+
491
+ if (process.env.RAILS_ENV === "production") {
492
+ Logger__default["default"].setLevel(Logger__default["default"].OFF);
493
+ }
494
+
495
+ window.logger = Logger__default["default"];
496
+ }
497
+
431
498
  function initializeMixPanel() {
432
499
  var isProduction = process.env.NODE_ENV === "production";
433
500
  var isTokenPresent = !!process.env.MIXPANEL_TOKEN;
@@ -467,6 +534,7 @@ function initializeApplication(_ref) {
467
534
  }
468
535
 
469
536
  if (!(skip !== null && skip !== void 0 && skip.i18n)) initializeI18n(translationResources);
537
+ if (!(skip !== null && skip !== void 0 && skip.logger)) initializeLogger();
470
538
  }
471
539
 
472
540
  exports["default"] = initializeApplication;
package/initializers.d.ts CHANGED
@@ -6,6 +6,7 @@ type Configurations = {
6
6
  globalProps: boolean;
7
7
  mixpanel: boolean;
8
8
  i18n: boolean;
9
+ logger: boolean;
9
10
  axios: Skippable<{
10
11
  baseURL: boolean;
11
12
  authHeaders: boolean;
package/initializers.js CHANGED
@@ -1,8 +1,9 @@
1
1
  import { Toastr } from '@bigbinary/neetoui';
2
2
  import axios from 'axios';
3
3
  import i18next from 'i18next';
4
- import { values, evolve, omit, modify, mergeDeepLeft, either, isEmpty, isNil } from 'ramda';
4
+ import { curryN, isNil, values, evolve, omit, modify, mergeDeepLeft, either, isEmpty } from 'ramda';
5
5
  import { initReactI18next } from 'react-i18next';
6
+ import Logger from 'js-logger';
6
7
  import mixpanel from 'mixpanel-browser';
7
8
 
8
9
  function _typeof(obj) {
@@ -91,6 +92,37 @@ function _slicedToArray(arr, i) {
91
92
  return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest();
92
93
  }
93
94
 
95
+ /**
96
+ * @template {Function} T
97
+ * @param {T} func
98
+ * @returns {T}
99
+ */
100
+
101
+ var nullSafe = function nullSafe(func) {
102
+ return (// @ts-ignore
103
+ curryN(func.length, function () {
104
+ var _ref;
105
+
106
+ var dataArg = (_ref = func.length - 1, _ref < 0 || arguments.length <= _ref ? undefined : arguments[_ref]);
107
+ return isNil(dataArg) ? dataArg : func.apply(void 0, arguments);
108
+ })
109
+ );
110
+ };
111
+
112
+ var slugify = function slugify(string) {
113
+ return string.toString().toLowerCase().replace(/\s+/g, "-") // Replace spaces with -
114
+ .replace(/&/g, "-and-") // Replace & with 'and'
115
+ .replace(/[^\w-]+/g, "") // Remove all non-word characters
116
+ .replace(/--+/g, "-") // Replace multiple - with single -
117
+ .replace(/^-+/, "") // Trim - from start of text
118
+ .replace(/-+$/, "");
119
+ }; // Trim - from end of text
120
+
121
+ var humanize = function humanize(string) {
122
+ string = string.replace(/[_-]+/g, " ").replace(/\s{2,}/g, " ").replace(/([a-z\d])([A-Z])/g, "$1" + " " + "$2").replace(/([A-Z]+)([A-Z][a-z\d]+)/g, "$1" + " " + "$2").toLowerCase().trim();
123
+ string = string.charAt(0).toUpperCase() + string.slice(1);
124
+ return string;
125
+ };
94
126
  var snakeToCamelCase = function snakeToCamelCase(string) {
95
127
  return string.replace(/(_\w)/g, function (letter) {
96
128
  return letter[1].toUpperCase();
@@ -101,6 +133,14 @@ var camelToSnakeCase = function camelToSnakeCase(string) {
101
133
  return "_".concat(letter.toLowerCase());
102
134
  });
103
135
  };
136
+ var capitalize = function capitalize(string) {
137
+ return string.charAt(0).toUpperCase() + string.slice(1);
138
+ };
139
+ nullSafe(slugify);
140
+ nullSafe(humanize);
141
+ nullSafe(snakeToCamelCase);
142
+ nullSafe(camelToSnakeCase);
143
+ nullSafe(capitalize);
104
144
 
105
145
  var transformObjectDeep = function transformObjectDeep(object, keyValueTransformer) {
106
146
  var objectPreProcessor = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : undefined;
@@ -147,6 +187,21 @@ var deepFreezeObject = function deepFreezeObject(object) {
147
187
 
148
188
  return object;
149
189
  };
190
+ var filterNonNull = function filterNonNull(object) {
191
+ return Object.fromEntries(Object.entries(object).filter(function (_ref5) {
192
+ var _ref6 = _slicedToArray(_ref5, 2),
193
+ v = _ref6[1];
194
+
195
+ return !isNil(v);
196
+ }).map(function (_ref7) {
197
+ var _ref8 = _slicedToArray(_ref7, 2),
198
+ k = _ref8[0],
199
+ v = _ref8[1];
200
+
201
+ return [k, _typeof(v) === "object" && !Array.isArray(v) ? filterNonNull(v) : v];
202
+ }));
203
+ };
204
+ nullSafe(filterNonNull);
150
205
 
151
206
  var HEADERS_KEYS = {
152
207
  xAuthEmail: "X-Auth-Email",
@@ -418,6 +473,17 @@ var initializeI18n = function initializeI18n(resources) {
418
473
  });
419
474
  };
420
475
 
476
+ function initializeLogger() {
477
+ /* eslint react-hooks/rules-of-hooks: "off" */
478
+ Logger.useDefaults();
479
+
480
+ if (process.env.RAILS_ENV === "production") {
481
+ Logger.setLevel(Logger.OFF);
482
+ }
483
+
484
+ window.logger = Logger;
485
+ }
486
+
421
487
  function initializeMixPanel() {
422
488
  var isProduction = process.env.NODE_ENV === "production";
423
489
  var isTokenPresent = !!process.env.MIXPANEL_TOKEN;
@@ -457,6 +523,7 @@ function initializeApplication(_ref) {
457
523
  }
458
524
 
459
525
  if (!(skip !== null && skip !== void 0 && skip.i18n)) initializeI18n(translationResources);
526
+ if (!(skip !== null && skip !== void 0 && skip.logger)) initializeLogger();
460
527
  }
461
528
 
462
529
  export { initializeApplication as default, globalProps$1 as globalProps };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bigbinary/neeto-commons-frontend",
3
- "version": "2.0.11",
3
+ "version": "2.0.13",
4
4
  "description": "A package encapsulating common code across neeto projects including initializers, utility functions, common components and hooks and so on.",
5
5
  "repository": "git@github.com:bigbinary/neeto-commons-frontend.git",
6
6
  "author": "Amaljith K <amaljith.k@bigbinary.com>",
@@ -79,6 +79,7 @@
79
79
  "husky": "^7.0.4",
80
80
  "i18next": "21.7.0",
81
81
  "jest": "27.5.1",
82
+ "js-logger": "^1.6.1",
82
83
  "lint-staged": "^12.3.7",
83
84
  "mixpanel-browser": "^2.45.0",
84
85
  "prettier": "^2.6.2",
@@ -95,7 +96,8 @@
95
96
  "rollup-plugin-analyzer": "^4.0.0",
96
97
  "rollup-plugin-cleaner": "^1.0.0",
97
98
  "rollup-plugin-peer-deps-external": "^2.2.4",
98
- "yup": "^0.32.11"
99
+ "yup": "^0.32.11",
100
+ "zustand": "^4.1.2"
99
101
  },
100
102
  "dependencies": {},
101
103
  "peerDependencies": {
@@ -107,6 +109,7 @@
107
109
  "dayjs": "1.11.1",
108
110
  "formik": "^2.2.9",
109
111
  "i18next": "21.7.0",
112
+ "js-logger": "^1.6.1",
110
113
  "mixpanel-browser": "^2.45.0",
111
114
  "ramda": "^0.28.0",
112
115
  "react": "^17.0.2",
package/pure.cjs.js CHANGED
@@ -75,6 +75,67 @@ function _typeof(obj) {
75
75
  }, _typeof(obj);
76
76
  }
77
77
 
78
+ /**
79
+ * @template {Function} T
80
+ * @param {T} func
81
+ * @returns {T}
82
+ */
83
+
84
+ var nullSafe = function nullSafe(func) {
85
+ return (// @ts-ignore
86
+ ramda.curryN(func.length, function () {
87
+ var _ref;
88
+
89
+ var dataArg = (_ref = func.length - 1, _ref < 0 || arguments.length <= _ref ? undefined : arguments[_ref]);
90
+ return ramda.isNil(dataArg) ? dataArg : func.apply(void 0, arguments);
91
+ })
92
+ );
93
+ };
94
+ var noop = function noop() {};
95
+ var toLabelAndValue = function toLabelAndValue(string) {
96
+ return {
97
+ label: string,
98
+ value: string
99
+ };
100
+ };
101
+ var getRandomInt = function getRandomInt() {
102
+ var a = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : Number.MAX_SAFE_INTEGER;
103
+ var b = arguments.length > 1 ? arguments[1] : undefined;
104
+
105
+ if (b) {
106
+ a = Math.ceil(a);
107
+ b = Math.floor(b);
108
+ } else {
109
+ b = a;
110
+ a = 0;
111
+ }
112
+
113
+ return Math.floor(Math.random() * (b - a) + a);
114
+ };
115
+ var randomPick = function randomPick() {
116
+ for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
117
+ args[_key] = arguments[_key];
118
+ }
119
+
120
+ var randomNumber = getRandomInt(0, args.length);
121
+ return args[randomNumber];
122
+ };
123
+ var dynamicArray = function dynamicArray(count, elementGenerator) {
124
+ return Array.from({
125
+ length: count
126
+ }, function (_, index) {
127
+ return elementGenerator(index);
128
+ });
129
+ };
130
+ var isNotNil = /*#__PURE__*/ramda.complement(ramda.isNil);
131
+ var isNotEmpty = /*#__PURE__*/ramda.complement(ramda.isEmpty);
132
+ var notEquals = /*#__PURE__*/ramda.curry(function (x, y) {
133
+ return x !== y;
134
+ });
135
+ var isNot = notEquals;
136
+ var notEqualsDeep = /*#__PURE__*/ramda.complement(ramda.equals);
137
+ var isNotEqualDeep = notEqualsDeep;
138
+
78
139
  var slugify = function slugify(string) {
79
140
  return string.toString().toLowerCase().replace(/\s+/g, "-") // Replace spaces with -
80
141
  .replace(/&/g, "-and-") // Replace & with 'and'
@@ -105,6 +166,14 @@ var capitalize = function capitalize(string) {
105
166
  var truncate = function truncate(string, length) {
106
167
  return string.length > length ? ramda.concat(ramda.slice(0, length, string), "...") : string;
107
168
  };
169
+ var _slugify = nullSafe(slugify);
170
+ var _humanize = nullSafe(humanize);
171
+ var _snakeToCamelCase = nullSafe(snakeToCamelCase);
172
+ var _camelToSnakeCase = nullSafe(camelToSnakeCase);
173
+ var _capitalize = nullSafe(capitalize);
174
+ var _truncate = function _truncate(string, length) {
175
+ return ramda.isNil(string) ? string : truncate(string, length);
176
+ };
108
177
 
109
178
  var matchesImpl = function matchesImpl(pattern, object) {
110
179
  var __parent = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : object;
@@ -196,6 +265,7 @@ var filterNonNull = function filterNonNull(object) {
196
265
  return [k, _typeof(v) === "object" && !Array.isArray(v) ? filterNonNull(v) : v];
197
266
  }));
198
267
  };
268
+ var _filterNonNull = nullSafe(filterNonNull);
199
269
 
200
270
  function _defineProperty(obj, key, value) {
201
271
  if (key in obj) {
@@ -326,52 +396,52 @@ var copyKeysDeep = /*#__PURE__*/ramda.curry(function (keyMap, objectArray) {
326
396
  return copyKeysSingleObject(object, keyMap);
327
397
  });
328
398
  });
329
-
330
- var noop = function noop() {};
331
- var toLabelAndValue = function toLabelAndValue(string) {
332
- return {
333
- label: string,
334
- value: string
335
- };
336
- };
337
- var getRandomInt = function getRandomInt() {
338
- var a = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : Number.MAX_SAFE_INTEGER;
339
- var b = arguments.length > 1 ? arguments[1] : undefined;
340
-
341
- if (b) {
342
- a = Math.ceil(a);
343
- b = Math.floor(b);
344
- } else {
345
- b = a;
346
- a = 0;
347
- }
348
-
349
- return Math.floor(Math.random() * (b - a) + a);
350
- };
351
- var randomPick = function randomPick() {
352
- for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
353
- args[_key] = arguments[_key];
354
- }
355
-
356
- var randomNumber = getRandomInt(0, args.length);
357
- return args[randomNumber];
358
- };
359
- var dynamicArray = function dynamicArray(count, elementGenerator) {
360
- return Array.from({
361
- length: count
362
- }, function (_, index) {
363
- return elementGenerator(index);
364
- });
365
- };
366
- var isNotNil = /*#__PURE__*/ramda.complement(ramda.isNil);
367
- var isNotEmpty = /*#__PURE__*/ramda.complement(ramda.isEmpty);
368
- var notEquals = /*#__PURE__*/ramda.curry(function (x, y) {
369
- return x !== y;
370
- });
371
- var isNot = notEquals;
372
- var notEqualsDeep = /*#__PURE__*/ramda.complement(ramda.equals);
373
- var isNotEqualDeep = notEqualsDeep;
374
-
399
+ var _removeById = /*#__PURE__*/nullSafe(removeById);
400
+ var _findById = /*#__PURE__*/nullSafe(findById);
401
+ var _replaceById = /*#__PURE__*/nullSafe(replaceById);
402
+ var _modifyById = /*#__PURE__*/nullSafe(modifyById);
403
+ var _findBy = /*#__PURE__*/nullSafe(findBy);
404
+ var _removeBy = /*#__PURE__*/nullSafe(removeBy);
405
+ var _replaceBy = /*#__PURE__*/nullSafe(replaceBy);
406
+ var _modifyBy = /*#__PURE__*/nullSafe(modifyBy);
407
+ var _existsById = /*#__PURE__*/nullSafe(existsById);
408
+ var _existsBy = /*#__PURE__*/nullSafe(existsBy);
409
+ var _findLastBy = /*#__PURE__*/nullSafe(findLastBy);
410
+ var _findIndexById = /*#__PURE__*/nullSafe(findIndexById);
411
+ var _findIndexBy = /*#__PURE__*/nullSafe(findIndexBy);
412
+ var _findLastIndexBy = /*#__PURE__*/nullSafe(findLastIndexBy);
413
+ var _filterBy = /*#__PURE__*/nullSafe(filterBy);
414
+ var _countBy = /*#__PURE__*/nullSafe(countBy);
415
+ var _copyKeys = /*#__PURE__*/nullSafe(copyKeys);
416
+ var _renameKeys = /*#__PURE__*/nullSafe(renameKeys);
417
+ var _copyKeysDeep = /*#__PURE__*/nullSafe(copyKeysDeep);
418
+
419
+ exports._camelToSnakeCase = _camelToSnakeCase;
420
+ exports._capitalize = _capitalize;
421
+ exports._copyKeys = _copyKeys;
422
+ exports._copyKeysDeep = _copyKeysDeep;
423
+ exports._countBy = _countBy;
424
+ exports._existsBy = _existsBy;
425
+ exports._existsById = _existsById;
426
+ exports._filterBy = _filterBy;
427
+ exports._filterNonNull = _filterNonNull;
428
+ exports._findBy = _findBy;
429
+ exports._findById = _findById;
430
+ exports._findIndexBy = _findIndexBy;
431
+ exports._findIndexById = _findIndexById;
432
+ exports._findLastBy = _findLastBy;
433
+ exports._findLastIndexBy = _findLastIndexBy;
434
+ exports._humanize = _humanize;
435
+ exports._modifyBy = _modifyBy;
436
+ exports._modifyById = _modifyById;
437
+ exports._removeBy = _removeBy;
438
+ exports._removeById = _removeById;
439
+ exports._renameKeys = _renameKeys;
440
+ exports._replaceBy = _replaceBy;
441
+ exports._replaceById = _replaceById;
442
+ exports._slugify = _slugify;
443
+ exports._snakeToCamelCase = _snakeToCamelCase;
444
+ exports._truncate = _truncate;
375
445
  exports.camelToSnakeCase = camelToSnakeCase;
376
446
  exports.capitalize = capitalize;
377
447
  exports.copyKeys = copyKeys;
@@ -403,6 +473,7 @@ exports.modifyById = modifyById;
403
473
  exports.noop = noop;
404
474
  exports.notEquals = notEquals;
405
475
  exports.notEqualsDeep = notEqualsDeep;
476
+ exports.nullSafe = nullSafe;
406
477
  exports.preprocessForSerialization = preprocessForSerialization;
407
478
  exports.randomPick = randomPick;
408
479
  exports.removeBy = removeBy;