$ show zloirock/core-js
core-js is a modular JavaScript standard library and polyfill system, not an end-user application. In production it supplies spec-compliant implementations of ECMAScript features, TC39 proposals, and selected web platform APIs for environments that lack native support. Its primary runtime behavior is side-effectful import: consumers load entry points such as `core-js`, `core-js/actual`, `core-js/full`, `core-js/es`, or granular per-feature modules, and the library either patches built-in constructors/prototypes or, in the `core-js-pure` variant, exports standalone implementations without global pollution. The architecture is a monorepo of packages: `core-js` (global polyfills), `core-js-pure` (pollution-free), `core-js-bundle` (prebuilt bundle), `core-js-compat` (compatibility data and module-selection engine), and `core-js-builder` (custom bundle generator). The implementation is split into thousands of tiny modules under `packages/core-js/modules/`, backed by a shared `internals/` layer that provides low-level spec operations, feature detection, environment/bug detection, iterator construction, collection internals, and export plumbing. Polyfill activation is decided by a `$({ target, stat, proto, forced }, ...)` export contract plus per-module `FORCED` flags derived from runtime probes and engine-version checks. Entry-point tiers (`es`, `stable`, `actual`, `full`, `stage`, `proposals`) map to spec maturity levels. Its primary data flow is configuration-driven: a consumer chooses an import path or, through Babel/swc integration, a set of target environments; `core-js-compat` converts targets into the minimum required module set; and `core-js-builder` can produce a custom bundle. The library itself depends on very few runtime dependencies; Babel, webpack, QUnit, Karma, and a matrix of JS engines are used for building, bundling, and testing. The codebase is unusually rigorous about spec conformance, including engine-specific bug workarounds and dual global/pure test suites. It is effectively the reference polyfill engine behind Babel's `useBuiltIns` and is highly study-worthy for anyone implementing low-level JavaScript compatibility layers.
The LLM identified 5 files worth highlighting for reuse:
A tiny, self-contained helper that converts prototype methods into plain callable functions by extracting and caching the native method. It avoids repeated `.call`/`.apply` overhead and works in ES3 environments, making it an elegant reusable pattern for any codebase that needs to call built-in methods safely and efficiently across engines.
A generic factory that wraps an iterator in a proxy implementing custom behavior for iterator helpers such as `map`, `filter`, `take`, and `drop`. It encapsulates iterator state, closing semantics, and result-object creation in one reusable abstraction. This is non-obvious, high-craftsmanship code that could be adapted for any iterator-transform library.
A shared implementation of strong Map/Set semantics, including same-value-zero key handling, iteration ordering, and internal slot storage. It is the foundation for Map, Set, and their subclasses, and demonstrates how to build spec-compliant collection behavior in a single maintainable module. Useful for anyone implementing compatible collection classes.
The programmatic API for mapping browser/engine targets to the exact set of core-js modules required. It ingests browserslist-style queries, merges version data from `core-js-compat` data files, and returns a normalized module list. This is a clean, data-driven, reusable component for build tools and transpilers that need to decide which polyfills to inject.
A builder that takes target environments, module inclusion/exclusion lists, and output format to produce custom core-js bundles. It encapsulates the webpack-based bundling logic behind a simple API/CLI, making it reusable beyond core-js itself as a template for generating environment-tailored JavaScript bundles.