A standard library polyfill for ES Modules supporting browsers providing polyfills for missing JavaScript methods
npx @tessl/cli install tessl/npm-next--polyfill-module@15.5.0A standard library polyfill for ES Modules supporting browsers (Edge 16+, Firefox 60+, Chrome 61+, Safari 10.1+) that provides implementations of modern JavaScript methods missing in older browser versions.
npm install @next/polyfill-module (typically bundled, not installed directly)This package is designed to be loaded as an IIFE bundle that automatically applies polyfills to global prototypes. It does not provide traditional import/export functionality.
<script src="node_modules/@next/polyfill-module/dist/polyfill-module.js"></script>Or in a build system that processes the main entry point:
// This will execute the polyfills automatically
require('@next/polyfill-module');The polyfills are applied automatically when the script is loaded. After loading, you can use the polyfilled methods directly on native prototypes:
// After loading the polyfill module, these methods are available
const text = " hello world ";
console.log(text.trimStart()); // "hello world "
console.log(text.trimEnd()); // " hello world"
const sym = Symbol('description');
console.log(sym.description); // "description"
const nested = [1, [2, [3, 4]]];
console.log(nested.flat(2)); // [1, 2, 3, 4]
const promise = Promise.resolve(42);
promise.finally(() => console.log('cleanup'));
const entries = [['a', 1], ['b', 2]];
const obj = Object.fromEntries(entries); // { a: 1, b: 2 }
const arr = [1, 2, 3];
console.log(arr.at(-1)); // 3
console.log(Object.hasOwn(obj, 'a')); // true
console.log(URL.canParse('https://example.com')); // trueThis package implements feature detection for each polyfill, only extending native prototypes when the methods are not already available. Each polyfill includes detailed browser compatibility information and implements standard behavior as defined by ECMAScript specifications.
The polyfills are designed to:
Polyfills for string trimming methods that remove whitespace from the beginning or end of strings.
/**
* Removes whitespace from the beginning of a string
* Available in: Edge (never), Firefox 61+, Chrome 66+, Safari 12+
*/
String.prototype.trimStart(): string;
/**
* Removes whitespace from the end of a string
* Available in: Edge (never), Firefox 61+, Chrome 66+, Safari 12+
*/
String.prototype.trimEnd(): string;Polyfill for accessing symbol descriptions.
/**
* Gets the description of a Symbol
* Available in: Edge (never), Firefox 63+, Chrome 70+, Safari 12.1+
*/
Symbol.prototype.description: string | undefined;Polyfills for array flattening and element access methods.
/**
* Flattens nested arrays to specified depth
* Available in: Edge (never), Firefox 62+, Chrome 69+, Safari 12+
* @param depth - Maximum depth to flatten (default: 1)
*/
Array.prototype.flat(depth?: number): any[];
/**
* Maps each element using a function and flattens the result
* Available in: Edge (never), Firefox 62+, Chrome 69+, Safari 12+
* @param callback - Function to execute on each element
* @param thisArg - Value to use as 'this' when executing callback
*/
Array.prototype.flatMap<U>(
callback: (value: any, index: number, array: any[]) => U | U[],
thisArg?: any
): U[];
/**
* Accesses array element by index with support for negative indexing
* Available in: Edge 92+, Firefox 90+, Chrome 92+, Safari 15.4+
* @param index - Index to access (negative indices count from end)
*/
Array.prototype.at(index: number): any;Polyfill for promise cleanup functionality.
/**
* Returns a promise that executes callback when settled (resolved or rejected)
* Available in: Edge 18+, Firefox 58+, Chrome 63+, Safari 11.1+
* @param callback - Function to execute when promise settles
*/
Promise.prototype.finally(callback: () => void): Promise<any>;Polyfills for object utility methods.
/**
* Creates an object from key-value pairs
* Available in: Edge (never), Firefox 63+, Chrome 73+, Safari 12.1+
* @param iterable - Iterable of key-value pairs
* @throws TypeError if iterable entries don't have numeric indices
*/
Object.fromEntries(iterable: Iterable<readonly [PropertyKey, any]>): any;
/**
* Checks if object has specified property as own property
* Available in: Edge 93+, Firefox 92+, Chrome 93+, Safari 15.4+
* @param object - Object to check
* @param property - Property name to check for
* @throws TypeError if object is null or undefined
*/
Object.hasOwn(object: any, property: PropertyKey): boolean;Polyfill for URL validation utility.
/**
* Checks if a URL string can be parsed
* Available in: Edge 120+, Firefox 115+, Chrome 120+, Safari 17.0+
* @param url - URL string to validate
* @param base - Optional base URL for relative URL resolution
*/
URL.canParse(url: string, base?: string): boolean;This package specifically targets browsers that support ES modules but are missing certain standard methods:
Each polyfill includes detailed compatibility information and only applies when the native implementation is not available.
The polyfills implement standard ECMAScript error behavior:
Object.hasOwn() throws TypeError if the first argument is null or undefinedURL.canParse() returns false for invalid URLs instead of throwing