Polyfills of built-in objects and methods to run IE6 and later code in early DHTML browsers.
And, tool to add the required polyfills to your code.
decodeURI
,decodeURIComponent
encodeURI
,encodeURIComponent
Function.prototype.apply
,Function.prototype.call
Array.prototype.pop
,Array.prototype.push
,Array.prototype.shift
,Array.prototype.splice
,Array.prototype.unshift
Array.prototype.indexOf
- ECMAScript2/es2-postprocessor A post-processor that workaround bugs in the Javascript implementation and warns about unimplemented.
- ECMAScript2/es2-regexpcompat, Mobile IE4 does not support
RegExp
!
const es2ToEs3 = require('es2-to-es3'),
resultObject = {};
sourceOfMain = es2ToEs3(sourceOfMain, {minIEVersion: 5, resultObject : resultObject});
console.log(resultObject.requiredPolyfills); // ["Function.prototype.apply", ... ]
console.log(resultObject.embeddedPolyfills); // ["Function.prototype.apply", ... ]
sourceOfLibrary = es2ToEs3(sourceOfLibrary, {minIEVersion: 5, skipEmbedPolyfills : resultObject.embeddedPolyfills});
gulp.task('post_process_for_ie_lte_5',
function(){
return gulp.src('main.js')
.pipe(
require('es2-to-es3').gulp({minIEVersion: 5})
).pipe(
gulp.dest('js/legacy')
);
}
);
See the gulpfile.js
of the following project for other usage examples.
Property | Description | Default value |
---|---|---|
minIEVersion |
5.5 |
|
minOperaVersion |
8.0 |
|
minGeckoVersion |
0.9 |
|
skipEmbedPolyfills |
Set result.embeddedPolyfills if you wont to embed twice. * : Never embed. |
[] |
forceEmbedPolyfills |
Set result.requiredPolyfills if you want to embed for other script file. |
[] |
resultObject |
Set resultObject = {} if you want to use it for later tasks. |
null |
- Embedding polyfills is simply done by looking at the Identifier name. This may result in unnecessary embedding. For Example, Embed
Array.prototype.indexOf
polyfill for"str".indexOf()
. In this case, useskipEmbedPolyfills : ["Array.prototype.indexOf"]
.
Property | Description | Example |
---|---|---|
requiredPolyfills |
Contains forceEmbedPolyfills and skipEmbedPolyfills . |
[] |
embeddedPolyfills |
[] |
Built-in objects and methods | IE | Opera | Gecko | Chrome | Safari |
---|---|---|---|---|---|
decodeURI |
5.5 | 7.0 | 0.6 | 1 | ? |
decodeURIComponent |
5.5 | 7.0 | 0.6 | 1 | ? |
encodeURI |
5.5 | 7.0 | 0.6 | 1 | ? |
encodeURIComponent |
5.5 | 7.0 | 0.6 | 1 | ? |
Function.prototype.apply |
5.5 | 7.0 | 0.6 | 1 | ? |
Function.prototype.call |
5.5 | 7.0 | 0.6 | 1 | ? |
Array.prototype.pop |
5.5 | 7.0 | 0.6 | 1 | ? |
Array.prototype.push |
5.5 | 7.0 | 0.6 | 1 | ? |
Array.prototype.shift |
5.5 | 7.0 | 0.6 | 1 | ? |
Array.prototype.splice |
5.5 | 7.0 | 0.6 | 1 | ? |
Array.prototype.unshift |
5.5 | 7.0 | 0.6 | 1 | ? |
Array.prototype.indexOf (ECMAScript 5+) |
9 | 9.60 | 1.8 | 1 | ? |
atob (*1, HTML5+) |
10 | 10.50 | 1.0 | 1 | ? |
btoa (*1, HTML5+) |
10 | 10.50 | 1.0 | 1 | ? |
JSON (*2, ECMAScript 5+) |
8 | 10.50 | 1.9.1 | 3 | 4.0 |
- es2-base64
- es2-json (in preparation...)
Built-in objects and methods | Author | Link to original | License |
---|---|---|---|
decodeURI , decodeURIComponent , encodeURI , encodeURIComponent | ヌルコムアーカイブス・デジタル制作室 | TransURI (UTF-8) | ? |
Array.prototype.indexOf | Mozilla Contributors | MDN / Array.prototype.indexOf | MIT or public domain |
Array.prototype.pop , Array.prototype.push , Array.prototype.shift , Array.prototype.splice , Array.prototype.unshift ,Function.prototype.apply , Function.prototype.call
| ofk | ?D of K / Function.prototype.applyとかArray.prototype.spliceのIE5用のコード | ? |
es2-to-es3 is licensed under MIT license.