{"library":"map2tree","title":"map2tree","description":"map2tree is a utility library that provides a pure function to convert a flat map structure into a hierarchical tree. Its primary use case is within the `redux-devtools-chart-monitor` package, influencing its specific opinions on how data is transformed. It does not convert objects and arrays deeply nested within collections into tree structures and offers support for Immutable.js List and Map data types. The current stable version, 4.0.0, was released as an ESM-only package. The library is part of the `reduxjs/redux-devtools` monorepo, suggesting its release cadence is tied to the broader Redux DevTools ecosystem.","language":"javascript","status":"active","last_verified":"Sun Apr 19","install":{"commands":["npm install map2tree"],"cli":null},"imports":["import map2tree from 'map2tree';"],"auth":{"required":false,"env_vars":[]},"quickstart":{"code":"import map2tree from 'map2tree';\n\nconst someMap = {\n  someReducer: {\n    todos: [\n      { title: 'map', someNestedObject: { foo: 'bar' } },\n      { title: 'to', someNestedArray: ['foo', 'bar'] },\n      { title: 'tree' },\n      { title: 'map2tree' },\n    ],\n    completedCount: 1,\n  },\n  otherReducer: {\n    foo: 0,\n    bar: { key: 'value' },\n  },\n};\n\nconst treeOutput = map2tree(someMap, {\n  key: 'state', // the name you want for the root node of the output tree\n  pushMethod: 'push', // use 'unshift' to change the order children nodes are added\n});\n\nconsole.log(JSON.stringify(treeOutput, null, 2));\n/*\nOutput example:\n{\n  \"name\": \"state\",\n  \"children\": [\n    {\n      \"name\": \"someReducer\",\n      \"children\": [\n        {\n          \"name\": \"todos\",\n          \"children\": [\n            {\n              \"name\": \"todo[0]\",\n              \"object\": {\n                \"title\": \"map\",\n                \"someNestedObject\": {\n                  \"foo\": \"bar\"\n                }\n              }\n            },\n            {\n              \"name\": \"todo[1]\",\n              \"object\": {\n                \"title\": \"to\",\n                \"someNestedArray\": [\n                  \"foo\",\n                  \"bar\"\n                ]\n              }\n            },\n            {\n              \"name\": \"todo[2]\",\n              \"object\": {\n                \"title\": \"tree\"\n              }\n            },\n            {\n              \"name\": \"todo[3]\",\n              \"object\": {\n                \"title\": \"map2tree\"\n              }\n            }\n          ]\n        },\n        {\n          \"name\": \"completedCount\",\n          \"value\": 1\n        }\n      ]\n    },\n    {\n      \"name\": \"otherReducer\",\n      \"children\": [\n        {\n          \"name\": \"foo\",\n          \"value\": 0\n        },\n        {\n          \"name\": \"bar\",\n          \"object\": {\n            \"key\": \"value\"\n          }\n        }\n      ]\n    }\n  ]\n}\n*/","lang":"typescript","description":"Demonstrates how to import and use `map2tree` with a sample map, specifying root key and child order, and logs the resulting tree structure.","tag":null,"tag_description":null,"last_tested":null,"results":[]},"compatibility":null}