ES6 Harmony
Provides an equivalent implementation of ES6(Harmony)
in pure ES5
and creates an ES6
environment for old browsers and JavaScript Engines.
ES6 shims in pure ES5.
Install
NPM
Install it from npm
and require
it before any other modules:
$ npm install --save es6-harmony
var ES6 = ;
CDN
If you prefer CDN, then just insert it into your HTML page on the top of other scripts:
<script src="https://cdn.jsdelivr.net/npm/es6-harmony/dist/es6-harmony.min.js"></script>
Examples
"use strict"; var ES6 = ; var arr = 1 2 3; ES6;// 1// 2// 3 console; // [ 'B', 'a', 'r' ] console; // [ 1, 2, 3 ] console; // { [Number: 3] '0': 1, '1': 2, '2': 3, length: 3 } console; // [ 'Bar', 'Bar', 'Bar' ] console;// 1 console;// 0 var it = arr; console; // { done: false, value: [ 0, 1 ] }console; // { done: false, value: [ 1, 2 ] }console; // { done: false, value: [ 2, 3 ] }console; // { done: true, value: undefined } var map = 1 2 "bar" "baz"; console; // 2 map;map; console; // trueconsole; // true it = map; console; // { done: false, value: 1 }console; // { done: false, value: 'bar' }console; // { done: false, value: NaN } ES6;// [ 1, 2 ]// [ 'bar', 'baz' ]// [ 0, {} ]// [ NaN, [Function: Object] ] var set = 1 2 "bar"; console; // 3 set;set; console; // trueconsole; // true it = set; console; // { done: false, value: 1 }console; // { done: false, value: 2 }console; // { done: false, value: 'bar' } ES6;// 1// 2// bar// -0// NaN var wm = ;wm;wm; console; // trueconsole; // false var ws = ; ws;ws; console; // trueconsole; // false console; // trueconsole; // falseconsole; // trueconsole; // true console; // falseconsole; // true var a = {};var b = {}; Object;console; // true console; // { '0': 'b', '1': 'a', '2': 'r' } var sym1 = Symbol"bar";var sym2 = Symbol"baz"; asym1 = "This is symbol property";asym2 = "This is another symbol property"; var allSymbols = Object; console; // 2console; // falseconsole; // false console; // 3 sym1 = Symbol"BAZ";sym2 = Symbol; console; // falseconsole; // true var obj = length: 2 0: "a" 1: 122; it = ArrayprototypeSymboliterator; // { done: false, value: 'a' } console; // [ 'B', 'a', 'r', 1, 2, 3, 1, 2, 4 ] { return Arrayprototypereduce;} console; // 39 { thiswidth = width; thisheight = height;} console; // Box { width: 1, height: 2.22 } console; // { done: false, value: 'a' } var promise = { ;}; promise; // 100// 110// Error
Implemented
-
Array
Array.from()
Array.of()
Array.prototype.fill()
Array.prototype.find()
Array.prototype.findIndex()
Array.prototype.entries()
Array.prototype.keys()
Array.prototype.copyWithin()
Array.prototype.concat()
(ES6 version, addition of@@isConcatSpreadable
support)Array.prototype[@@iterator]
-
Map
Map.prototype.size
Map.prototype.set()
Map.prototype.get()
Map.prototype.has()
Map.prototype.clear()
Map.prototype.delete()
Map.prototype.entries()
Map.prototype.forEach()
Map.prototype.keys()
Map.prototype.values()
Map.prototype[@@iterator]()
Map.prototype[@@toStringTag]()
-
Set
Set.prototype.size
Set.prototype.add()
Set.prototype.clear()
Set.prototype.delete()
Set.prototype.entries()
Set.prototype.forEach()
Set.prototype.has()
Set.prototype.keys()
Set.prototype.values()
Set.prototype[@@iterator]()
Set.prototype[@@toStringTag]()
-
WeakMap
WeakMap.prototype.delete()
WeakMap.prototype.get()
WeakMap.prototype.has()
WeakMap.prototype.set()
WeakMap.prototype[@@toStringTag]()
-
WeakSet
WeakSet.prototype.add()
WeakSet.prototype.delete()
WeakSet.prototype.has()
WeakSet.prototype[@@toStringTag]()
-
Number
Number.isNaN()
Number.isFinite()
Number.isInteger()
Number.parseInt()
Number.parseFloat()
Number.EPSILON
Number.MAX_SAFE_INTEGER
Number.MIN_SAFE_INTEGER
Number.isSafeIntger()
-
Object
Object.is()
Object.setPrototypeOf()
(It assumes thatObject.prototype.__proto__
accessor property already exists)Object.assign()
Object.getOwnPropertySymbols
Object.prototype.toString()
(ES6 version, addition of@@toStringTag
support)
-
Promise
Promise.all()
Promise.race()
Promise.reject()
Promise.resolve()
Promise.prototype.then()
Promise.prototype.catch()
-
String
String.fromCodePoint()
String.prototype.codePointAt()
String.prototype.startsWith()
String.prototype.endsWith()
String.prototype.includes()
String.prototype.repeat()
-
Symbol
Symbol.for()
Symbol.keyFor()
Symbol.iterator
Symbol.hasInstance
Symbol.isConcatSpreadable
Symbol.toStringTag
Symbol.prototype.toString()
Symbol.prototype.valueOf()
Not Yet Implemented
Some features are not yet implemented, but can be implemented safely. Click here to see those features.
Limitation
Some ES6
features can not be implemented in ES5
natively like spread operator
, for..of
loop, ES6
version of instanceOf
operator etc.
So this module exports an object named ES6
globally, that provides some approximate equivalent implementation of those features.
ES6
Object
This object provides,
isSymbol()
(It can be used as equivalent API fortypeof symbol === 'symbol'
)instanceOf()
(Provides ES6 version ofinstanceOf
operator)forOf()
(This method behaves exactly same asfor...of
loop)spreadOperator
(Gives same functionality of thespread operator
)
Others utility methods,
isMap
isSet
isWeakMap
isWeakSet
isPromise
Contributing
Your PRs and stars are always welcome.
Please, try to follow:
- Clone the repository.
- Checkout
develop
branch. - Install dependencies.
- Add your new features or fixes.
- Build the project.
$ git clone https://github.com/rousan/es6-harmony.git$ cd es6-harmony$ git checkout develop$ npm i$ npm run build