ext: JavaScript Utilities and Polyfills

1.7.0 · active · verified Sun Apr 19

The `ext` package, formerly known as `es5-ext`, is a comprehensive JavaScript utility library that provides a collection of non-standard or soon-to-be-standard language extensions and polyfills. It differentiates itself by offering these utilities in a future-proof and non-invasive manner, meaning it generally avoids polluting global prototypes without explicit action, and is designed to be compatible with ES3+ environments without requiring a transpilation step. The library is highly modular, allowing developers to import only the specific functions or objects they need, such as `globalThis`, `Object.clear`, or `String.prototype.camelToHyphen` functionality. While the package has seen recent maintenance releases (e.g., `v0.10.64` in February 2024) addressing stability issues, the latest feature-rich version is `v1.7.0`, released in August 2022. Its release cadence combines frequent bug fixes with less frequent, but impactful, feature additions, ensuring both stability and progressive enhancement capabilities.

Common errors

Warnings

Install

Imports

Quickstart

Demonstrates importing and using `globalThis`, `objectClear`, `camelToHyphen`, and `identity` utilities. It shows cross-environment `globalThis` access, clearing an object, string case conversion, and a basic identity function.

import globalThis from 'ext/global-this';
import objectClear from 'ext/object/clear';
import camelToHyphen from 'ext/string/camel-to-hyphen';
import identity from 'ext/function/identity';

// Access globalThis reliably across environments
console.log('Is this browser globalThis?', typeof window !== 'undefined' && globalThis === window);
console.log('Is this Node globalThis?', typeof global !== 'undefined' && globalThis === global);

// Clear an object's properties
const data = { a: 1, b: 'two', c: true };
console.log('Original object:', data); // { a: 1, b: 'two', c: true }
objectClear(data);
console.log('Object after clear:', data); // {}

// Convert camelCase to hyphen-case
const camelCaseString = 'myCamelCaseString';
const hyphenatedString = camelToHyphen.call(camelCaseString);
console.log(`'${camelCaseString}' hyphenated: '${hyphenatedString}'`); // 'my-camel-case-string'

// Use a simple identity function
const value = 42;
const transformedValue = identity(value);
console.log(`Identity of ${value} is ${transformedValue}`); // 'Identity of 42 is 42'

view raw JSON →