Support older browsers like IE8 in a JavaScript project by loading es5-shim before any other scripts
Use modern Array methods like map, filter, and reduce safely in legacy browser environments
Polyfill specific ES5 methods individually as standalone npm packages to keep bundle size minimal
Understand the partial limitations of es5-sham before deciding whether its incomplete implementations are acceptable for your use case
Load via two script tags in HTML or via npm install, no configuration needed.
es5-shim is a JavaScript library that fills in missing features for older web browsers that do not support a version of JavaScript called ECMAScript 5 (ES5). When this standard was released around 2009, many browsers in use at the time did not yet implement all of its features. This library lets developers write code that uses those modern features while still supporting users on older browsers, because the library provides its own versions of the missing pieces. The library ships as two separate files with different purposes. The first, es5-shim.js, contains implementations of features that can be faithfully reproduced in older JavaScript engines: things like Array methods for filtering, mapping, and reducing data, string trimming, Object.keys for listing an object's properties, Date formatting utilities, and Function.prototype.bind for controlling how functions refer to their context. These implementations behave correctly according to the specification, so using them is safe. The second file, es5-sham.js, handles features that cannot be fully reproduced in older environments. These are listed with warning labels throughout the README and are intended mainly to prevent crashes rather than to provide correct behavior. For instance, Object.create roughly works for basic inheritance but does not reliably handle the full ES5 property descriptor system. Object.freeze and Object.seal appear to succeed but do not actually enforce immutability in old engines. The README is explicit that developers need to decide for themselves whether these partial implementations are acceptable for their use case. The library is installed via npm or included directly from a CDN with two script tags. It should be loaded before any other scripts so that the patched methods are available from the start. Individual shims for many of the included features are also available as standalone npm packages for projects that only need one or two specific methods.
← es-shims on gitmyhub — every repo by this author, as a profile.
Verify against the repo before relying on details.