{"id":10864,"library":"ext","title":"ext: JavaScript Utilities and Polyfills","description":"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.","status":"active","version":"1.7.0","language":"javascript","source_language":"en","source_url":"https://github.com/medikoo/es5-ext#ext","tags":["javascript","ecmascript","es","es6","extensions","ext","addons","lodash","extras"],"install":[{"cmd":"npm install ext","lang":"bash","label":"npm"},{"cmd":"yarn add ext","lang":"bash","label":"yarn"},{"cmd":"pnpm add ext","lang":"bash","label":"pnpm"}],"dependencies":[],"imports":[{"note":"The `ext` package encourages granular ESM imports for specific utilities. CommonJS `require()` is generally discouraged in modern contexts.","wrong":"const globalThis = require('ext/global-this');","symbol":"globalThis","correct":"import globalThis from 'ext/global-this';"},{"note":"Each utility is typically imported from its specific subpath. There is no single top-level 'object' module export for all its methods.","wrong":"import { clear } from 'ext/object'; // Incorrect path/named import\nimport objectClear from 'ext/object/clear.js'; // .js extension is usually not needed","symbol":"objectClear","correct":"import objectClear from 'ext/object/clear';"},{"note":"For methods that extend prototypes (like String.prototype.camelToHyphen), the library exports the function directly. You can call it with `.call()` or manually extend the prototype if desired, adhering to the 'non-invasive' principle.","wrong":"import { camelToHyphen } from 'ext/string'; // Incorrect, it's a subpath module\nimport 'ext/string/#/camel-to-hyphen'; // Old `es5-ext` path or direct prototype extension side-effect","symbol":"camelToHyphen","correct":"import camelToHyphen from 'ext/string/camel-to-hyphen';"}],"quickstart":{"code":"import globalThis from 'ext/global-this';\nimport objectClear from 'ext/object/clear';\nimport camelToHyphen from 'ext/string/camel-to-hyphen';\nimport identity from 'ext/function/identity';\n\n// Access globalThis reliably across environments\nconsole.log('Is this browser globalThis?', typeof window !== 'undefined' && globalThis === window);\nconsole.log('Is this Node globalThis?', typeof global !== 'undefined' && globalThis === global);\n\n// Clear an object's properties\nconst data = { a: 1, b: 'two', c: true };\nconsole.log('Original object:', data); // { a: 1, b: 'two', c: true }\nobjectClear(data);\nconsole.log('Object after clear:', data); // {}\n\n// Convert camelCase to hyphen-case\nconst camelCaseString = 'myCamelCaseString';\nconst hyphenatedString = camelToHyphen.call(camelCaseString);\nconsole.log(`'${camelCaseString}' hyphenated: '${hyphenatedString}'`); // 'my-camel-case-string'\n\n// Use a simple identity function\nconst value = 42;\nconst transformedValue = identity(value);\nconsole.log(`Identity of ${value} is ${transformedValue}`); // 'Identity of 42 is 42'\n","lang":"typescript","description":"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."},"warnings":[{"fix":"Update all package references and import/require paths in your codebase to use `ext` instead of `es5-ext`. For example, change `import 'es5-ext/array/#/clear'` to `import arrayClear from 'ext/array/clear'` and then use `arrayClear.call(myArray)`.","message":"The package was renamed from `es5-ext` to `ext`. Users migrating from `es5-ext` will need to update all import paths (e.g., `require('es5-ext/object/clear')` becomes `import objectClear from 'ext/object/clear';`). While `es5-ext` still receives maintenance, `ext` is the officially supported name.","severity":"breaking","affected_versions":">=1.0.0 (for `ext` package)"},{"fix":"Ensure your Node.js and npm installations are up-to-date. If issues persist, try `npm install ext --ignore-scripts`. If a critical setup is missed, consult the official GitHub issues for specific workarounds or report the problem with detailed environment information.","message":"The package's `postinstall` script has historically caused issues on various operating systems (Windows, specific Linux terminals, Powershell), potentially leading to installation failures or errors. While recent `0.10.x` releases have focused on patching these, environmental-specific problems may still arise.","severity":"gotcha","affected_versions":"All versions, particularly problematic in `0.10.x` prior to `0.10.64`."},{"fix":"Adopt explicit ESM `import` statements for specific utilities from their respective subpaths. Ensure your project is configured to handle ESM imports correctly (e.g., `\"type\": \"module\"` in `package.json`).","message":"The library primarily promotes granular ESM imports (e.g., `import util from 'ext/path/to/util';`). Attempting to use CommonJS `require()` syntax with modern `ext` versions in an ESM-configured project, or assuming a single top-level default export for multiple utilities, will lead to module resolution errors.","severity":"gotcha","affected_versions":">=1.0.0"}],"env_vars":null,"last_verified":"2026-04-19T00:00:00.000Z","next_check":"2026-07-18T00:00:00.000Z","problems":[{"fix":"Update Node.js/npm. If the error persists, install with `npm install ext --ignore-scripts`. This bypasses the script but might require manual setup if it performs critical configuration. Consult package GitHub issues for specific workarounds.","cause":"The `postinstall` script, which runs after `npm install`, encountered an error due to environmental factors, shell compatibility, or permissions issues on Windows, Powershell, or certain Linux terminals.","error":"Command failed with exit code 1"},{"fix":"Update the `ext` package to at least `v0.10.63` (or the latest `1.x` series) which includes bug fixes for improved regex robustness and better support for modern JavaScript function definitions.","cause":"Older versions of the library relied on problematic regex patterns, particularly affecting methods that parse function definitions, leading to failures with ES2015+ syntax.","error":"TypeError: Cannot read property 'match' of null (or similar regex errors) when using function#toStringTokens()"},{"fix":"Verify the exact import path for the specific utility you are trying to use (e.g., `import clear from 'ext/object/clear';`). Ensure your project's module resolution (`package.json#type`) aligns with how you are importing modules.","cause":"This error typically occurs when trying to `import` the package using an incorrect path or if the environment is configured for CommonJS while `ext` is being treated as an ESM module, or vice-versa, specifically for subpath imports.","error":"Error [ERR_MODULE_NOT_FOUND]: Cannot find package 'ext' imported from ..."}],"ecosystem":"npm"}