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).
npm install flattieVerified import paths — ran on the pinned version, not inferred.
Demonstrates basic object flattening, custom glue usage, and how to retain nullish values.
To retain nullish values, pass `true` as the third argument to the `flattie` function: `flattie(input, glue, true)`.
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.
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.
For ESM, use `import { flattie } from 'flattie';`. For CommonJS, use `const { flattie } = require('flattie');`.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.
No dependency data recorded yet.