{"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,"search_vec":"'1.1.1':30 '203b':50 'also':93 'altern':56 'array':20 'automat':76 'behavior':65 'benchmark':54 'bundl':48 'cadenc':37 'concaten':68 'core':42 'counterpart':105 'current':27 'customiz':64 'default':74 'definit':98 'demonstr':51 'depth':25 'develop':102 'differenti':43 'expand':111 'experi':103 'extrem':46 'featur':87 'flat':58,119 'flatten':3,16,61,84,112,116 'flatten-object':60 'flatti':1,5 'glue':71 'high':10 'includ':44 'increment':39 'javascript':12,114 'key':67,115 'librari':32 'like':57 'maintain':33 'minimalist':8 'nest':17,118 'nesti':106 'null':80 'nullish':78 'object':2,18,26,62,113,117 'omit':77 'oper':110 'output':85 'patch':40 'perform':11 'provid':99,107 'recurs':15 'releas':36 'revers':109 'robust':101 'ship':94 'singl':24 'single-depth':23 'size':49 'small':47 'speed':52 'stabl':35 'string':72 'toggl':91 'type':97 'typescript':96,120 'undefin':81 'util':4,13 'valu':79 'version':29 'via':53,69","created_at":"2026-04-19T13:35:13.343094+00:00","updated_at":"2026-04-19T13:35:13.343094+00:00","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","meta_description":null,"install_score":null,"quickstart_score":null,"quickstart_tag":null,"pypi_latest":null,"cli_name":"","cli_version":null,"type":"library","homepage":null,"github":"https://github.com/lukeed/flattie","docs":null,"changelog":null,"pypi":null,"npm":"https://www.npmjs.com/package/flattie","openapi_spec":null,"status_page":null,"smithery":null,"categories":["serialization","data"],"base_url":null,"auth_type":null,"provenance":{"verified_status":null,"verified_at":null,"last_verified":"2026-06-17","next_check":"2026-07-18","install_tag":null}}