{"id":20993041,"url":"https://github.com/jessie-codes/safe-flat","last_synced_at":"2025-05-14T20:33:25.769Z","repository":{"id":44979518,"uuid":"182582700","full_name":"jessie-codes/safe-flat","owner":"jessie-codes","description":"Safely flatten a nested JavaScript object.","archived":false,"fork":false,"pushed_at":"2024-09-19T05:42:36.000Z","size":458,"stargazers_count":5,"open_issues_count":1,"forks_count":8,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-04-17T22:42:16.233Z","etag":null,"topics":["flat","javascript","nodejs"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/jessie-codes.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":"CODE_OF_CONDUCT.md","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-04-21T21:09:41.000Z","updated_at":"2024-09-19T05:42:39.000Z","dependencies_parsed_at":"2024-06-18T17:08:25.471Z","dependency_job_id":"136f48a5-53e9-4323-861f-29339ddb124e","html_url":"https://github.com/jessie-codes/safe-flat","commit_stats":{"total_commits":53,"total_committers":7,"mean_commits":7.571428571428571,"dds":"0.26415094339622647","last_synced_commit":"205208feaccbb5f4154da90d12b4d345d3e770dc"},"previous_names":[],"tags_count":9,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jessie-codes%2Fsafe-flat","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jessie-codes%2Fsafe-flat/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jessie-codes%2Fsafe-flat/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jessie-codes%2Fsafe-flat/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/jessie-codes","download_url":"https://codeload.github.com/jessie-codes/safe-flat/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254222539,"owners_count":22034895,"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":["flat","javascript","nodejs"],"created_at":"2024-11-19T07:13:33.403Z","updated_at":"2025-05-14T20:33:25.512Z","avatar_url":"https://github.com/jessie-codes.png","language":"JavaScript","readme":"# safe-flat\n\u003e Safely flatten a nested JavaScript object.\n\n[![NPM](https://nodei.co/npm/safe-flat.png?compact=true)](https://nodei.co/npm/safe-flat/)\n\n[![Commitizen friendly](https://img.shields.io/badge/commitizen-friendly-brightgreen.svg)](http://commitizen.github.io/cz-cli/)\n[![js-standard-style](https://img.shields.io/badge/code%20style-standard-brightgreen.svg)](http://standardjs.com)\n[![Coverage](https://coveralls.io/repos/github/jessie-codes/safe-flat/badge.svg?branch=master)](https://coveralls.io/github/jessie-codes/safe-flat?branch=master)\n[![Known Vulnerabilities](https://snyk.io/test/github/jessie-codes/safe-flat/badge.svg)](https://snyk.io/test/github/jessie-codes/safe-flat)\n\n## Installation\n\n``` bash\n$ npm i safe-flat\n```\n\n## Methods\n\n### flatten(obj, [delimiter])\n\nFlattens an object to one level deep. Optionally takes a custom `delimiter`, otherwise uses `.` by default. Circular references within the object will be replaced with `[Circular]`.\n\n``` javascript\nconst { flatten } = require('safe-flat')\n\nconst original = {\n    a: {\n        b: {\n            c: [{\n                val: 'one'\n            }, {\n                val: 'two'\n            }],\n            d: 'three'\n        },\n        e: 'four',\n    }\n}\noriginal.a.b.f = original.a.b\noriginal.a.b.c.push(original.a)\n\nconst flat = flatten(original)\n/*\n{\n  'a.b.c.0.val': 'one',\n  'a.b.c.1.val': 'two',\n  'a.b.c.2': '[Circular]',\n  'a.b.d': 'three',\n  'a.e': 'four',\n  'a.b.f': '[Circular]'\n}\n*/\n\nconst underscoreFlat = flatten(original, '_')\n/*\n{\n  'a_b_c_0_val': 'one',\n  'a_b_c_1_val': 'two',\n  'a_b_c_2': '[Circular]',\n  'a_b_d': 'three',\n  'a_e': 'four',\n  'a_b_f': '[Circular]'\n}\n*/\n```\n### unflatten(obj, [delimiter])\n\nUnflattens an object back to its original nested form. Optionally takes a custom `delimiter`, otherwise uses `.` by default. Circular references denoted by `[Circular]` are treated as Strings.\n\n``` javascript\nconst { unflatten } = require('safe-flat')\n\nconst original = {\n    'a.b.c.0.val': 'one',\n    'a.b.c.1.val': 'two',\n    'a.b.c.2': '[Circular]',\n    'a.b.d': 'three',\n    'a.e': 'four',\n    'a.b.f': '[Circular]'\n}\n\n\nconst unflat = unflatten(original)\n\n/*{\n  a:{\n    b:{\n      c:[\n        {\n          val:'one'\n        },\n        {\n          val:'two'\n        },\n        '[Circular]'\n      ],\n      d:'three',\n      f:'[Circular]'\n    },\n    e:'four'\n  }\n}*/\n```\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjessie-codes%2Fsafe-flat","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjessie-codes%2Fsafe-flat","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjessie-codes%2Fsafe-flat/lists"}