es2-to-es3

0.9.2 • Public • Published

es2 to es3

Polyfills of built-in objects and built-in methods to run IE6 and later code in early DHTML browsers.

And, tool to add the required polyfills to your code.

Polyfills

  • 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

Usage

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 plugin

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.

  1. itozyun/web-doc-base
  2. ECMAScript2/es2-code-prettify
  3. itozyun/rerejs

Options

Property Description Default value
minIEVersion 5.5
minOperaVersion 8.0
minGeckoVersion 0.9
skipEmbedPolyfills Set report.embeddedPolyfills if you wont to embed twice. *: Never embed. []
forceEmbedPolyfills Set report.requiredPolyfills if you want to embed for other script file. []
resultObject Set resultObject = {} if you want to use it for later tasks. null
  1. 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, use skipEmbedPolyfills : ["Array.prototype.indexOf"].

Result Object

Property Description Example
requiredPolyfills Contains forceEmbedPolyfills and skipEmbedPolyfills. []
embeddedPolyfills []

Reference : Corresponding starting versions of built-in objects and built-in methods

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(*4) 9 9.60 1.8 1 ?
atob(*1, *3) 10 10.50 1.0 1 ?
btoa(*1, *3) 10 10.50 1.0 1 ?
JSON(*2, *4) 8 10.50 1.9.1 3 4.0
  1. es2-base64
  2. es2-json (in preparation...)
  3. HTML5+
  4. ECMAScript 5+

License

MIT License

Dependency Licenses

Object and Method Author URL 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 ofk ?D of K / Function.prototype.applyとかArray.prototype.spliceのIE5用のコード ?
Function.prototype.apply, Function.prototype.call ofk ?D of K / Function.prototype.applyとかArray.prototype.spliceのIE5用のコード ?

Package Sidebar

Install

npm i es2-to-es3

Weekly Downloads

18

Version

0.9.2

License

MIT

Unpacked Size

16.8 kB

Total Files

4

Last publish

Collaborators

  • itozyun