klona
A tiny, dependency-free utility for deep cloning objects, arrays, dates, and more.
Repository Health
Technical Analysis
klona is a minimal JavaScript utility for deep cloning values — objects, arrays, dates, regular expressions, Maps, Sets, typed arrays, and more — without pulling in a dependency-heavy library like lodash. It ships as ES modules, CommonJS, and UMD builds, and offers four progressively capable entry points (klona/json, klona/lite, klona, klona/full) so consumers can trade feature coverage against bundle size, from 240 bytes up to 501 bytes gzipped.
Under the hood klona recursively walks a value’s structure using Object.prototype.toString tag checks rather than instanceof, letting it correctly branch on Object, Array, Date, RegExp, Map, Set, DataView, ArrayBuffer, and TypedArray inputs. The full build additionally preserves Symbol-keyed properties and non-enumerable property descriptors, matching what a hand-rolled recursive copy would otherwise require far more code to achieve.
What You Get
- Four import modes (
klona,klona/json,klona/lite,klona/full) covering different tradeoffs between bundle size and supported types - ESM, CommonJS, and UMD builds generated via the
bundtbundler, plus bundled TypeScript definitions - Deep clone support for Object, Array, Date, RegExp, Map, Set, DataView, ArrayBuffer, and TypedArray values
- A benchmark suite comparing klona’s throughput and correctness against lodash, clone, rfdc, and clone-deep
Common Use Cases
- Deep-cloning Redux/Vuex state trees before mutating them to preserve immutability guarantees
- Copying configuration objects so defaults can be safely overridden per request in a server
- Cloning parsed JSON payloads in test fixtures to avoid cross-test mutation
- Snapshotting complex form state (dates, nested objects) in a UI before allowing edits
Under The Hood
Architecture
klona is a flat, single-purpose utility with no internal layering: each of its four variants (src/json.js, src/lite.js, src/index.js, src/full.js) exports one recursive klona(x) function, resolved through the exports/modes map in package.json to the matching build. The variants share the same recursive shape but progressively add type-dispatch branches — json handles only plain Objects/Arrays, lite adds Date/RegExp, the default build adds Map/Set/DataView/ArrayBuffer/TypedArray, and full layers in Symbol-keyed and non-enumerable property cloning via a shared set() helper. There is no dependency injection or abstraction layering to speak of; the entire design surface is the branching logic inside one function per build.
Tech Stack
Written in plain ES2015+ JavaScript with zero runtime dependencies. Distribution is handled by bundt (produces dist/*.js, *.mjs, and minified UMD bundles per entry point, listed under package.json’s exports and legacy modes fields), with a single index.d.ts copied across the json, lite, and full output directories via the postbuild script. Tests run on uvu (a minimal, fast test runner) loaded through the esm package for ES module support on older Node. CI (GitHub Actions) runs the suite across Node 8, 10, and 12 with nyc coverage uploaded to Codecov.
Code Quality
Tests live under test/suites/, one file per data type (array.js, object.js, date.js, regexp.js, map.js, set.js, symbol.js, typedarray.js, pollution.js, class.js, descriptor.js, and more), each exporting a parameterized suite function that is run against every build variant from test/index.js, test/full.js, test/lite.js, and test/json.js — the same assertions verify all four implementations without duplicating test logic. There is a dedicated pollution.js suite specifically asserting __proto__ keys can’t be used to pollute the prototype chain. No TypeScript, ESLint, or Prettier config is present in the repo; naming favors terse single-letter locals (k, tmp, str) consistent with the project’s minimal-bundle-size goal rather than a general-audience readability standard.
What Makes It Unique
klona’s core dispatch uses Object.prototype.toString.call(x) tag checks instead of instanceof, which correctly clones values that cross realm boundaries (e.g. arrays from an iframe) where instanceof checks would fail. It explicitly special-cases the __proto__ key with Object.defineProperty in both the default and lite builds to prevent prototype-pollution vectors that affect naive recursive cloners. Its most distinctive choice is offering four separately-published entry points sized from 240 to 501 bytes gzipped, letting consumers opt into exactly the type coverage they need rather than a single one-size-fits-all implementation — a packaging strategy the project’s own benchmarks show outperforming lodash’s cloneDeep by roughly 4-5x.
Used by 5 apps in this directory
Appsmith
Developer Tools · Automation · No Code Platforms
Open-source low-code platform to build admin panels, dashboards, and internal tools connected to any database or API.
ILLA Builder
Developer Tools · Low Code Platforms · No Code Platforms
Open-source low-code platform for building internal tools with drag-and-drop UI, reactive data bindings, and real-time collaboration.
Laudspeaker
Marketing · Automation
Open-source customer engagement platform for building visual, event-triggered messaging journeys across email, SMS, push, in-app, and webhooks.
LibreChat
Developer Tools · AI Assistants
Unite every major AI model in one self-hosted chat platform with agents, code execution, MCP tools, and enterprise authentication.
Vikunja
Project Management
Self-hosted task management with natural-language quick-add, multiple views, and a fully documented REST API — your tasks, your infrastructure, zero lock-in.