{"_id":"@allnulled/jsontyped-reducer","name":"@allnulled/jsontyped-reducer","dist-tags":{"latest":"1.0.1"},"versions":{"1.0.1":{"name":"@allnulled/jsontyped-reducer","version":"1.0.1","description":"Reduces recusively JSON objects with $type property through customizable reducers. Uses JSON.stringify.","main":"jsontyped-reducer.js","scripts":{"build":"npx htmlbundler --list bundlelist.js --output dist/jsontyped-reducer.bundled.js --id false --module false --wrap false && cp jsontyped-reducer.js dist/jsontyped-reducer.unbundled.js","test":"npx mocha test.js"},"keywords":["json","extension","jsontyped"],"author":{"name":"allnulled"},"license":"WTFPL","gitHead":"20fd5ebc633065cab78fd4c6ed014dc2ab46953a","_id":"@allnulled/jsontyped-reducer@1.0.1","_nodeVersion":"18.17.1","_npmVersion":"9.6.7","dist":{"integrity":"sha512-7TVrjwEzif+eGbwxin9OaAC26n8Cx14fWqaqCsKDZHsCki00u7TozIvh77J3dLnfumeuEK9+oNLgZo3V2NvY2A==","shasum":"486c495525e720ceebb4d65206cf4a872a0e3fe8","tarball":"https://registry.npmjs.org/@allnulled/jsontyped-reducer/-/jsontyped-reducer-1.0.1.tgz","fileCount":9,"unpackedSize":85026,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEQCIFiYYj8kpcCDrYytxwaX8WpqlU0vVWEJngzEbnzMDmjQAiBzZfU8r8h9JFD2jRPSCp7m2dPXve+5gs1JI9zpbcuS2w=="}]},"_npmUser":{"name":"allnulled","email":"todosanulados@gmail.com"},"directories":{},"maintainers":[{"name":"allnulled","email":"todosanulados@gmail.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages-npm-production","tmp":"tmp/jsontyped-reducer_1.0.1_1735448481239_0.8753783621968201"},"_hasShrinkwrap":false}},"time":{"created":"2024-12-29T05:01:21.144Z","1.0.1":"2024-12-29T05:01:21.468Z","modified":"2024-12-29T05:01:21.809Z"},"maintainers":[{"name":"allnulled","email":"todosanulados@gmail.com"}],"description":"Reduces recusively JSON objects with $type property through customizable reducers. Uses JSON.stringify.","keywords":["json","extension","jsontyped"],"author":{"name":"allnulled"},"license":"WTFPL","readme":"# jsontyped-reducer\n\nReduces recusively JSON objects with $type property through customizable reducers. Uses JSON.stringify.\n\n## Installation\n\n```sh\nnpm i -s @allnulled/jsontyped-reducer\n```\n\n## Importation\n\nIn node.js:\n\n```js\nrequire(\"@allnulled/jsontyped-reducer\")\n```\n\nIn browser:\n\n```html\n<script src=\"node_modules/@allnulled/jsontyped-reducer/jsontyped-reducer.js\"></script>\n```\n\n## Usage\n\nThis is the current test.\n\n```js\nrequire(__dirname + \"/jsontyped-reducer.js\");\n\ndescribe(\"JsontypedReducer API Test\", function () {\n  it(\"can reduce types as expected in test 1\", async function () {\n    try {\n      console.log(JsontypedReducer.reduce([{\n        $type: \"sumar\",\n        $operands: [\"a\", \"b\", \"c\"],\n        a: 1,\n        b: 2,\n        c: 3\n      },\n      {\n        $type: \"restar\",\n        $operands: [\"c\", \"b\", \"a\"],\n        a: 1,\n        b: 2,\n        c: 3\n      }\n      ], [\n        function (node) {\n          if (node.$type === \"sumar\") {\n            return node.$operands.reduce((out, it) => {\n              out += node[it];\n              return out;\n            }, 0);\n          }\n        },\n        function (node) {\n          if (node.$type === \"restar\") {\n            return node.$operands.reduce((out, it) => {\n              out -= node[it];\n              return out;\n            }, 0);\n          }\n        },\n      ]));\n    } catch (error) {\n      console.log(error);\n    }\n  });\n});\n\ndescribe(\"JsontypedReducer API Test\", function () {\n  it(\"can reduce types as expected in test 2\", async function () {\n    try {\n      const input = {\n        data: [\n          { $type: \"sumar\", $operands: [\"a\", \"b\", \"c\"], a: 1, b: 2, c: 3 },\n          { $type: \"restar\", $operands: [\"c\", \"b\", \"a\"], a: 1, b: 2, c: 3 },\n          { randomKey: \"no debería cambiar\" },\n        ],\n        nested: {\n          another: {\n            $type: \"sumar\",\n            $operands: [\"x\", \"y\"],\n            x: 10,\n            y: 20,\n          },\n        },\n      };\n\n      const reducers = [\n        function (node) {\n          if (node.$type === \"sumar\") {\n            return node.$operands.reduce((out, it) => out + (node[it] || 0), 0);\n          }\n        },\n        function (node) {\n          if (node.$type === \"restar\") {\n            return node.$operands.reduce((out, it) => out - (node[it] || 0), 0);\n          }\n        },\n      ];\n\n      const result = JsontypedReducer.reduce(input, reducers);\n      console.log(result);\n    } catch (error) {\n      console.error(error);\n    }\n  });\n});\n```\n\n## Notes\n\nNote: this project is **TOTALLY PROGRAMMATICALLY** independant from [jsontyped](https://github.com/allnulled/jsontyped/blob/main/jsontyped.js). However, the *bundled* version of this module ships with [jsontyped](https://github.com/allnulled/jsontyped/blob/main/jsontyped.js). Absolutely unnecesarily, you can choose a lighter version with the *unbundled* file.","readmeFilename":"README.md"}