@8ms/helpers 1.1.112 → 1.1.113

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.
@@ -0,0 +1,10 @@
1
+ declare type ReplaceKeys = {
2
+ instance: any;
3
+ getNewKey: Function;
4
+ };
5
+ /**
6
+ * Iteratively replace all the keys in an object.
7
+ * https://www.techighness.com/post/replace-all-keys-of-deeply-nested-objects-or-array-of-objects/
8
+ */
9
+ declare const replaceKeys: ({ instance, getNewKey }: ReplaceKeys) => object;
10
+ export default replaceKeys;
@@ -0,0 +1,30 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ /**
4
+ * Iteratively replace all the keys in an object.
5
+ * https://www.techighness.com/post/replace-all-keys-of-deeply-nested-objects-or-array-of-objects/
6
+ */
7
+ const replaceKeys = ({ instance, getNewKey }) => {
8
+ let response = instance;
9
+ if (Array.isArray(instance)) {
10
+ response = [];
11
+ for (let i = 0; i < instance.length; i++) {
12
+ response[i] = replaceKeys({
13
+ instance: instance[i],
14
+ getNewKey,
15
+ });
16
+ }
17
+ }
18
+ else if ("object" === typeof instance) {
19
+ response = {};
20
+ for (const key in instance) {
21
+ const newKey = getNewKey(key);
22
+ response[newKey] = replaceKeys({
23
+ instance: instance[key],
24
+ getNewKey,
25
+ });
26
+ }
27
+ }
28
+ return response;
29
+ };
30
+ exports.default = replaceKeys;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@8ms/helpers",
3
3
  "license": "UNLICENSED",
4
- "version": "1.1.112",
4
+ "version": "1.1.113",
5
5
  "repository": {
6
6
  "type": "git",
7
7
  "url": "git+https://github.com/8millionstories-organisation/8ms-helpers-ts.git"