{"_id":"@bybrave/flat2","_rev":"3-d158d846eba5e3c21eb45bf276e6038a","name":"@bybrave/flat2","dist-tags":{"latest":"6.0.2"},"versions":{"6.0.0":{"name":"@bybrave/flat2","version":"6.0.0","keywords":["flat","flatten","unflatten","json","nested","object","delimiter","esm","commonjs","typescript"],"author":{"url":"https://github.com/bybraveHQ","name":"bybrave"},"license":"BSD-3-Clause","_id":"@bybrave/flat2@6.0.0","maintainers":[{"name":"bybrave","email":"opmybrave@gmail.com"}],"contributors":[{"url":"author of the original flat","name":"Hugh Kennedy","email":"hughskennedy@gmail.com"}],"homepage":"https://github.com/bybraveHQ/flat2#readme","bugs":{"url":"https://github.com/bybraveHQ/flat2/issues"},"bin":{"flat2":"cli.js"},"dist":{"shasum":"1c15e1c226d2a5695f2f415b0c343cce208f0900","tarball":"https://registry.npmjs.org/@bybrave/flat2/-/flat2-6.0.0.tgz","fileCount":8,"integrity":"sha512-tSfZHtyHi7fTe/sClebRmbuXXnicd23O0TWean7/2p1PixeAftvpln3QVejr4HN3jFlz4Y72WqJW1loz1iwl3A==","signatures":[{"sig":"MEUCIH+pQig4YrDSLiNazTw96I6MmDTEZD8SOJsmoK2syv7mAiEAwSKLc+dZgDouV6VBzF5mScOLx+KZfEZdtoxPK3xVj7I=","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"unpackedSize":20244},"main":"./dist/index.cjs","type":"module","types":"./index.d.ts","module":"./index.js","engines":{"node":">=18"},"exports":{".":{"types":"./index.d.ts","import":"./index.js","require":"./dist/index.cjs"},"./package.json":"./package.json"},"funding":"https://ko-fi.com/bybrave","gitHead":"c416eb9179655c421378cfa16581a7cddeb10af8","scripts":{"test":"node --test test/*.test.js","build":"node build/build.js","test-types":"tsc --noEmit --strict test/type-declarations.ts","prepublishOnly":"npm run build"},"_npmUser":{"name":"bybrave","email":"opmybrave@gmail.com"},"repository":{"url":"git+https://github.com/bybraveHQ/flat2.git","type":"git"},"_npmVersion":"10.8.2","description":"Maintained fork of flat — flatten/unflatten nested objects, now dual ESM + CommonJS (require() works again), with bundled TypeScript types and a CHANGELOG","directories":{},"sideEffects":false,"_nodeVersion":"20.19.6","_hasShrinkwrap":false,"devDependencies":{"esbuild":"^0.23.0","typescript":"^5.5.0","@types/node":"^20.14.0"},"_npmOperationalInternal":{"tmp":"tmp/flat2_6.0.0_1783272202464_0.6173603875911038","host":"s3://npm-registry-packages-npm-production"}},"6.0.1":{"name":"@bybrave/flat2","version":"6.0.1","keywords":["flat","flatten","unflatten","json","nested","object","delimiter","esm","commonjs","typescript"],"author":{"url":"https://github.com/bybraveHQ","name":"bybrave"},"license":"BSD-3-Clause","_id":"@bybrave/flat2@6.0.1","maintainers":[{"name":"bybrave","email":"opmybrave@gmail.com"}],"contributors":[{"url":"author of the original flat","name":"Hugh Kennedy","email":"hughskennedy@gmail.com"}],"homepage":"https://github.com/bybraveHQ/flat2#readme","bugs":{"url":"https://github.com/bybraveHQ/flat2/issues"},"bin":{"flat2":"cli.js"},"dist":{"shasum":"3f109c71fba022b09b7e9025508ce5fcbf895e1f","tarball":"https://registry.npmjs.org/@bybrave/flat2/-/flat2-6.0.1.tgz","fileCount":8,"integrity":"sha512-BrHWIuYtZYCjTfEOKl/uR7uhqs4FCd/4WFQ0gErajnz/spSS2zMs8RwIShU8peJGO3LhvSGGh+AGplBzr+1B+Q==","signatures":[{"sig":"MEUCIBvoWES4ku8wmQGjqbSOHqkEW9m0sGS/f+m1Q/GO4PJWAiEA46QmEm67vUYpHoomZ2xEae8wlon+y+S3bwQuZ8XRnC0=","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"unpackedSize":20611},"main":"./dist/index.cjs","type":"module","types":"./index.d.ts","module":"./index.js","engines":{"node":">=18"},"exports":{".":{"types":"./index.d.ts","import":"./index.js","require":"./dist/index.cjs"},"./package.json":"./package.json"},"funding":"https://ko-fi.com/bybrave","gitHead":"c32a77a6da6ecd50c7fe7c5e0b7f68925e162a2f","scripts":{"test":"node --test test/*.test.js","build":"node build/build.js","test-types":"tsc --noEmit --strict test/type-declarations.ts","prepublishOnly":"npm run build"},"_npmUser":{"name":"bybrave","email":"opmybrave@gmail.com"},"repository":{"url":"git+https://github.com/bybraveHQ/flat2.git","type":"git"},"_npmVersion":"10.8.2","description":"Maintained fork of flat — flatten/unflatten nested objects, now dual ESM + CommonJS (require() works again), with bundled TypeScript types and a CHANGELOG","directories":{},"sideEffects":false,"_nodeVersion":"20.19.6","_hasShrinkwrap":false,"devDependencies":{"esbuild":"^0.23.0","typescript":"^5.5.0","@types/node":"^20.14.0"},"_npmOperationalInternal":{"tmp":"tmp/flat2_6.0.1_1783297153041_0.007337800175771347","host":"s3://npm-registry-packages-npm-production"}},"6.0.2":{"name":"@bybrave/flat2","version":"6.0.2","description":"Maintained fork of flat — flatten/unflatten nested objects, with bundled TypeScript types, improved generics, a CHANGELOG, and dual ESM + CommonJS packaging","type":"module","main":"./dist/index.cjs","module":"./index.js","types":"./index.d.ts","bin":{"flat2":"cli.js"},"exports":{".":{"types":"./index.d.ts","import":"./index.js","require":"./dist/index.cjs"},"./package.json":"./package.json"},"sideEffects":false,"scripts":{"build":"node build/build.js","test":"node --test test/*.test.js","test-types":"tsc --noEmit --strict test/type-declarations.ts","prepublishOnly":"npm run build"},"repository":{"type":"git","url":"git+https://github.com/bybraveHQ/flat2.git"},"bugs":{"url":"https://github.com/bybraveHQ/flat2/issues"},"homepage":"https://github.com/bybraveHQ/flat2#readme","keywords":["flat","flatten","unflatten","json","nested","object","delimiter","esm","commonjs","typescript"],"author":{"name":"bybrave","url":"https://github.com/bybraveHQ"},"contributors":[{"name":"Hugh Kennedy","email":"hughskennedy@gmail.com","url":"author of the original flat"}],"license":"BSD-3-Clause","funding":"https://ko-fi.com/bybrave","engines":{"node":">=18"},"devDependencies":{"@types/node":"^20.14.0","esbuild":"^0.23.0","typescript":"^5.5.0"},"_id":"@bybrave/flat2@6.0.2","gitHead":"bd63b2d67ea45418c0b3ed776e719c69c8254a83","_nodeVersion":"20.19.6","_npmVersion":"10.8.2","dist":{"integrity":"sha512-jg4soe6TzT3wZIJB5FjYyPfputd6mHzb8OFsBw7dmCNaj2ab3YZQ6BwXKfn8n05OyTqP1YELcZHASolE7cjMAA==","shasum":"dcc3ac52ba445633bc88fa672e1986a25c0e91cd","tarball":"https://registry.npmjs.org/@bybrave/flat2/-/flat2-6.0.2.tgz","fileCount":8,"unpackedSize":20695,"signatures":[{"keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U","sig":"MEUCICeDzq77SPqaFNHa4aTE6oWRJjV4J2TzEzeMEFZ9tICmAiEA4+7wTMpSlAwFpj3zuZbZAo3eY+p82UEoxM0fHI7Hk8s="}]},"_npmUser":{"name":"bybrave","email":"opmybrave@gmail.com"},"directories":{},"maintainers":[{"name":"bybrave","email":"opmybrave@gmail.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages-npm-production","tmp":"tmp/flat2_6.0.2_1783368546081_0.696443090954739"},"_hasShrinkwrap":false}},"time":{"created":"2026-07-05T17:23:22.341Z","modified":"2026-07-06T20:09:06.357Z","6.0.0":"2026-07-05T17:23:22.596Z","6.0.1":"2026-07-06T00:19:13.203Z","6.0.2":"2026-07-06T20:09:06.222Z"},"bugs":{"url":"https://github.com/bybraveHQ/flat2/issues"},"author":{"name":"bybrave","url":"https://github.com/bybraveHQ"},"license":"BSD-3-Clause","homepage":"https://github.com/bybraveHQ/flat2#readme","keywords":["flat","flatten","unflatten","json","nested","object","delimiter","esm","commonjs","typescript"],"repository":{"type":"git","url":"git+https://github.com/bybraveHQ/flat2.git"},"description":"Maintained fork of flat — flatten/unflatten nested objects, with bundled TypeScript types, improved generics, a CHANGELOG, and dual ESM + CommonJS packaging","contributors":[{"name":"Hugh Kennedy","email":"hughskennedy@gmail.com","url":"author of the original flat"}],"maintainers":[{"name":"bybrave","email":"opmybrave@gmail.com"}],"readme":"# @bybrave/flat2\n\n**Maintained, drop-in fork of [`flat`](https://github.com/hughsk/flat)** — take a\nnested JavaScript object and flatten it, or unflatten an object with delimited keys.\n\nThe original `flat` has had no npm release since 2023, ships **no bundled TypeScript\ntypes**, and its v6 went **ESM-only**. `@bybrave/flat2` ships the **exact same\nflatten/unflatten algorithm** (verified byte-for-byte against `flat@6.0.1`) —\nmaintained, fully typed, and packaged as dual ESM + CommonJS.\n\n```\nnpm install @bybrave/flat2\n```\n\n## Why this fork\n\n| Fix | Upstream issues |\n|---|---|\n| **Alive & maintained** — published again, CI on Node 18/20/22 | #137, #156, #110 |\n| **Bundled TypeScript types**, guaranteed in the tarball (no `@types/flat`) | #162 |\n| **Improved generics** — result type is `Record<string, any>`, not `unknown` | #179 |\n| **A CHANGELOG** | #76 (👍13) |\n| **Dual ESM + CommonJS** — `require()` works on every Node, including <20.19 / <22.12 where `flat` v6 throws `ERR_REQUIRE_ESM` | #101 (👍18), #173, #171, #175 |\n\nZero runtime dependencies — same as the original.\n\n## Usage\n\n### ESM\n\n```js\nimport { flatten, unflatten } from '@bybrave/flat2'\n\nflatten({ key1: { keyA: 'valueI' }, key2: { keyB: 'valueII' } })\n// { 'key1.keyA': 'valueI', 'key2.keyB': 'valueII' }\n\nunflatten({ 'key1.keyA': 'valueI', 'key2.keyB': 'valueII' })\n// { key1: { keyA: 'valueI' }, key2: { keyB: 'valueII' } }\n```\n\n### CommonJS\n\n```js\nconst flatten = require('@bybrave/flat2')          // callable, like flat v5\nconst { unflatten } = require('@bybrave/flat2')     // or destructure\n\nflatten({ a: { b: 1 } })      // { 'a.b': 1 }\nflatten.unflatten({ 'a.b': 1 }) // { a: { b: 1 } }\n```\n\n### CLI\n\n```bash\nnpx flat2 foo.json\ncat foo.json | npx flat2\n```\n\n## API\n\n### `flatten(object, options?)`\n\n| Option | Type | Default | Description |\n|---|---|---|---|\n| `delimiter` | `string` | `'.'` | Key delimiter in the flattened output. |\n| `maxDepth` | `number` | — | Stop flattening after this depth. Also a mitigation for deeply nested/untrusted input. |\n| `safe` | `boolean` | `false` | Preserve arrays (and their contents) instead of flattening into them. |\n| `transformKey` | `(key: string) => string` | identity | Transform each key while (un)flattening. |\n\n### `unflatten(object, options?)`\n\n| Option | Type | Default | Description |\n|---|---|---|---|\n| `delimiter` | `string` | `'.'` | Key delimiter to split on. |\n| `object` | `boolean` | `false` | Do not turn numeric keys into arrays — keep them as object keys. |\n| `overwrite` | `boolean` | `false` | Overwrite existing non-object values instead of skipping. |\n| `transformKey` | `(key: string) => string` | identity | Transform each key while unflattening. |\n\n## Migrating from `flat`\n\n`@bybrave/flat2` is a drop-in replacement. In most projects only the import changes:\n\n```diff\n- const flatten = require('flat')\n+ const flatten = require('@bybrave/flat2')\n```\n\n```diff\n- import { flatten, unflatten } from 'flat'\n+ import { flatten, unflatten } from '@bybrave/flat2'\n```\n\nThe output of `flatten` / `unflatten` and every option behaves identically — no\ncode changes beyond the module specifier. The `flat` CLI is available as `flat2`.\n\n## By design (not bugs)\n\nThese behaviors are inherited from the original spec and left unchanged for\ncompatibility. They are configurable, not broken:\n\n- **Numeric keys become array indexes.** `unflatten({ 'a.0': 'x', 'a.1': 'y' })`\n  produces `{ a: ['x', 'y'] }`, and leading zeros in numeric keys are dropped\n  (`'0001'` → `1`). Pass `{ object: true }` to keep numeric keys as object keys\n  and preserve the exact string. (Issues #103, #115, #50.)\n- **A flat key can't record whether its container was an object or an array**\n  (`{ '0': 2 }` vs `[2]`); `{ object: true }` forces objects. (#115.)\n- **Recursion is recursive.** Extremely deep input can exceed the call stack; use\n  `{ maxDepth: n }` to bound it when flattening untrusted data. (#189, #24, #161.)\n\n## Security\n\nThe prototype-pollution guard from upstream (`__proto__` keys are ignored during\n`unflatten`) is retained and covered by a regression test. When processing\nuntrusted input, also bound recursion with `maxDepth`.\n\n## Support\n\nIf this package saves you time, you can support maintenance:\n\n[![Ko-fi](https://img.shields.io/badge/Ko--fi-buy%20me%20a%20coffee-FF5E5B?logo=kofi&logoColor=white)](https://ko-fi.com/bybrave)\n[![Bitcoin](https://img.shields.io/badge/Bitcoin-BTC-F7931A?logo=bitcoin&logoColor=white)](#support)\n\nBitcoin (BTC): `bc1q37557q5jpeaxqydzwvf3jgj7zhnfpn2td3q40q`\n\n## License\n\nBSD-3-Clause. Original © 2014 Hugh Kennedy; fork © 2026 bybrave. See [LICENSE](./LICENSE).\n","readmeFilename":"README.md"}