{"id":21356765,"url":"https://github.com/rousan/es6-harmony","last_synced_at":"2025-07-13T00:31:34.382Z","repository":{"id":57227143,"uuid":"93669551","full_name":"rousan/es6-harmony","owner":"rousan","description":":zap: ES6 equivalent implimentation in ES5 for old JavaScript engines","archived":false,"fork":false,"pushed_at":"2018-02-18T09:31:28.000Z","size":86,"stargazers_count":6,"open_issues_count":0,"forks_count":1,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-04-22T11:44:36.677Z","etag":null,"topics":["equivalent","es5","es6","es6-classes","es6-harmony","es6-javascript","es6-map","es6-polyfill","es6-promise","es6-promises","es6-set","es6-symbol","es6-weakmap","es6-weakset","harmony","implementation","javascript-engine","js","polyfill","ponyfill"],"latest_commit_sha":null,"homepage":"https://rousan.io/es6-harmony/","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/rousan.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2017-06-07T19:00:10.000Z","updated_at":"2023-08-23T12:58:52.000Z","dependencies_parsed_at":"2022-09-06T13:40:25.750Z","dependency_job_id":null,"html_url":"https://github.com/rousan/es6-harmony","commit_stats":null,"previous_names":[],"tags_count":4,"template":false,"template_full_name":null,"purl":"pkg:github/rousan/es6-harmony","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rousan%2Fes6-harmony","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rousan%2Fes6-harmony/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rousan%2Fes6-harmony/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rousan%2Fes6-harmony/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/rousan","download_url":"https://codeload.github.com/rousan/es6-harmony/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rousan%2Fes6-harmony/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":263737947,"owners_count":23503891,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["equivalent","es5","es6","es6-classes","es6-harmony","es6-javascript","es6-map","es6-polyfill","es6-promise","es6-promises","es6-set","es6-symbol","es6-weakmap","es6-weakset","harmony","implementation","javascript-engine","js","polyfill","ponyfill"],"created_at":"2024-11-22T04:36:05.336Z","updated_at":"2025-07-13T00:31:34.096Z","avatar_url":"https://github.com/rousan.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"[![NPM version](https://img.shields.io/npm/v/es6-harmony.svg)](https://www.npmjs.com/package/es6-harmony)\n[![NPM total downloads](https://img.shields.io/npm/dt/es6-harmony.svg)](https://www.npmjs.com/package/es6-harmony)\n[![License](https://img.shields.io/github/license/rousan/es6-harmony.svg)](https://github.com/rousan/es6-harmony/blob/master/LICENSE)\n\n# ES6 Harmony\n\nProvides an equivalent implementation of `ES6(Harmony)` in pure `ES5` and creates an `ES6` environment for old browsers and JavaScript Engines.\n\n\u003e ES6 shims in pure ES5.\n\n## Install\n\n### NPM\n\nInstall it from `npm` and `require` it before any other modules:\n\n```bash\n$ npm install --save es6-harmony\n```\n\n```javascript\nvar ES6 = require(\"es6-harmony\");\n```\n\n### CDN\n\nIf you prefer CDN, then just insert it into your HTML page on the top of other scripts:\n\n`\u003cscript src=\"https://cdn.jsdelivr.net/npm/es6-harmony/dist/es6-harmony.min.js\"\u003e\u003c/script\u003e`\n\n## Examples\n    \n```javascript\n\"use strict\";\n\nvar ES6 = require(\"es6-harmony\");\n\nvar arr = [1, 2, 3];\n\nES6.forOf(arr, function (v) {\n    console.log(v);\n});\n// 1\n// 2\n// 3\n\nconsole.log(Array.from(\"Bar\")); // [ 'B', 'a', 'r' ]\n\nconsole.log(Array.of(1, 2, 3)); // [ 1, 2, 3 ]\n\nconsole.log(Array.of.call(Object, 1, 2, 3)); // { [Number: 3] '0': 1, '1': 2, '2': 3, length: 3 }\n\nconsole.log([1, 2, 3].fill(\"Bar\")); // [ 'Bar', 'Bar', 'Bar' ]\n\nconsole.log([1, 2, \"bar\"].find(function (v) {\n    return typeof v === \"number\";\n}));\n// 1\n\nconsole.log([1, 2, \"bar\"].findIndex(function (v) {\n    return typeof v === \"number\";\n}));\n// 0\n\nvar it = arr.entries();\n\nconsole.log(it.next()); // { done: false, value: [ 0, 1 ] }\nconsole.log(it.next()); // { done: false, value: [ 1, 2 ] }\nconsole.log(it.next()); // { done: false, value: [ 2, 3 ] }\nconsole.log(it.next()); // { done: true, value: undefined }\n\n\nvar map = new Map([[1, 2], [\"bar\", \"baz\"]]);\n\nconsole.log(map.size); // 2\n\nmap.set(0, {});\nmap.set(NaN, Object);\n\nconsole.log(map.has(NaN)); // true\nconsole.log(map.has(-0)); // true\n\nit = map.keys();\n\nconsole.log(it.next()); // { done: false, value: 1 }\nconsole.log(it.next()); // { done: false, value: 'bar' }\nconsole.log(it.next()); // { done: false, value: NaN }\n\nES6.forOf(map, function (v) {\n    console.log(v);\n});\n// [ 1, 2 ]\n// [ 'bar', 'baz' ]\n// [ 0, {} ]\n// [ NaN, [Function: Object] ]\n\nvar set = new Set([1, 2, \"bar\"]);\n\nconsole.log(set.size); // 3\n\nset.add(-0);\nset.add(NaN);\n\nconsole.log(set.has(0)); // true\nconsole.log(set.has(NaN)); // true\n\nit = set.values();\n\nconsole.log(it.next()); // { done: false, value: 1 }\nconsole.log(it.next()); // { done: false, value: 2 }\nconsole.log(it.next()); // { done: false, value: 'bar' }\n\nES6.forOf(set, function (v) {\n    console.log(v);\n});\n// 1\n// 2\n// bar\n// -0\n// NaN\n\nvar wm = new WeakMap();\nwm.set(Object, \"object\");\nwm.set({}, \"normal object\");\n\nconsole.log(wm.has(Object)); // true\nconsole.log(wm.has({})); // false\n\nvar ws = new WeakSet();\n\nws.add(Object);\nws.add(Math);\n\nconsole.log(ws.has(Math)); // true\nconsole.log(ws.has(new Object())); // false\n\nconsole.log(Number.isNaN(NaN)); // true\nconsole.log(Number.isFinite(Infinity)); // false\nconsole.log(Number.isInteger(-11)); // true\nconsole.log(Number.isSafeInteger(Math.pow(2, 53) - 1)); // true\n\nconsole.log(Object.is(-0, 0)); // false\nconsole.log(Object.is(NaN, NaN)); // true\n\nvar a = {};\nvar b = {};\n\nObject.setPrototypeOf(a, b);\nconsole.log(Object.getPrototypeOf(a) === b); // true\n\nconsole.log(Object.assign({}, \"bar\")); // { '0': 'b', '1': 'a', '2': 'r' }\n\nvar sym1 = Symbol(\"bar\");\nvar sym2 = Symbol(\"baz\");\n\na[sym1] = \"This is symbol property\";\na[sym2] = \"This is another symbol property\";\n\nvar allSymbols = Object.getOwnPropertySymbols(a);\n\nconsole.log(allSymbols.length); // 2\nconsole.log(allSymbols[0] === a); // false\nconsole.log(allSymbols[1] === b); // false\n\nconsole.log(String.fromCodePoint(0xFFFF, 0x10FFFF).length); // 3\n\nsym1 = Symbol(\"BAZ\");\nsym2 = Symbol.for(\"BAZ\");\n\nconsole.log(sym1 === Symbol(\"BAZ\")); // false\nconsole.log(sym2 === Symbol.for(\"BAZ\")); // true\n\nvar obj = {\n    length: 2,\n    0: \"a\",\n    1: 122\n};\n\nit = Array.prototype[Symbol.iterator].call(obj); // { done: false, value: 'a' }\n\nconsole.log(ES6.spreadOperator([]).spread(\"Bar\", [1, 2, 3]).add(1, 2, 4).array()); // [ 'B', 'a', 'r', 1, 2, 3, 1, 2, 4 ]\n\nfunction sumArgs() {\n    return Array.prototype.reduce.call(arguments, function (acc, currV) {\n        return acc + currV;\n    }, 0);\n}\n\nconsole.log(ES6.spreadOperator(sumArgs).spread([1, 2, 3]).add(11, 22).call()); // 39\n\nfunction Box(width, height) {\n    this.width = width;\n    this.height = height;\n}\n\nconsole.log(ES6.spreadOperator(Box).spread([1, 2.22]).new()); // Box { width: 1, height: 2.22 }\n\nconsole.log(it.next()); // { done: false, value: 'a' }\n\nvar promise = new Promise(function (resolve, reject) {\n    setTimeout(resolve, 0, 100);\n});\n\npromise.then(function (value) {\n    console.log(value);\n    return new Promise(function (resolve, reject) {\n        setTimeout(resolve, 0, 110);\n    });\n}).then(function (value) {\n    console.log(value);\n    return {\n        then: function (resolve, reject) {\n            setTimeout(reject, 0, \"Error\");\n        }\n    }\n}).catch(console.log.bind(console));\n\n// 100\n// 110\n// Error\n```\n\n## Implemented\n\n* `Array`\n\n    * `Array.from()`\n    * `Array.of()`\n    * `Array.prototype.fill()`\n    * `Array.prototype.find()`\n    * `Array.prototype.findIndex()`\n    * `Array.prototype.entries()`\n    * `Array.prototype.keys()`\n    * `Array.prototype.copyWithin()`\n    * `Array.prototype.concat()` (ES6 version, addition of `@@isConcatSpreadable` support)\n    * `Array.prototype[@@iterator]`\n    \n* `Map`\n\n    * `Map.prototype.size`\n    * `Map.prototype.set()`\n    * `Map.prototype.get()`\n    * `Map.prototype.has()`\n    * `Map.prototype.clear()`\n    * `Map.prototype.delete()`\n    * `Map.prototype.entries()`\n    * `Map.prototype.forEach()`\n    * `Map.prototype.keys()`\n    * `Map.prototype.values()`\n    * `Map.prototype[@@iterator]()` \n    * `Map.prototype[@@toStringTag]()`\n    \n* `Set`\n\n    * `Set.prototype.size`\n    * `Set.prototype.add()`\n    * `Set.prototype.clear()`\n    * `Set.prototype.delete()`\n    * `Set.prototype.entries()`\n    * `Set.prototype.forEach()`\n    * `Set.prototype.has()`\n    * `Set.prototype.keys()`\n    * `Set.prototype.values()`\n    * `Set.prototype[@@iterator]()`\n    * `Set.prototype[@@toStringTag]()`\n    \n* `WeakMap`\n\n    * `WeakMap.prototype.delete()`\n    * `WeakMap.prototype.get()`\n    * `WeakMap.prototype.has()`\n    * `WeakMap.prototype.set()`\n    * `WeakMap.prototype[@@toStringTag]()`\n    \n* `WeakSet`\n\n    * `WeakSet.prototype.add()`\n    * `WeakSet.prototype.delete()`\n    * `WeakSet.prototype.has()`\n    * `WeakSet.prototype[@@toStringTag]()`\n    \n* `Number`\n    \n    * `Number.isNaN()`\n    * `Number.isFinite()`\n    * `Number.isInteger()`\n    * `Number.parseInt()`\n    * `Number.parseFloat()`\n    * `Number.EPSILON`\n    * `Number.MAX_SAFE_INTEGER`\n    * `Number.MIN_SAFE_INTEGER`\n    * `Number.isSafeIntger()`\n    \n* `Object`\n    \n    * `Object.is()`\n    * `Object.setPrototypeOf()` (It assumes that `Object.prototype.__proto__` accessor property already exists)\n    * `Object.assign()`\n    * `Object.getOwnPropertySymbols`\n    * `Object.prototype.toString()` (ES6 version, addition of `@@toStringTag` support)\n\n* `Promise`\n\n    * `Promise.all()`\n    * `Promise.race()`\n    * `Promise.reject()`\n    * `Promise.resolve()`\n    * `Promise.prototype.then()`\n    * `Promise.prototype.catch()`\n\n* `String`\n    \n    * `String.fromCodePoint()`\n    * `String.prototype.codePointAt()`\n    * `String.prototype.startsWith()`\n    * `String.prototype.endsWith()`\n    * `String.prototype.includes()`\n    * `String.prototype.repeat()`\n    \n* `Symbol`\n\n    * `Symbol.for()`\n    * `Symbol.keyFor()`\n    * `Symbol.iterator`\n    * `Symbol.hasInstance`\n    * `Symbol.isConcatSpreadable`\n    * `Symbol.toStringTag`\n    * `Symbol.prototype.toString()`\n    * `Symbol.prototype.valueOf()`\n\n## Not Yet Implemented\n\nSome features are not yet implemented, but can be implemented safely. Click [here](https://github.com/ariyankhan/es6-harmony/blob/master/not-yet-implemented.md) to see those features.\n\n## Limitation\n\nSome `ES6` features can not be implemented in `ES5` natively like `spread operator`, `for..of` loop, `ES6` version of `instanceOf` operator etc.\nSo this module exports an object named `ES6` globally, that provides some approximate equivalent implementation of those features.\n\n## `ES6` Object\n\nThis object provides,\n\n   * `isSymbol()` (It can be used as equivalent API for `typeof symbol === 'symbol'`)\n   * `instanceOf()` (Provides ES6 version of `instanceOf` operator)\n   * `forOf()` (This method behaves exactly same as `for...of` loop)\n   * `spreadOperator` (Gives same functionality of the `spread operator`)\n   \n   Others utility methods,\n   \n   * `isMap`\n   * `isSet`\n   * `isWeakMap`\n   * `isWeakSet`\n   * `isPromise`\n\n## Contributing\n\nYour PRs and stars are always welcome.\n\nPlease, try to follow:\n\n* Clone the repository.\n* Checkout `develop` branch.\n* Install dependencies.\n* Add your new features or fixes.\n* Build the project.\n\n```sh\n$ git clone https://github.com/rousan/es6-harmony.git\n$ cd es6-harmony\n$ git checkout develop\n$ npm i\n$ npm run build\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frousan%2Fes6-harmony","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Frousan%2Fes6-harmony","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frousan%2Fes6-harmony/lists"}