{"name":"neotraverse","version":"1.0.0","keywords":["clone","deep","forEach","map","recursive","traverse","walk"],"author":{"url":"https://puruvj.dev","name":"Puru Vijay"},"license":"MIT","_id":"neotraverse@1.0.0","maintainers":[{"name":"puruvj","email":"awesomepuruvj@gmail.com"}],"homepage":"https://neotraverse.puruvj.dev","bugs":{"url":"https://github.com/PuruVJ/neotraverse/issues"},"dist":{"shasum":"36a3a3679f4bba8c4d7ff9ef5c902436e86d084f","tarball":"http://registry-npm.ywwl.com/neotraverse/download/neotraverse-1.0.0.tgz","fileCount":17,"integrity":"sha512-DxwuwBj4rEIc3p2ffVjN9ACIvhgzhGwEv4PMXA/7jA74H3P9jyIQ1GzdfbEf7kuqJ230vQMl5gBAi/FcqmtClA==","signatures":[{"sig":"MEQCIEBvvPn8uwCGdWHf0iV0XR6vCr0F+VrUfOgKZ2xpfnV5AiAnBZIf+C/24PGDwdwURKPApHgVAFrMacBOvQeo05Q57Q==","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"attestations":{"url":"https://registry.npmjs.org/-/npm/v1/attestations/neotraverse@1.0.0","provenance":{"predicateType":"https://slsa.dev/provenance/v1"}},"unpackedSize":235947,"size":53305,"noattachment":false,"key":"/neotraverse/-/neotraverse-1.0.0.tgz"},"main":"dist/legacy/legacy.cjs","type":"module","_from":"file:neotraverse-1.0.0.tgz","types":"dist/index.d.ts","engines":{"node":">= 10"},"exports":{".":{"types":"./dist/index.d.ts","default":"./dist/index.js"},"./safe":{"types":"./dist/safe/index.d.ts","default":"./dist/safe/index.js"},"./legacy":{"import":{"types":"./dist/legacy/legacy.d.ts","default":"./dist/legacy/legacy.mjs"},"default":"./dist/legacy/legacy.cjs","require":{"types":"./dist/legacy/legacy.d.cts","default":"./dist/legacy/legacy.cjs"}},"./modern":{"types":"./dist/modern.d.ts","default":"./dist/modern.js"},"./package.json":"./package.json"},"scripts":{"test":"vp test","bench":"pnpm compile && node --expose-gc --max-semi-space-size=128 --import tsx bench/run.ts","compile":"vp pack","test:cov":"vp test --coverage","typecheck":"tsc --noEmit","bench:safe":"pnpm compile && node --expose-gc --max-semi-space-size=128 --import tsx bench/run-safe.ts","test:types":"vp test --typecheck","bundle-size":"node scripts/measure-bundle.mjs","bench:safe-memory":"pnpm compile && node --expose-gc --max-semi-space-size=128 --import tsx bench/safe-memory.ts"},"_npmUser":{"name":"GitHub Actions","email":"npm-oidc-no-reply@github.com","trustedPublisher":{"id":"github","oidcConfigId":"oidc:28099fa2-8d35-46c3-85b7-f811316800e8"}},"_resolved":"/tmp/4570aa560edc068c9221dd4380573481/neotraverse-1.0.0.tgz","_integrity":"sha512-DxwuwBj4rEIc3p2ffVjN9ACIvhgzhGwEv4PMXA/7jA74H3P9jyIQ1GzdfbEf7kuqJ230vQMl5gBAi/FcqmtClA==","repository":{"url":"git+https://github.com/PuruVJ/neotraverse.git","type":"git","directory":"packages/neotraverse"},"_npmVersion":"11.16.0","description":"traverse and transform objects by visiting every node on a recursive walk","directories":{},"sideEffects":false,"_nodeVersion":"24.16.0","publishConfig":{"provenance":true},"_hasShrinkwrap":false,"devDependencies":{"tsx":"^4.22.4","traverse":"^0.6.11","tinybench":"^6.0.2","typescript":"^6.0.3","@types/node":"^25.9.1"},"_npmOperationalInternal":{"tmp":"tmp/neotraverse_1.0.0_1781183049782_0.8120753904377778","host":"s3://npm-registry-packages-npm-production"},"readme":"# neotraverse\n\nTraverse and transform objects by visiting every node on a recursive walk. A TypeScript rewrite of [`traverse`](https://github.com/ljharb/js-traverse) with **0 dependencies**, **prototype-pollution hardening**, **~5× the throughput** and **~6× less allocation** with the functional API (up to **~10×** / **~11×** peaks on core walks).\n\n> 📖 **Full docs, security audit & live benchmarks:** **[neotraverse.puruvj.dev](https://neotraverse.puruvj.dev)**\n\n**Utility-first:** the default export is named functions (`sideEffects: false`), pay for what you use, not a monolithic class.\n\n- 🤌 **~2–6 KB brotli** (tree-shaken; ~2 KB for one walk like `forEach`, ~5.8 KB for every helper)\n- 🚥 Zero dependencies, no polyfills\n- 🎹 TypeScript: throw away `@types/traverse`\n- 🛡️ Safe on untrusted input ([prototype-pollution & injection hardened](#security))\n- ⚡ **~5× faster** and **~6× leaner** than `traverse` with the functional API (up to **~10×** / **~11×**); **~3×** speed and **~2×** less memory on the legacy drop-in build\n- 🛸 ESM-first, with a legacy ES2015 CJS/ESM build\n- 🛟 **[`neotraverse/safe`](#neotraversesafe):** an opt-in, stack-safe iterative core that walks **200,000-deep** trees recursion can't, with a lazy `visit` iterator and copy-on-write `transform` (Node 22+)\n\n## Benchmarks (summary)\n\nGeometric-mean speedup versus the original `traverse` across the full operation × shape matrix:\n\n| Build                               | Speedup vs `traverse`                                               | Allocation vs `traverse` (core walks)               |\n| ----------------------------------- | ------------------------------------------------------------------- | --------------------------------------------------- |\n| **neotraverse modern** (functional) | **≈ 4.9×** (full matrix) · **≈ 5.6×** (core walks) · **up to ~10×** | **≈ 5.7× less** · **up to ~11×** (`forEach · wide`) |\n| **neotraverse legacy** (drop-in)    | **≈ 3×**                                                            | **≈ 2× less**                                       |\n\nCore traversal ops (`forEach` / `map` / `clone` / `reduce` / `paths` / `nodes`) on the **functional** build land at **~3–10×** throughput and **~6× less heap** on average vs `traverse` (peaks: `clone · small` **~9.9×** speed, `forEach · wide` **~11×** memory). See the [full table](#benchmarks-full) or the [interactive benchmarks page](https://neotraverse.puruvj.dev/benchmarks). Reproduce with `pnpm bench`.\n\n## Install\n\n```sh\nnpm install neotraverse\n```\n\n## Bundle size (tree-shaken, brotli)\n\nMeasured with esbuild + brotli from published ESM ([`bench/bundle-sizes.json`](./bench/bundle-sizes.json); `pnpm bundle-size`):\n\n| Import                                                  | Brotli          |\n| ------------------------------------------------------- | --------------- |\n| One walk terminal (`forEach`, `map`, `find`, `size`, …) | **~2 KB**       |\n| Path only (`get` / `has` / `set` or `getPath`)          | **~0.3–0.5 KB** |\n| Every functional helper                                 | **~5.8 KB**     |\n\n## Quick start\n\n```ts\n// the default export: tree-shakeable functions, `ctx` argument (recommended)\nimport { forEach } from 'neotraverse';\n\nforEach({ a: 1, b: 2, c: [3, 4] }, (ctx, x) => {\n  if (typeof x === 'number') ctx.update(x * 10);\n});\n```\n\n```ts\n// classic `traverse`-compatible API (drop-in for the original `traverse`)\nimport traverse from 'neotraverse/legacy';\n\ntraverse({ a: 1, b: 2, c: [3, 4] }).forEach(function (x) {\n  if (typeof x === 'number') this.update(x * 10);\n});\n```\n\n```ts\n// the deprecated 0.x `Traverse` class lives here, removed in v2\nimport { Traverse } from 'neotraverse/modern';\n```\n\n## `neotraverse/safe`\n\nA second, opt-in entry point for input that is **deep, untrusted, huge, or only partially consumed**. The default `neotraverse` walk is recursive (fast, but it overflows the call stack on deep enough input). `neotraverse/safe` runs on an **iterative** engine, so it traverses arbitrarily deep trees that crash a recursive walker (measured: the default overflows past **~2,000** levels; `/safe` handles **200,000+**). It is also lazy and copy-on-write.\n\n```ts\nimport { visit, transform } from 'neotraverse/safe';\n\n// lazy iteration: stop early, never materialize the rest\nconst first5 = visit(huge)\n  .filter((v) => typeof v.value === 'string')\n  .take(5)\n  .toArray();\n\n// copy-on-write: shares untouched subtrees, returns the input by identity on a no-op\nconst redacted = transform(doc, {\n  '**.{password,token}': (v, { replace }) => replace('***')\n});\n```\n\nIt ships a twelve-export surface: `visit`, `transform` / `transformAsync`, `get` / `set` / `has`, `clone`, `equal`, `merge`, `diff`, `patch`, `resolveRefs`.\n\n**The honest trade-off:** on a full eager scan `/safe` runs at roughly **0.8×** the default (still ~4× faster than `traverse`), and materializing a whole tree costs a little more memory. It wins on **stack safety**, on **early-exit memory** (~6× less peak on a `filter().take()` chain), and on **copy-on-write** edits. Requires **Node 22+** / evergreen browsers (it uses native ES2025 iterator helpers). See the [`/safe` guide](https://neotraverse.puruvj.dev/guide/safe).\n\n## Builds & browser support\n\n| Build       | Import               | Contents                           | Module    | Target | Browsers                                      |\n| ----------- | -------------------- | ---------------------------------- | --------- | ------ | --------------------------------------------- |\n| **default** | `neotraverse`        | functional API (recommended)       | ESM       | ES2022 | Chrome/Edge 94+, Firefox 93+, Safari 15+      |\n| **safe**    | `neotraverse/safe`   | stack-safe iterative core (opt-in) | ESM       | ES2024 | Node 22+, evergreen browsers                  |\n| **modern**  | `neotraverse/modern` | deprecated `Traverse` class only   | ESM       | ES2022 | Chrome/Edge 94+, Firefox 93+, Safari 15+      |\n| **legacy**  | `neotraverse/legacy` | classic `traverse` drop-in         | CJS + ESM | ES2015 | Chrome 51+, Firefox 54+, Safari 10+, Edge 15+ |\n\n> ⚠️ **1.0 breaking changes:** the default export (`neotraverse`) is now the functional API, not the classic `traverse` default. Move classic drop-in imports to `neotraverse/legacy`, and `import { Traverse }` to `neotraverse/modern`. The legacy build also targets **ES2015** (was ES5); only environments needing literal ES5 (e.g. IE11) are affected.\n\n## Security\n\n`neotraverse` is safe to run on **untrusted data**:\n\n- **No prototype pollution:** `set(path, value)` refuses `__proto__` / `constructor` / `prototype` keys.\n- **No prototype injection:** `clone()` / `map()` of hostile JSON like `{\"__proto__\":{\"isAdmin\":true}}` keep their real prototype; `result.isAdmin` is `undefined`.\n- **Prototype preservation intact:** legitimate `instanceof` still works after a clone.\n- **No prototype-chain disclosure:** `get()` / `has()` follow only own properties.\n\n```ts\nimport { clone } from 'neotraverse';\n\nconst evil = JSON.parse('{\"user\":\"bob\",\"__proto__\":{\"isAdmin\":true}}');\nclone(evil).isAdmin; // undefined\n({}).isAdmin; // undefined, global prototype untouched\n```\n\nRead the full story in the [**1.0 release post**](https://puruvj.dev/blog/neotraverse-1-0).\n\n### DoS guard\n\nBound recursion on deeply-nested hostile input with `maxDepth` (throws a catchable `RangeError`; unlimited by default):\n\n```ts\nclone(untrusted, { maxDepth: 1000 });\n```\n\n> The hardening and DoS guards apply to the **functional** API. The `neotraverse/legacy` drop-in is intentionally kept behaviour-compatible with the original `traverse` and does **not** receive them — run untrusted data through the functional API.\n\n## Migrating from `traverse`\n\n**[Differences from traverse](https://neotraverse.puruvj.dev/guide/vs-traverse):** drop-in vs functional, what's new, which build to use.\n\n```diff\n-import traverse from 'traverse';\n+import traverse from 'neotraverse/legacy';\n```\n\n```sh\nnpm install neotraverse && npm uninstall traverse @types/traverse\n```\n\nThe legacy API is identical to `traverse`. For new code, prefer the functional default export.\n\n## API\n\n**Functional (`neotraverse`, recommended):** `forEach`, `map`, `clone`, `reduce`, `find`, `filter`, `some`, `every`, `paths`, `nodes`, `get`, `set`, `has`, `entries`, `values`, `walk`, `breadthFirst`, `mapBfs`, `forEachAsync`, `mapAsync`, plus `findPaths`, `filterPaths`, `getPath`, `setPath`, `hasPath`, `parsePath`, `parseDotPath`, `parseJsonPointer`, `pointerPath`, `parseGlob`, `count`, `size`, `getType`, `groupBy`, `skipWhere`, `deleteWhere`, `prune`, `pruneDeep`, `sanitize`, `deepEqual`, `merge`, `dereference`, `toJSON`, `freeze`, `diff`, `patch`, `select`. Options are always the last argument.\n\n**Deprecated class (`neotraverse/modern`):** the `Traverse` class (`.get`/`.has`/`.set`/`.map`/`.forEach`/`.reduce`/`.paths`/`.nodes`/`.clone`) is deprecated and **removed in v2** — use the functions above.\n\n**Classic (`neotraverse/legacy`):** `.map(fn)` · `.forEach(fn)` · `.reduce(fn, acc)` · `.paths()` · `.nodes()` · `.clone()` · `.get(path)` · `.set(path, value)` · `.has(path)` on a traversal instance (`this`-bound context).\n\nOptions: `{ immutable?, includeSymbols?, maxDepth?, signal? }` (`signal` is async-only on modern).\n\nEach callback gets a context (`ctx` in modern, `this` in classic) with `node`, `path`, `parent`, `key`, `isRoot`, `isLeaf`, `isFirst`, `isLast`, `level`, `circular`, and the mutators `update()`, `remove()`, `delete()`, `before()`, `after()`, `pre()`, `post()`, `stop()`, `block()`.\n\n👉 Full API reference, examples, and context docs: **[neotraverse.puruvj.dev/guide](https://neotraverse.puruvj.dev/guide)**.\n\n## Benchmarks (full) {#benchmarks-full}\n\n`neotraverse` vs `traverse`, ops/sec (and ×speedup). Generated by [`bench/run.ts`](./bench/run.ts) via [tinybench](https://github.com/tinylibs/tinybench); see [`bench/results.json`](./bench/results.json).\n\n| Operation · shape |   traverse | neotraverse legacy | neotraverse modern |\n| ----------------- | ---------: | -----------------: | -----------------: |\n| `forEach · small` |    841,043 |  2,414,704 (2.87×) |  4,016,013 (4.78×) |\n| `forEach · wide`  |     79,308 |    284,208 (3.58×) |    594,241 (7.49×) |\n| `forEach · deep`  |     53,214 |    160,316 (3.01×) |    330,800 (6.22×) |\n| `forEach · array` |      3,019 |     10,186 (3.37×) |     21,242 (7.04×) |\n| `forEach · json`  |     57,421 |    186,579 (3.25×) |    382,143 (6.66×) |\n| `map · small`     |    393,442 |  1,268,242 (3.22×) |  2,267,588 (5.76×) |\n| `map · wide`      |     50,468 |    106,498 (2.11×) |    183,870 (3.64×) |\n| `map · deep`      |     18,833 |     87,198 (4.63×) |    136,623 (7.25×) |\n| `map · array`     |      1,421 |      4,376 (3.08×) |      8,619 (6.07×) |\n| `map · json`      |     23,178 |     83,958 (3.62×) |    151,069 (6.52×) |\n| `clone · small`   |    494,252 |  3,356,979 (6.79×) |  4,884,062 (9.88×) |\n| `clone · wide`    |    209,591 |    309,111 (1.47×) |    574,325 (2.74×) |\n| `clone · deep`    |     27,853 |    170,807 (6.13×) |    260,473 (9.35×) |\n| `clone · array`   |      3,250 |     11,408 (3.51×) |     15,411 (4.74×) |\n| `clone · json`    |     42,207 |    205,740 (4.87×) |    303,054 (7.18×) |\n| `reduce · small`  |    796,994 |  2,201,209 (2.76×) |  3,536,758 (4.44×) |\n| `reduce · wide`   |     75,627 |    260,493 (3.44×) |    489,665 (6.47×) |\n| `reduce · deep`   |     50,668 |    145,498 (2.87×) |     288,933 (5.7×) |\n| `reduce · array`  |      2,909 |      9,229 (3.17×) |     17,781 (6.11×) |\n| `reduce · json`   |     55,255 |    173,837 (3.15×) |    328,782 (5.95×) |\n| `paths · small`   |    811,923 |  2,279,936 (2.81×) |  3,402,905 (4.19×) |\n| `paths · wide`    |     77,412 |    268,188 (3.46×) |    475,490 (6.14×) |\n| `paths · deep`    |     50,955 |    151,982 (2.98×) |    212,666 (4.17×) |\n| `paths · array`   |      2,976 |      9,566 (3.21×) |      16,368 (5.5×) |\n| `paths · json`    |     56,251 |    177,158 (3.15×) |    294,870 (5.24×) |\n| `nodes · small`   |    800,765 |  2,258,624 (2.82×) |  3,490,623 (4.36×) |\n| `nodes · wide`    |     76,618 |    265,446 (3.46×) |    506,638 (6.61×) |\n| `nodes · deep`    |     51,151 |    149,846 (2.93×) |    288,099 (5.63×) |\n| `nodes · array`   |      2,943 |      9,442 (3.21×) |     17,715 (6.02×) |\n| `nodes · json`    |     55,541 |    176,656 (3.18×) |    328,321 (5.91×) |\n| `get · json`      | 18,069,492 | 22,168,643 (1.23×) | 21,280,988 (1.18×) |\n| `has · json`      | 18,943,414 | 22,254,349 (1.17×) | 22,156,236 (1.17×) |\n| `set · json`      | 23,632,276 | 23,862,298 (1.01×) | 19,365,527 (0.82×) |\n\n> `get` / `has` / `set` are micro-ops (20M+ ops/s); all three builds are within noise of each other and of `traverse`. The legacy class stores its state in plain instance fields (not `#private`, which would downlevel to WeakMaps at ES2015), so these stay native-fast on the drop-in too.\n\n## License\n\n[MIT](./LICENSE), [Puru Vijay](https://puruvj.dev).\n","publish_time":1781183049927,"_cnpm_publish_time":1781183049927,"dist-tags":{"latest":"1.0.2","next":"0.6.9-next.0"}}