@bigbinary/neeto-commons-frontend 2.0.8 → 2.0.9

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.8"
10
+ yarn add "@bigbinary/neeto-commons-frontend@2.0.9"
11
11
  ```
12
12
 
13
13
  This package relies on the host project's tailwind configuration. So add
@@ -113,9 +113,15 @@ var camelToSnakeCase = function camelToSnakeCase(string) {
113
113
  };
114
114
 
115
115
  var transformObjectDeep = function transformObjectDeep(object, keyValueTransformer) {
116
+ var objectPreProcessor = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : undefined;
117
+
118
+ if (objectPreProcessor && typeof objectPreProcessor === "function") {
119
+ object = objectPreProcessor(object);
120
+ }
121
+
116
122
  if (Array.isArray(object)) {
117
123
  return object.map(function (obj) {
118
- return transformObjectDeep(obj, keyValueTransformer);
124
+ return transformObjectDeep(obj, keyValueTransformer, objectPreProcessor);
119
125
  });
120
126
  } else if (object === null || _typeof(object) !== "object") {
121
127
  return object;
@@ -126,7 +132,7 @@ var transformObjectDeep = function transformObjectDeep(object, keyValueTransform
126
132
  key = _ref4[0],
127
133
  value = _ref4[1];
128
134
 
129
- return keyValueTransformer(key, transformObjectDeep(value, keyValueTransformer));
135
+ return keyValueTransformer(key, transformObjectDeep(value, keyValueTransformer, objectPreProcessor));
130
136
  }));
131
137
  };
132
138
  var keysToCamelCase = function keysToCamelCase(object) {
@@ -135,21 +141,11 @@ var keysToCamelCase = function keysToCamelCase(object) {
135
141
  });
136
142
  };
137
143
  var serializeKeysToSnakeCase = function serializeKeysToSnakeCase(object) {
138
- var serializedObj = typeof (object === null || object === void 0 ? void 0 : object.toJSON) === "function" ? object.toJSON() : object;
139
-
140
- if (Array.isArray(serializedObj)) {
141
- return serializedObj.map(serializeKeysToSnakeCase);
142
- } else if (serializedObj === null || _typeof(serializedObj) !== "object") {
143
- return serializedObj;
144
- }
145
-
146
- return Object.fromEntries(Object.entries(serializedObj).map(function (_ref5) {
147
- var _ref6 = _slicedToArray(_ref5, 2),
148
- key = _ref6[0],
149
- value = _ref6[1];
150
-
151
- return [camelToSnakeCase(key), serializeKeysToSnakeCase(value)];
152
- }));
144
+ return transformObjectDeep(object, function (key, value) {
145
+ return [camelToSnakeCase(key), value];
146
+ }, function (object) {
147
+ return typeof (object === null || object === void 0 ? void 0 : object.toJSON) === "function" ? object.toJSON() : object;
148
+ });
153
149
  };
154
150
  var deepFreezeObject = function deepFreezeObject(object) {
155
151
  if (object && _typeof(object) === "object" && !Object.isFrozen(object)) {
package/initializers.js CHANGED
@@ -103,9 +103,15 @@ var camelToSnakeCase = function camelToSnakeCase(string) {
103
103
  };
104
104
 
105
105
  var transformObjectDeep = function transformObjectDeep(object, keyValueTransformer) {
106
+ var objectPreProcessor = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : undefined;
107
+
108
+ if (objectPreProcessor && typeof objectPreProcessor === "function") {
109
+ object = objectPreProcessor(object);
110
+ }
111
+
106
112
  if (Array.isArray(object)) {
107
113
  return object.map(function (obj) {
108
- return transformObjectDeep(obj, keyValueTransformer);
114
+ return transformObjectDeep(obj, keyValueTransformer, objectPreProcessor);
109
115
  });
110
116
  } else if (object === null || _typeof(object) !== "object") {
111
117
  return object;
@@ -116,7 +122,7 @@ var transformObjectDeep = function transformObjectDeep(object, keyValueTransform
116
122
  key = _ref4[0],
117
123
  value = _ref4[1];
118
124
 
119
- return keyValueTransformer(key, transformObjectDeep(value, keyValueTransformer));
125
+ return keyValueTransformer(key, transformObjectDeep(value, keyValueTransformer, objectPreProcessor));
120
126
  }));
121
127
  };
122
128
  var keysToCamelCase = function keysToCamelCase(object) {
@@ -125,21 +131,11 @@ var keysToCamelCase = function keysToCamelCase(object) {
125
131
  });
126
132
  };
127
133
  var serializeKeysToSnakeCase = function serializeKeysToSnakeCase(object) {
128
- var serializedObj = typeof (object === null || object === void 0 ? void 0 : object.toJSON) === "function" ? object.toJSON() : object;
129
-
130
- if (Array.isArray(serializedObj)) {
131
- return serializedObj.map(serializeKeysToSnakeCase);
132
- } else if (serializedObj === null || _typeof(serializedObj) !== "object") {
133
- return serializedObj;
134
- }
135
-
136
- return Object.fromEntries(Object.entries(serializedObj).map(function (_ref5) {
137
- var _ref6 = _slicedToArray(_ref5, 2),
138
- key = _ref6[0],
139
- value = _ref6[1];
140
-
141
- return [camelToSnakeCase(key), serializeKeysToSnakeCase(value)];
142
- }));
134
+ return transformObjectDeep(object, function (key, value) {
135
+ return [camelToSnakeCase(key), value];
136
+ }, function (object) {
137
+ return typeof (object === null || object === void 0 ? void 0 : object.toJSON) === "function" ? object.toJSON() : object;
138
+ });
143
139
  };
144
140
  var deepFreezeObject = function deepFreezeObject(object) {
145
141
  if (object && _typeof(object) === "object" && !Object.isFrozen(object)) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bigbinary/neeto-commons-frontend",
3
- "version": "2.0.8",
3
+ "version": "2.0.9",
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>",
@@ -81,7 +81,7 @@
81
81
  "lint-staged": "^12.3.7",
82
82
  "mixpanel-browser": "^2.45.0",
83
83
  "prettier": "^2.6.2",
84
- "query-string": "^7.1.1",
84
+ "qs": "^6.11.0",
85
85
  "ramda": "^0.28.0",
86
86
  "react": "^17.0.2",
87
87
  "react-dom": "17.0.2",
package/pure.cjs.js CHANGED
@@ -123,9 +123,15 @@ var matchesImpl = function matchesImpl(pattern, object) {
123
123
  };
124
124
 
125
125
  var transformObjectDeep = function transformObjectDeep(object, keyValueTransformer) {
126
+ var objectPreProcessor = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : undefined;
127
+
128
+ if (objectPreProcessor && typeof objectPreProcessor === "function") {
129
+ object = objectPreProcessor(object);
130
+ }
131
+
126
132
  if (Array.isArray(object)) {
127
133
  return object.map(function (obj) {
128
- return transformObjectDeep(obj, keyValueTransformer);
134
+ return transformObjectDeep(obj, keyValueTransformer, objectPreProcessor);
129
135
  });
130
136
  } else if (object === null || _typeof(object) !== "object") {
131
137
  return object;
@@ -136,7 +142,7 @@ var transformObjectDeep = function transformObjectDeep(object, keyValueTransform
136
142
  key = _ref4[0],
137
143
  value = _ref4[1];
138
144
 
139
- return keyValueTransformer(key, transformObjectDeep(value, keyValueTransformer));
145
+ return keyValueTransformer(key, transformObjectDeep(value, keyValueTransformer, objectPreProcessor));
140
146
  }));
141
147
  };
142
148
  var keysToCamelCase = function keysToCamelCase(object) {
@@ -150,21 +156,18 @@ var keysToSnakeCase = function keysToSnakeCase(object) {
150
156
  });
151
157
  };
152
158
  var serializeKeysToSnakeCase = function serializeKeysToSnakeCase(object) {
153
- var serializedObj = typeof (object === null || object === void 0 ? void 0 : object.toJSON) === "function" ? object.toJSON() : object;
154
-
155
- if (Array.isArray(serializedObj)) {
156
- return serializedObj.map(serializeKeysToSnakeCase);
157
- } else if (serializedObj === null || _typeof(serializedObj) !== "object") {
158
- return serializedObj;
159
- }
160
-
161
- return Object.fromEntries(Object.entries(serializedObj).map(function (_ref5) {
162
- var _ref6 = _slicedToArray(_ref5, 2),
163
- key = _ref6[0],
164
- value = _ref6[1];
165
-
166
- return [camelToSnakeCase(key), serializeKeysToSnakeCase(value)];
167
- }));
159
+ return transformObjectDeep(object, function (key, value) {
160
+ return [camelToSnakeCase(key), value];
161
+ }, function (object) {
162
+ return typeof (object === null || object === void 0 ? void 0 : object.toJSON) === "function" ? object.toJSON() : object;
163
+ });
164
+ };
165
+ var preprocessForSerialization = function preprocessForSerialization(object) {
166
+ return transformObjectDeep(object, function (key, value) {
167
+ return [key, value];
168
+ }, function (object) {
169
+ return typeof (object === null || object === void 0 ? void 0 : object.toJSON) === "function" ? object.toJSON() : object;
170
+ });
168
171
  };
169
172
  var deepFreezeObject = function deepFreezeObject(object) {
170
173
  if (object && _typeof(object) === "object" && !Object.isFrozen(object)) {
@@ -180,15 +183,15 @@ var matches = /*#__PURE__*/ramda.curry(function (pattern, object) {
180
183
  return matchesImpl(pattern, object);
181
184
  });
182
185
  var filterNonNull = function filterNonNull(object) {
183
- return Object.fromEntries(Object.entries(object).filter(function (_ref7) {
184
- var _ref8 = _slicedToArray(_ref7, 2),
185
- v = _ref8[1];
186
+ return Object.fromEntries(Object.entries(object).filter(function (_ref5) {
187
+ var _ref6 = _slicedToArray(_ref5, 2),
188
+ v = _ref6[1];
186
189
 
187
190
  return !ramda.isNil(v);
188
- }).map(function (_ref9) {
189
- var _ref10 = _slicedToArray(_ref9, 2),
190
- k = _ref10[0],
191
- v = _ref10[1];
191
+ }).map(function (_ref7) {
192
+ var _ref8 = _slicedToArray(_ref7, 2),
193
+ k = _ref8[0],
194
+ v = _ref8[1];
192
195
 
193
196
  return [k, _typeof(v) === "object" && !Array.isArray(v) ? filterNonNull(v) : v];
194
197
  }));
@@ -400,6 +403,7 @@ exports.modifyById = modifyById;
400
403
  exports.noop = noop;
401
404
  exports.notEquals = notEquals;
402
405
  exports.notEqualsDeep = notEqualsDeep;
406
+ exports.preprocessForSerialization = preprocessForSerialization;
403
407
  exports.randomPick = randomPick;
404
408
  exports.removeBy = removeBy;
405
409
  exports.removeById = removeById;
package/pure.d.ts CHANGED
@@ -170,6 +170,7 @@ export function replaceById<T>(id: any, entityArray: T[]): T[];
170
170
  export function replaceById(id: any): <T>(entityArray: T[]) => T[];
171
171
 
172
172
  export function serializeKeysToSnakeCase(object: object): object;
173
+ export function preprocessForSerialization(object: object): object;
173
174
  export function slugify(string: string): string;
174
175
  export function snakeToCamelCase(string: string): string;
175
176
  export function toLabelAndValue(string: string): {
@@ -178,7 +179,8 @@ export function toLabelAndValue(string: string): {
178
179
  };
179
180
  export function transformObjectDeep(
180
181
  object: object,
181
- keyValueTransformer: (key: string | number | symbol, object: any) => any[]
182
+ keyValueTransformer: (key: string | number | symbol, object: any) => any[],
183
+ objectPreProcessor?: (object: any) => any
182
184
  ): object;
183
185
 
184
186
  export function truncate(string: string, length: number): string;
package/pure.js CHANGED
@@ -119,9 +119,15 @@ var matchesImpl = function matchesImpl(pattern, object) {
119
119
  };
120
120
 
121
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
+
122
128
  if (Array.isArray(object)) {
123
129
  return object.map(function (obj) {
124
- return transformObjectDeep(obj, keyValueTransformer);
130
+ return transformObjectDeep(obj, keyValueTransformer, objectPreProcessor);
125
131
  });
126
132
  } else if (object === null || _typeof(object) !== "object") {
127
133
  return object;
@@ -132,7 +138,7 @@ var transformObjectDeep = function transformObjectDeep(object, keyValueTransform
132
138
  key = _ref4[0],
133
139
  value = _ref4[1];
134
140
 
135
- return keyValueTransformer(key, transformObjectDeep(value, keyValueTransformer));
141
+ return keyValueTransformer(key, transformObjectDeep(value, keyValueTransformer, objectPreProcessor));
136
142
  }));
137
143
  };
138
144
  var keysToCamelCase = function keysToCamelCase(object) {
@@ -146,21 +152,18 @@ var keysToSnakeCase = function keysToSnakeCase(object) {
146
152
  });
147
153
  };
148
154
  var serializeKeysToSnakeCase = function serializeKeysToSnakeCase(object) {
149
- var serializedObj = typeof (object === null || object === void 0 ? void 0 : object.toJSON) === "function" ? object.toJSON() : object;
150
-
151
- if (Array.isArray(serializedObj)) {
152
- return serializedObj.map(serializeKeysToSnakeCase);
153
- } else if (serializedObj === null || _typeof(serializedObj) !== "object") {
154
- return serializedObj;
155
- }
156
-
157
- return Object.fromEntries(Object.entries(serializedObj).map(function (_ref5) {
158
- var _ref6 = _slicedToArray(_ref5, 2),
159
- key = _ref6[0],
160
- value = _ref6[1];
161
-
162
- return [camelToSnakeCase(key), serializeKeysToSnakeCase(value)];
163
- }));
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
+ });
164
167
  };
165
168
  var deepFreezeObject = function deepFreezeObject(object) {
166
169
  if (object && _typeof(object) === "object" && !Object.isFrozen(object)) {
@@ -176,15 +179,15 @@ var matches = /*#__PURE__*/curry(function (pattern, object) {
176
179
  return matchesImpl(pattern, object);
177
180
  });
178
181
  var filterNonNull = function filterNonNull(object) {
179
- return Object.fromEntries(Object.entries(object).filter(function (_ref7) {
180
- var _ref8 = _slicedToArray(_ref7, 2),
181
- v = _ref8[1];
182
+ return Object.fromEntries(Object.entries(object).filter(function (_ref5) {
183
+ var _ref6 = _slicedToArray(_ref5, 2),
184
+ v = _ref6[1];
182
185
 
183
186
  return !isNil(v);
184
- }).map(function (_ref9) {
185
- var _ref10 = _slicedToArray(_ref9, 2),
186
- k = _ref10[0],
187
- v = _ref10[1];
187
+ }).map(function (_ref7) {
188
+ var _ref8 = _slicedToArray(_ref7, 2),
189
+ k = _ref8[0],
190
+ v = _ref8[1];
188
191
 
189
192
  return [k, _typeof(v) === "object" && !Array.isArray(v) ? filterNonNull(v) : v];
190
193
  }));
@@ -365,4 +368,4 @@ var isNot = notEquals;
365
368
  var notEqualsDeep = /*#__PURE__*/complement(equals);
366
369
  var isNotEqualDeep = notEqualsDeep;
367
370
 
368
- 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 };
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 };