or run

npx @tessl/cli init
Log in

Version

Tile

Overview

Evals

Files

docs

index.md
tile.json

tessl/npm-next--polyfill-module

A standard library polyfill for ES Modules supporting browsers providing polyfills for missing JavaScript methods

Workspace
tessl
Visibility
Public
Created
Last updated
Describes
npmpkg:npm/@next/polyfill-module@15.5.x

To install, run

npx @tessl/cli install tessl/npm-next--polyfill-module@15.5.0

index.mddocs/

@next/polyfill-module

A 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.

Package Information

  • Package Name: @next/polyfill-module
  • Package Type: npm
  • Language: JavaScript
  • Installation: npm install @next/polyfill-module (typically bundled, not installed directly)
  • Distribution: IIFE (Immediately Invoked Function Expression) bundle

Core Imports

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');

Basic Usage

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')); // true

Architecture

This 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:

  • Only apply when native implementations are missing
  • Follow ECMAScript specification behavior exactly
  • Provide compatibility for browsers that support ES modules but lack specific methods
  • Extend native prototypes and objects directly

Capabilities

String Prototype Extensions

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;

Symbol Prototype Extensions

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;

Array Prototype Extensions

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;

Promise Prototype Extensions

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>;

Object Static Method Extensions

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;

URL Static Method Extensions

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;

Browser Compatibility

This package specifically targets browsers that support ES modules but are missing certain standard methods:

  • Edge 16+: Missing trimStart/End, description, flat/flatMap, fromEntries, at, hasOwn, canParse
  • Firefox 60+: Missing some methods in earlier versions within the range
  • Chrome 61+: Missing some methods in earlier versions within the range
  • Safari 10.1+: Missing some methods in earlier versions within the range

Each polyfill includes detailed compatibility information and only applies when the native implementation is not available.

Error Handling

The polyfills implement standard ECMAScript error behavior:

  • Object.hasOwn() throws TypeError if the first argument is null or undefined
  • URL.canParse() returns false for invalid URLs instead of throwing
  • Other methods follow their respective specification error handling

Implementation Notes

  • All polyfills check for existing native implementations before applying
  • Implementations follow ECMAScript specifications exactly
  • Source code includes detailed browser compatibility comments
  • Built as IIFE bundle for immediate execution in browser environments
  • No external dependencies or imports required