does this JavaScript environment conform to ECMAScript 5?
I made this after reading Kangax's terrific ES5 compatibility table. Rather than feature-detect every single piece of ECMAScript 5, I've selected the smallest number of tests to identify non-conformant JavaScript environments.
parseInt()
ignores leading zeros
- after this test, we get a
false
in most old browsers
Strict Mode
- after this test, we get a
false
in Internet Explorer 9 and environments or apps that load ES5-shim
Date.prototype.toISOString
- after this test, we get a
false
in EJS
Job done!
I've manually tested in a range of environments:
-
true
: Node.js (0.12), Chrome (43), Safari (8), Firefox (38), Internet Explorer (10, 11), Edge -
false
: Internet Explorer (6, 7, 8, 9)
- CommonJS (e.g. Node.js, Browserify, etc) use index.js
var isES5Supported = require('is-es5-supported');
console.log(isES5Supported); // `true` or `false`
- dist/index.js is a UMD-wrapped version for browsers and AMD
<script src="dist/index.js"></script>
<script>
console.log(isES5Supported); // `true` or `false`
</script>
-
this approach does assume correlations between the 3 included tests and the rest of the ECMASCript 5 implementation, which might not return correct results in exotic environments
-
Internet Explorer 10 Platform Preview 2 will get a
false
(who cares?)