aboutsummaryrefslogtreecommitdiffstats
path: root/app/scripts/lib/getObjStructure.js
diff options
context:
space:
mode:
authorDan Finlay <542863+danfinlay@users.noreply.github.com>2018-04-25 00:51:18 +0800
committerGitHub <noreply@github.com>2018-04-25 00:51:18 +0800
commitac334d7b1a9cd8b6888f5c4f3309740d5df62474 (patch)
tree7498f29e899821d879b3f68a42b8995f42f80321 /app/scripts/lib/getObjStructure.js
parent66ae4a948abbebdb513f9bd60d47fda36095e8df (diff)
parent0fbd389a509a2447d833192bbe854c586890d512 (diff)
downloadtangerine-wallet-browser-ac334d7b1a9cd8b6888f5c4f3309740d5df62474.tar
tangerine-wallet-browser-ac334d7b1a9cd8b6888f5c4f3309740d5df62474.tar.gz
tangerine-wallet-browser-ac334d7b1a9cd8b6888f5c4f3309740d5df62474.tar.bz2
tangerine-wallet-browser-ac334d7b1a9cd8b6888f5c4f3309740d5df62474.tar.lz
tangerine-wallet-browser-ac334d7b1a9cd8b6888f5c4f3309740d5df62474.tar.xz
tangerine-wallet-browser-ac334d7b1a9cd8b6888f5c4f3309740d5df62474.tar.zst
tangerine-wallet-browser-ac334d7b1a9cd8b6888f5c4f3309740d5df62474.zip
Merge pull request #4040 from MetaMask/dm-docs-2
Even more documentation for various controllers and libs.
Diffstat (limited to 'app/scripts/lib/getObjStructure.js')
-rw-r--r--app/scripts/lib/getObjStructure.js17
1 files changed, 17 insertions, 0 deletions
diff --git a/app/scripts/lib/getObjStructure.js b/app/scripts/lib/getObjStructure.js
index 3db389507..52250d3fb 100644
--- a/app/scripts/lib/getObjStructure.js
+++ b/app/scripts/lib/getObjStructure.js
@@ -14,6 +14,15 @@ module.exports = getObjStructure
// }
// }
+/**
+ * Creates an object that represents the structure of the given object. It replaces all values with the result of their
+ * type.
+ *
+ * @param {object} obj The object for which a 'structure' will be returned. Usually a plain object and not a class.
+ * @returns {object} The "mapped" version of a deep clone of the passed object, with each non-object property value
+ * replaced with the javascript type of that value.
+ *
+ */
function getObjStructure(obj) {
const structure = clone(obj)
return deepMap(structure, (value) => {
@@ -21,6 +30,14 @@ function getObjStructure(obj) {
})
}
+/**
+ * Modifies all the properties and deeply nested of a passed object. Iterates recursively over all nested objects and
+ * their properties, and covers the entire depth of the object. At each property value which is not an object is modified.
+ *
+ * @param {object} target The object to modify
+ * @param {Function} visit The modifier to apply to each non-object property value
+ * @returns {object} The modified object
+ */
function deepMap(target = {}, visit) {
Object.entries(target).forEach(([key, value]) => {
if (typeof value === 'object' && value !== null) {