core-js-pure is a modular standard library for JavaScript that provides polyfills for ECMAScript features up to 2025 without global namespace pollution. Unlike the main core-js package, core-js-pure allows developers to import only the specific polyfills they need as pure functions and constructors, enabling fine-grained control over bundle size while maintaining JavaScript compatibility across different environments and browser versions.
npm install core-js-pure// Import specific features (recommended)
import Array from 'core-js-pure/stable/array';
import Promise from 'core-js-pure/stable/promise';
import Set from 'core-js-pure/stable/set';
// Import individual methods
import arrayFrom from 'core-js-pure/stable/array/from';
import promiseAllSettled from 'core-js-pure/stable/promise/all-settled';
// Import everything (not recommended for production)
import 'core-js-pure';For ES modules (import from specific paths):
import Array from 'core-js-pure/stable/array';
import Promise from 'core-js-pure/stable/promise';
import Set from 'core-js-pure/stable/set';CommonJS:
const Array = require('core-js-pure/stable/array');
const Promise = require('core-js-pure/stable/promise');import Array from 'core-js-pure/stable/array';
import Promise from 'core-js-pure/stable/promise';
import Set from 'core-js-pure/stable/set';
// Array methods as pure functions
const result = Array.from([1, 2, 3]).map(x => x * 2);
console.log(result); // [2, 4, 6]
// Promise with modern methods
Promise.allSettled([
Promise.resolve(1),
Promise.reject(2),
Promise.resolve(3)
]).then(results => {
console.log(results);
// [
// { status: 'fulfilled', value: 1 },
// { status: 'rejected', reason: 2 },
// { status: 'fulfilled', value: 3 }
// ]
});
// Set with modern methods
const set1 = new Set([1, 2, 3]);
const set2 = new Set([3, 4, 5]);
const union = set1.union(set2);
console.log([...union]); // [1, 2, 3, 4, 5]core-js-pure is organized around several key concepts:
stable/, actual/, es/, features/, full/) for different feature sets and compatibility levelsvirtual/ subdirectoriesstable/ - Use for maximum compatibility with only standardized ECMAScript featuresactual/ - Use for latest features including stage 3-4 TC39 proposalses/ - Use for specific ECMAScript version compatibilityfeatures/ - Use for individual feature imports with automatic dependency resolutionfull/ - Use for everything including experimental proposals (not recommended for production)Comprehensive array methods including modern additions like flat, flatMap, at, and immutable operations.
interface ArrayConstructor {
from<T>(arrayLike: ArrayLike<T> | Iterable<T>): T[];
from<T, U>(arrayLike: ArrayLike<T> | Iterable<T>, mapfn: (v: T, k: number) => U, thisArg?: any): U[];
fromAsync<T>(asyncIterable: AsyncIterable<T> | Iterable<T | Promise<T>>): Promise<T[]>;
of<T>(...items: T[]): T[];
isArray(arg: any): arg is any[];
}
interface Array<T> {
at(index: number): T | undefined;
flat<D = 1>(depth?: D): FlatArray<T, D>[];
flatMap<U, This = undefined>(callback: (value: T, index: number, array: T[]) => U | ReadonlyArray<U>, thisArg?: This): U[];
toReversed(): T[];
toSorted(compareFn?: (a: T, b: T) => number): T[];
toSpliced(start: number, deleteCount?: number, ...items: T[]): T[];
with(index: number, value: T): T[];
}Modern Promise methods including allSettled, any, try, and withResolvers for advanced async patterns.
interface PromiseConstructor {
allSettled<T>(values: Iterable<T | PromiseLike<T>>): Promise<PromiseSettledResult<Awaited<T>>[]>;
any<T>(values: Iterable<T | PromiseLike<T>>): Promise<Awaited<T>>;
try<T>(fn: () => T | PromiseLike<T>): Promise<T>;
withResolvers<T>(): { promise: Promise<T>; resolve: (value: T | PromiseLike<T>) => void; reject: (reason?: any) => void; };
}
interface Promise<T> {
finally(onfinally?: (() => void) | undefined | null): Promise<T>;
}Complete Object static methods including property management, iteration, and modern utilities.
interface ObjectConstructor {
assign<T, U>(target: T, source: U): T & U;
create(proto: object | null, propertiesObject?: PropertyDescriptorMap): any;
entries<T>(obj: { [s: string]: T } | ArrayLike<T>): [string, T][];
fromEntries<T = any>(entries: Iterable<readonly [PropertyKey, T]>): { [k: string]: T };
groupBy<T, K extends PropertyKey>(items: Iterable<T>, keyFn: (item: T, index: number) => K): Partial<Record<K, T[]>>;
hasOwn(obj: object, key: PropertyKey): boolean;
keys(obj: {}): string[];
values<T>(obj: { [s: string]: T } | ArrayLike<T>): T[];
}String methods for modern text processing including Unicode handling and pattern matching.
interface StringConstructor {
fromCodePoint(...codePoints: number[]): string;
raw(template: TemplateStringsArray, ...substitutions: any[]): string;
}
interface String {
at(index: number): string | undefined;
codePointAt(pos: number): number | undefined;
endsWith(searchString: string, length?: number): boolean;
includes(searchString: string, position?: number): boolean;
isWellFormed(): boolean;
matchAll(regexp: RegExp): IterableIterator<RegExpMatchArray>;
padEnd(targetLength: number, padString?: string): string;
padStart(targetLength: number, padString?: string): string;
repeat(count: number): string;
replaceAll(searchValue: string | RegExp, replaceValue: string | ((substring: string, ...args: any[]) => string)): string;
startsWith(searchString: string, position?: number): boolean;
toWellFormed(): string;
trimEnd(): string;
trimStart(): string;
}Symbol constructor and well-known symbols for customizing language behavior.
interface SymbolConstructor {
for(key: string): symbol;
keyFor(sym: symbol): string | undefined;
readonly asyncDispose: unique symbol;
readonly asyncIterator: unique symbol;
readonly dispose: unique symbol;
readonly hasInstance: unique symbol;
readonly isConcatSpreadable: unique symbol;
readonly iterator: unique symbol;
readonly match: unique symbol;
readonly matchAll: unique symbol;
readonly replace: unique symbol;
readonly search: unique symbol;
readonly species: unique symbol;
readonly split: unique symbol;
readonly toPrimitive: unique symbol;
readonly toStringTag: unique symbol;
readonly unscopables: unique symbol;
}Modern Set and Map with advanced operations like union, intersection, and difference.
interface Set<T> {
difference<U>(other: SetLike<U>): Set<T>;
intersection<U>(other: SetLike<U>): Set<T & U>;
union<U>(other: SetLike<U>): Set<T | U>;
symmetricDifference<U>(other: SetLike<U>): Set<T | U>;
isDisjointFrom<U>(other: SetLike<U>): boolean;
isSubsetOf<U>(other: SetLike<U>): boolean;
isSupersetOf<U>(other: SetLike<U>): boolean;
}
interface MapConstructor {
groupBy<K, T>(items: Iterable<T>, keyFn: (item: T, index: number) => K): Map<K, T[]>;
}Extended Math methods for advanced mathematical operations and precision handling.
interface Math {
acosh(x: number): number;
asinh(x: number): number;
atanh(x: number): number;
cbrt(x: number): number;
clz32(x: number): number;
cosh(x: number): number;
expm1(x: number): number;
f16round(x: number): number;
fround(x: number): number;
hypot(...values: number[]): number;
imul(x: number, y: number): number;
log10(x: number): number;
log1p(x: number): number;
log2(x: number): number;
sign(x: number): number;
sinh(x: number): number;
sumPrecise(items: Iterable<number>): number;
tanh(x: number): number;
trunc(x: number): number;
}Binary data handling with enhanced TypedArray methods and encoding utilities.
interface Uint8Array {
fromBase64(string: string, options?: { alphabet?: 'base64' | 'base64url'; strict?: boolean }): Uint8Array;
toBase64(options?: { alphabet?: 'base64' | 'base64url' }): string;
fromHex(string: string): Uint8Array;
toHex(): string;
setFromBase64(string: string, offset?: number): { read: number; written: number };
setFromHex(string: string, offset?: number): { read: number; written: number };
}
interface TypedArrayConstructor {
from<T>(arrayLike: ArrayLike<T> | Iterable<T>): TypedArray;
of(...items: number[]): TypedArray;
}Modern iterator methods for functional programming patterns with lazy evaluation.
interface Iterator<T> {
map<U>(mapperFn: (value: T) => U): Iterator<U>;
filter(filtererFn: (value: T) => boolean): Iterator<T>;
take(limit: number): Iterator<T>;
drop(limit: number): Iterator<T>;
flatMap<U>(mapperFn: (value: T) => Iterator<U> | Iterable<U>): Iterator<U>;
reduce<U>(reducerFn: (accumulator: U, currentValue: T) => U, initialValue: U): U;
toArray(): T[];
forEach(callbackFn: (value: T) => void): void;
some(predicate: (value: T) => boolean): boolean;
every(predicate: (value: T) => boolean): boolean;
find(predicate: (value: T) => boolean): T | undefined;
dispose(): void;
}Complete Reflect API for meta-programming and proxy operations.
interface Reflect {
apply<T, A extends readonly any[], R>(target: (this: T, ...args: A) => R, thisArgument: T, argumentsList: Readonly<A>): R;
construct<A extends readonly any[], R>(target: new (...args: A) => R, argumentsList: Readonly<A>, newTarget?: any): R;
defineProperty(target: object, propertyKey: PropertyKey, attributes: PropertyDescriptor): boolean;
deleteProperty(target: object, propertyKey: PropertyKey): boolean;
get<T extends object, P extends PropertyKey>(target: T, propertyKey: P, receiver?: unknown): T[P];
getOwnPropertyDescriptor(target: object, propertyKey: PropertyKey): PropertyDescriptor | undefined;
getPrototypeOf(target: object): object | null;
has(target: object, propertyKey: PropertyKey): boolean;
isExtensible(target: object): boolean;
ownKeys(target: object): (string | symbol)[];
preventExtensions(target: object): boolean;
set<T extends object, P extends PropertyKey>(target: T, propertyKey: P, value: T[P], receiver?: any): boolean;
setPrototypeOf(target: object, proto: object | null): boolean;
}Cross-platform web standard APIs including URL handling, Base64, and structured cloning.
declare function atob(data: string): string;
declare function btoa(data: string): string;
declare function structuredClone<T>(value: T, options?: { transfer?: Transferable[] }): T;
declare function queueMicrotask(callback: () => void): void;
declare class URL {
constructor(url: string | URL, base?: string | URL);
href: string;
origin: string;
protocol: string;
username: string;
password: string;
host: string;
hostname: string;
port: string;
pathname: string;
search: string;
searchParams: URLSearchParams;
hash: string;
static canParse(url: string, base?: string): boolean;
static parse(url: string, base?: string): URL | null;
toString(): string;
toJSON(): string;
}
declare class URLSearchParams {
constructor(init?: string | string[][] | Record<string, string> | URLSearchParams);
append(name: string, value: string): void;
delete(name: string, value?: string): void;
get(name: string): string | null;
getAll(name: string): string[];
has(name: string, value?: string): boolean;
set(name: string, value: string): void;
sort(): void;
toString(): string;
entries(): IterableIterator<[string, string]>;
keys(): IterableIterator<string>;
values(): IterableIterator<string>;
forEach(callbackfn: (value: string, key: string, parent: URLSearchParams) => void, thisArg?: any): void;
readonly size: number;
}Modern error types for better error handling and resource management.
declare class AggregateError extends Error {
constructor(errors: Iterable<any>, message?: string);
errors: any[];
}
declare class SuppressedError extends Error {
constructor(error: any, suppressed: any, message?: string);
error: any;
suppressed: any;
}
declare class DOMException extends Error {
constructor(message?: string, name?: string);
readonly name: string;
readonly message: string;
readonly code: number;
}