{"id":10903,"library":"flattie","title":"Flattie Object Flattening Utility","description":"Flattie is a minimalist and highly performant JavaScript utility for recursively flattening nested objects and arrays into a single-depth object. Currently at version 1.1.1, the library maintains a stable release cadence with incremental patches. Its core differentiators include its extremely small bundle size (203B), demonstrated speed via benchmarks against alternatives like `flat` and `flatten-object`, and customizable behavior for key concatenation via a 'glue' string. By default, it automatically omits nullish values (`null`, `undefined`) from the flattened output, a feature that can be toggled. It also ships with TypeScript type definitions, providing a robust developer experience. Its counterpart, `nestie`, provides the reverse operation (expanding flattened objects).","status":"active","version":"1.1.1","language":"javascript","source_language":"en","source_url":"https://github.com/lukeed/flattie","tags":["javascript","keys","flatten","object","nested","flat","typescript"],"install":[{"cmd":"npm install flattie","lang":"bash","label":"npm"},{"cmd":"yarn add flattie","lang":"bash","label":"yarn"},{"cmd":"pnpm add flattie","lang":"bash","label":"pnpm"}],"dependencies":[],"imports":[{"note":"The primary flattening function is a named export. It is not a default export, and CommonJS `require` should use destructuring.","wrong":"import flattie from 'flattie';\nconst flattie = require('flattie');","symbol":"flattie","correct":"import { flattie } from 'flattie';"}],"quickstart":{"code":"import { flattie } from 'flattie';\n\nconst nestedObject = {\n  user: 'alice',\n  profile: {\n    email: 'alice@example.com',\n    settings: {\n      theme: 'dark',\n      notifications: true,\n      preferences: [\n        { id: 1, value: 'optionA' },\n        { id: 2, value: null },\n        { id: 3, value: 'optionC' }\n      ]\n    }\n  },\n  status: null,\n  tags: ['admin', 'premium']\n};\n\n// Flatten the object with default glue ('.') and nullish purging (true)\nconst flatDefault = flattie(nestedObject);\nconsole.log('Default Flattened:', flatDefault);\n\n// Flatten the object keeping nullish values\nconst flatKeepNullish = flattie(nestedObject, '.', true);\nconsole.log('Flattened (keeping nullish):', flatKeepNullish);\n\n// Flatten the object with a custom glue\nconst flatCustomGlue = flattie(nestedObject, '__');\nconsole.log('Flattened (custom glue):', flatCustomGlue);","lang":"typescript","description":"Demonstrates basic object flattening, custom glue usage, and how to retain nullish values."},"warnings":[{"fix":"To retain nullish values, pass `true` as the third argument to the `flattie` function: `flattie(input, glue, true)`.","message":"By default, `null` and `undefined` values are automatically excluded from the flattened output. This behavior might be unexpected if you intend to preserve all original data points.","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"Be aware that the output format is consistently an object. If an array is desired, a post-processing step to convert the flattened object back into an array structure would be necessary.","message":"Flattie always returns a new object, even if the input is an array. Array elements will be mapped to keys using their numerical indices combined with the specified glue string.","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"If specific handling for empty strings, `NaN`, or other non-nullish but undesirable values is required, implement custom pre-processing on the input or post-processing on the flattened output.","message":"While `null` and `undefined` are purged, other 'empty' or special values like empty strings (`''`) or `NaN` are preserved in the output by default.","severity":"gotcha","affected_versions":">=1.0.0"}],"env_vars":null,"last_verified":"2026-04-19T00:00:00.000Z","next_check":"2026-07-18T00:00:00.000Z","problems":[{"fix":"For ESM, use `import { flattie } from 'flattie';`. For CommonJS, use `const { flattie } = require('flattie');`.","cause":"Attempting to import `flattie` as a default export or using `require()` without destructuring in a CommonJS environment. The `flattie` function is a named export.","error":"TypeError: flattie is not a function"},{"fix":"Ensure the `input` provided to `flattie` is a valid JavaScript object or array. Verify your Node.js version is `>=8` as specified in the package engines.","cause":"This error typically indicates an issue with an object not being a plain object or potential environment incompatibility, though less common with `flattie`'s focused scope. It might occur if `input` is a primitive or a highly custom object lacking standard `Object.prototype` methods.","error":"Object.prototype.hasOwnProperty.call is not a function"}],"ecosystem":"npm"}