{"id":19658222,"url":"https://github.com/cdaringe/primitivify","last_synced_at":"2025-04-30T21:46:43.407Z","repository":{"id":37271155,"uuid":"217631053","full_name":"cdaringe/primitivify","owner":"cdaringe","description":"deep copy data keeping only primitives in nested data structures","archived":false,"fork":false,"pushed_at":"2025-01-03T21:59:10.000Z","size":690,"stargazers_count":0,"open_issues_count":1,"forks_count":0,"subscribers_count":3,"default_branch":"main","last_synced_at":"2025-01-06T18:36:33.032Z","etag":null,"topics":["clone","json","primitives","serialization","stringify"],"latest_commit_sha":null,"homepage":"","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/cdaringe.png","metadata":{"files":{"readme":"readme.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2019-10-25T23:54:58.000Z","updated_at":"2025-01-03T21:58:37.000Z","dependencies_parsed_at":"2024-01-15T18:43:03.857Z","dependency_job_id":"a315641d-84bf-4841-810a-00c146f0db74","html_url":"https://github.com/cdaringe/primitivify","commit_stats":{"total_commits":538,"total_committers":4,"mean_commits":134.5,"dds":0.06505576208178443,"last_synced_commit":"79d79ddec5c38fe2f27150d0c72155e0fce236fd"},"previous_names":[],"tags_count":11,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cdaringe%2Fprimitivify","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cdaringe%2Fprimitivify/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cdaringe%2Fprimitivify/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cdaringe%2Fprimitivify/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/cdaringe","download_url":"https://codeload.github.com/cdaringe/primitivify/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":233279541,"owners_count":18652172,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["clone","json","primitives","serialization","stringify"],"created_at":"2024-11-11T15:36:34.110Z","updated_at":"2025-01-10T00:58:32.137Z","avatar_url":"https://github.com/cdaringe.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# primitivify\n\ndeep copy data keeping only primitives in nested data structures. useful for serializing complex objects where you only care about the raw data contained within.\n\n\"primitive-ify\"\n\n[![TypeScript package](https://img.shields.io/badge/language-typescript-blue)](https://www.typescriptlang.org)\n[![semantic-release](https://img.shields.io/badge/%20%20%F0%9F%93%A6%F0%9F%9A%80-semantic--release-e10079.svg)](https://github.com/semantic-release/semantic-release)\n\n## install\n\n`npm install --save primitivify`\n\n## usage\n\nthe best demonstration of the value of this module is exemplified from the tests!\n\n```ts\nimport primitivify from \"primitivify\";\nconst dummyFn = () =\u003e {};\nconst complex = {\n  dummyFn,\n  a: {\n    b: {\n      c: setTimeout(() =\u003e {}, 0),\n    },\n    d: setInterval(dummyFn, 1e3),\n  },\n  b: [dummyFn, \"wee\", { e: \"e\" }],\n};\nt.deepEqual(\n  {\n    // observe how non-primitive datas are nulled away\n    dummyFn: null,\n    a: {\n      b: {\n        c: null,\n      },\n      d: null,\n    },\n    b: [null, \"wee\", { e: \"e\" }],\n  },\n  primitivify(complexObj),\n  \"complex\"\n);\n```\n\nprimitivify is immutable--calls return deeply cloned values.\n\nneed a _custom_ serializer? use the 2nd argument, `onVisit`, to transform the current value being inspected:\n\n```ts\nprimitivify(\n  { a: () =\u003e {} },\n  v =\u003e typeof v === 'function' ? 'wee' : v)\n)\n// { a: 'wee' }\n```\n\n### why\n\ngenerally to decomplect objects and/or arrays. consinder a simple example:\n\n```js\nJSON.stringify({ usefulData: \"beep\", a: setTimeout(() =\u003e {}, 0) });\n\n/*\nThrown:\nTypeError: Converting circular structure to JSON\n    --\u003e starting at object with constructor 'Timeout'\n    |     property '_idlePrev' -\u003e object with constructor 'TimersList'\n    --- property '_idleNext' closes the circle\n    at JSON.stringify (\u003canonymous\u003e)\n*/\n\nJSON.stringify(primitivify({ a: setTimeout(() =\u003e {}, 0) }));\n/*\n'{\"usefulData\":\"beep\",\"a\":null}'\n*/\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcdaringe%2Fprimitivify","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcdaringe%2Fprimitivify","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcdaringe%2Fprimitivify/lists"}