npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@bybrave/flat2

v6.0.2

Published

Maintained fork of flat — flatten/unflatten nested objects, with bundled TypeScript types, improved generics, a CHANGELOG, and dual ESM + CommonJS packaging

Readme

@bybrave/flat2

Maintained, drop-in fork of flat — take a nested JavaScript object and flatten it, or unflatten an object with delimited keys.

The original flat has had no npm release since 2023, ships no bundled TypeScript types, and its v6 went ESM-only. @bybrave/flat2 ships the exact same flatten/unflatten algorithm (verified byte-for-byte against [email protected]) — maintained, fully typed, and packaged as dual ESM + CommonJS.

npm install @bybrave/flat2

Why this fork

| Fix | Upstream issues | |---|---| | Alive & maintained — published again, CI on Node 18/20/22 | #137, #156, #110 | | Bundled TypeScript types, guaranteed in the tarball (no @types/flat) | #162 | | Improved generics — result type is Record<string, any>, not unknown | #179 | | A CHANGELOG | #76 (👍13) | | Dual ESM + CommonJSrequire() works on every Node, including <20.19 / <22.12 where flat v6 throws ERR_REQUIRE_ESM | #101 (👍18), #173, #171, #175 |

Zero runtime dependencies — same as the original.

Usage

ESM

import { flatten, unflatten } from '@bybrave/flat2'

flatten({ key1: { keyA: 'valueI' }, key2: { keyB: 'valueII' } })
// { 'key1.keyA': 'valueI', 'key2.keyB': 'valueII' }

unflatten({ 'key1.keyA': 'valueI', 'key2.keyB': 'valueII' })
// { key1: { keyA: 'valueI' }, key2: { keyB: 'valueII' } }

CommonJS

const flatten = require('@bybrave/flat2')          // callable, like flat v5
const { unflatten } = require('@bybrave/flat2')     // or destructure

flatten({ a: { b: 1 } })      // { 'a.b': 1 }
flatten.unflatten({ 'a.b': 1 }) // { a: { b: 1 } }

CLI

npx flat2 foo.json
cat foo.json | npx flat2

API

flatten(object, options?)

| Option | Type | Default | Description | |---|---|---|---| | delimiter | string | '.' | Key delimiter in the flattened output. | | maxDepth | number | — | Stop flattening after this depth. Also a mitigation for deeply nested/untrusted input. | | safe | boolean | false | Preserve arrays (and their contents) instead of flattening into them. | | transformKey | (key: string) => string | identity | Transform each key while (un)flattening. |

unflatten(object, options?)

| Option | Type | Default | Description | |---|---|---|---| | delimiter | string | '.' | Key delimiter to split on. | | object | boolean | false | Do not turn numeric keys into arrays — keep them as object keys. | | overwrite | boolean | false | Overwrite existing non-object values instead of skipping. | | transformKey | (key: string) => string | identity | Transform each key while unflattening. |

Migrating from flat

@bybrave/flat2 is a drop-in replacement. In most projects only the import changes:

- const flatten = require('flat')
+ const flatten = require('@bybrave/flat2')
- import { flatten, unflatten } from 'flat'
+ import { flatten, unflatten } from '@bybrave/flat2'

The output of flatten / unflatten and every option behaves identically — no code changes beyond the module specifier. The flat CLI is available as flat2.

By design (not bugs)

These behaviors are inherited from the original spec and left unchanged for compatibility. They are configurable, not broken:

  • Numeric keys become array indexes. unflatten({ 'a.0': 'x', 'a.1': 'y' }) produces { a: ['x', 'y'] }, and leading zeros in numeric keys are dropped ('0001'1). Pass { object: true } to keep numeric keys as object keys and preserve the exact string. (Issues #103, #115, #50.)
  • A flat key can't record whether its container was an object or an array ({ '0': 2 } vs [2]); { object: true } forces objects. (#115.)
  • Recursion is recursive. Extremely deep input can exceed the call stack; use { maxDepth: n } to bound it when flattening untrusted data. (#189, #24, #161.)

Security

The prototype-pollution guard from upstream (__proto__ keys are ignored during unflatten) is retained and covered by a regression test. When processing untrusted input, also bound recursion with maxDepth.

Support

If this package saves you time, you can support maintenance:

Ko-fi Bitcoin

Bitcoin (BTC): bc1q37557q5jpeaxqydzwvf3jgj7zhnfpn2td3q40q

License

BSD-3-Clause. Original © 2014 Hugh Kennedy; fork © 2026 bybrave. See LICENSE.