{"id":13459037,"url":"https://github.com/lukeed/flattie","last_synced_at":"2025-10-09T18:23:42.449Z","repository":{"id":41362218,"uuid":"58668020","full_name":"lukeed/flattie","owner":"lukeed","description":"A tiny (203B) and fast utility to flatten an object with customizable glue","archived":false,"fork":false,"pushed_at":"2024-03-06T21:55:26.000Z","size":46,"stargazers_count":262,"open_issues_count":2,"forks_count":11,"subscribers_count":4,"default_branch":"master","last_synced_at":"2025-03-01T18:20:01.373Z","etag":null,"topics":[],"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/lukeed.png","metadata":{"files":{"readme":"readme.md","changelog":null,"contributing":null,"funding":".github/FUNDING.yml","license":"license","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},"funding":{"github":"lukeed"}},"created_at":"2016-05-12T18:48:49.000Z","updated_at":"2025-02-06T06:25:25.000Z","dependencies_parsed_at":"2024-03-06T22:46:43.835Z","dependency_job_id":null,"html_url":"https://github.com/lukeed/flattie","commit_stats":{"total_commits":64,"total_committers":2,"mean_commits":32.0,"dds":0.015625,"last_synced_commit":"8e1a0c4b8c3e4d87bb00fda153dc0f9d27fca538"},"previous_names":["lukeed/flat-obj"],"tags_count":3,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lukeed%2Fflattie","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lukeed%2Fflattie/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lukeed%2Fflattie/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lukeed%2Fflattie/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/lukeed","download_url":"https://codeload.github.com/lukeed/flattie/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":245308562,"owners_count":20594271,"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":[],"created_at":"2024-07-31T09:01:01.243Z","updated_at":"2025-10-09T18:23:37.402Z","avatar_url":"https://github.com/lukeed.png","language":"JavaScript","funding_links":["https://github.com/sponsors/lukeed"],"categories":["JavaScript"],"sub_categories":[],"readme":"# flattie [![CI](https://github.com/lukeed/flattie/workflows/CI/badge.svg)](https://github.com/lukeed/flattie/actions) [![codecov](https://badgen.now.sh/codecov/c/github/lukeed/flattie)](https://codecov.io/gh/lukeed/flattie)\n\n\u003e A tiny (203B) and [fast](#benchmarks) utility to flatten an object with customizable glue\n\nThis module recursively squashes an Object/Array. The output is a flat object – AKA, it has a single level of depth.\n\nBy default, the `.` character is used to glue/join layers' keys together. This is customizable.\n\nFinally, by default, any keys with nullish values (`null` and `undefined`) are **not** included in the return object.\n\n## Install\n\n```\n$ npm install --save flattie\n```\n\n\n## Usage\n\n```js\nimport { flattie } from 'flattie';\n\nflattie({\n  a: 'hi',\n  b: {\n    a: null,\n    b: ['foo', '', null, 'bar'],\n    d: 'hello',\n    e: {\n      a: 'yo',\n      b: undefined,\n      c: 'sup',\n      d: 0,\n      f: [\n        { foo: 123, bar: 123 },\n        { foo: 465, bar: 456 },\n      ]\n    }\n  },\n  c: 'world'\n});\n// {\n//   'a': 'hi',\n//   'b.b.0': 'foo',\n//   'b.b.1': '',\n//   'b.b.3': 'bar',\n//   'b.d': 'hello',\n//   'b.e.a': 'yo',\n//   'b.e.c': 'sup',\n//   'b.e.d': 0,\n//   'b.e.f.0.foo': 123,\n//   'b.e.f.0.bar': 123,\n//   'b.e.f.1.foo': 465,\n//   'b.e.f.1.bar': 456,\n//   'c': 'world'\n// }\n```\n\n\u003e **Note:** `null` and `undefined` values are purged by default.\n\n## API\n\n### flattie(input, glue?, keepNullish?)\nReturns: `Object`\n\nReturns a new object with a single level of depth.\n\n\u003e **Important:** An object is always returned despite `input` type.\n\n#### input\nType: `Object|Array`\n\nThe object to flatten.\n\n#### glue\nType: `String`\u003cbr\u003e\nDefault: `.`\n\nA string used to join parent key names to nested child key names.\n\n```js\nconst foo = { bar: 123 };\n\nflattie({ foo }); //=\u003e { 'foo.bar': 123 }\nflattie({ foo }, '???'); //=\u003e { 'foo???bar': 123 }\n```\n\n#### keepNullish\nType: `Boolean`\u003cbr\u003e\nDefault: `false`\n\nWhether or not `null` and `undefined` values should be kept.\n\n```js\n// Note: Applies to Objects too\nconst foo = ['hello', null, NaN, undefined, /*hole*/, 'world'];\n\nflattie({ foo });\n//=\u003e {\n//=\u003e   'foo.0': 'hello',\n//=\u003e   'foo.2': NaN,\n//=\u003e   'foo.5': 'world'\n//=\u003e }\n\nflattie({ foo }, '.', true);\n//=\u003e {\n//=\u003e   'foo.0': 'hello',\n//=\u003e   'foo.1': null,\n//=\u003e   'foo.2': NaN,\n//=\u003e   'foo.3': undefined,\n//=\u003e   'foo.4': undefined,\n//=\u003e   'foo.5': 'world'\n//=\u003e }\n```\n\n## Benchmarks\n\n\u003e Running on Node.js v10.13.0\n\n```\nLoad Time:\n  flat             1.047ms\n  flatten-object   1.239ms\n  flat-obj         0.997ms\n  flattie          0.258ms\n\nValidation:\n  ✔ flat\n  ✔ flatten-object\n  ✔ flat-obj\n  ✔ flattie\n\nBenchmark:\n  flat               x 186,487 ops/sec ±1.28% (86 runs sampled)\n  flatten-object     x 199,476 ops/sec ±1.01% (93 runs sampled)\n  flat-obj           x 393,574 ops/sec ±1.41% (95 runs sampled)\n  flattie            x 909,734 ops/sec ±0.82% (93 runs sampled)\n```\n\n\n## Related\n\n* [nestie](https://github.com/lukeed/nestie) – A tiny (242B) and fast utility to expand a flattened object \u003cbr\u003e_This is `flattie`'s reverse / counterpart._\n\n\n## License\n\nMIT © [Luke Edwards](https://lukeed.com)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flukeed%2Fflattie","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Flukeed%2Fflattie","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flukeed%2Fflattie/lists"}