npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

es5-shim

v4.6.7

Published

ECMAScript 5 compatibility shims for legacy JavaScript engines

Downloads

6,062,869

Readme

es5-shim Version Badge

github actions coverage dependency status dev dependency status License Downloads

npm badge

es5-shim.js and es5-shim.min.js monkey-patch a JavaScript context to contain all EcmaScript 5 methods that can be faithfully emulated with a legacy JavaScript engine. Note: As es5-shim.js is designed to patch the native Javascript engine, it should be the library that is loaded first.

es5-sham.js and es5-sham.min.js monkey-patch other ES5 methods as closely as possible. For these methods, as closely as possible to ES5 is not very close. Many of these shams are intended only to allow code to be written to ES5 without causing run-time errors in older engines. In many cases, this means that these shams cause many ES5 methods to silently fail. Decide carefully whether this is what you want. Note: es5-sham.js requires es5-shim.js to be able to work properly.

Tests

The tests are written with the Jasmine BDD test framework. To run the tests, navigate to /tests/ , or, simply npm install and npm test.

Shims

Complete tests

  • Array.prototype.every (standalone shim)
  • Array.prototype.filter (standalone shim)
  • Array.prototype.forEach (standalone shim)
  • Array.prototype.indexOf (standalone shim)
  • Array.prototype.lastIndexOf (standalone shim)
  • Array.prototype.map (standalone shim)
  • Array.prototype.slice
  • Array.prototype.some (standalone shim)
  • Array.prototype.sort
  • Array.prototype.reduce (standalone shim)
  • Array.prototype.reduceRight (standalone shim)
  • Array.prototype.push (standalone shim)
  • Array.prototype.join
  • Array.prototype.splice (standalone shim)
  • Array.isArray
  • Date.now
  • Date.prototype.toJSON
  • Function.prototype.bind
    • :warning: Caveat: the bound function has a prototype property.
    • :warning: Caveat: bound functions do not try too hard to keep you from manipulating their arguments and caller properties.
    • :warning: Caveat: bound functions don't have checks in call and apply to avoid executing as a constructor.
  • Number.prototype.toExponential (standalone shim)
  • Number.prototype.toFixed
  • Number.prototype.toPrecision
  • Object.keys (standalone shim)
  • String.prototype.split (standalone shim)
  • String.prototype.trim (standalone shim)
  • String.prototype.lastIndexOf (standalone shim)
  • String.prototype.replace
    • Firefox (through v29) natively handles capturing groups incorrectly.
  • Date.parse (for ISO parsing)
  • Date.prototype.toISOString
  • parseInt
  • parseFloat
  • Error.prototype.toString
  • Error.prototype.name
  • Error.prototype.message
  • RegExp.prototype.toString

Shams

  • :warning: Object.create

    For the case of simply "begetting" an object that inherits prototypically from another, this should work fine across legacy engines.

    :warning: The second argument is passed to Object.defineProperties which will probably fail either silently or with extreme prejudice.

  • :warning: Object.getPrototypeOf

    This will return "undefined" in some cases. It uses __proto__ if it's available. Failing that, it uses constructor.prototype, which depends on the constructor property of the object's prototype having not been replaced. If your object was created like this, it won't work:

      function Foo() {
      }
      Foo.prototype = {};

    Because the prototype reassignment destroys the constructor property.

    This will work for all objects that were created using Object.create implemented with this library.

  • :warning: Object.getOwnPropertyNames

    This method uses Object.keys, so it will not be accurate on legacy engines.

  • Object.isSealed

    Returns "false" in all legacy engines for all objects, which is conveniently guaranteed to be accurate.

  • Object.isFrozen

    Returns "false" in all legacy engines for all objects, which is conveniently guaranteed to be accurate.

  • Object.isExtensible

    Works like a charm, by trying very hard to extend the object then redacting the extension.

May fail

  • :warning: Object.getOwnPropertyDescriptor

    The behavior of this shim does not conform to ES5. It should probably not be used at this time, until its behavior has been reviewed and been confirmed to be useful in legacy engines.

  • :warning: Object.defineProperty

    In the worst of circumstances, IE 8 provides a version of this method that only works on DOM objects. This sham will not be installed. The given version of defineProperty will throw an exception if used on non-DOM objects.

    In slightly better circumstances, this method will silently fail to set "writable", "enumerable", and "configurable" properties.

    Providing a getter or setter with "get" or "set" on a descriptor will silently fail on engines that lack "defineGetter" and "defineSetter", which include all versions of IE.

    https://github.com/es-shims/es5-shim/issues#issue/5

  • :warning: Object.defineProperties

    This uses the Object.defineProperty shim.

  • Object.seal

    Silently fails on all legacy engines. This should be fine unless you are depending on the safety and security provisions of this method, which you cannot possibly obtain in legacy engines.

  • Object.freeze

    Silently fails on all legacy engines. This should be fine unless you are depending on the safety and security provisions of this method, which you cannot possibly obtain in legacy engines.

  • Object.preventExtensions

    Silently fails on all legacy engines. This should be fine unless you are depending on the safety and security provisions of this method, which you cannot possibly obtain in legacy engines.

Example of applying ES compatibility shims in a browser project

<script src="https://cdnjs.cloudflare.com/ajax/libs/es5-shim/4.5.14/es5-shim.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/es5-shim/4.5.14/es5-sham.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/json3/3.3.2/json3.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/es6-shim/0.35.5/es6-shim.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/es6-shim/0.35.5/es6-sham.min.js"></script>
<script src="other-libs.js"></script>