{"id":21356777,"url":"https://github.com/rousan/symbol-es6","last_synced_at":"2025-07-13T00:31:41.138Z","repository":{"id":57376179,"uuid":"94212636","full_name":"rousan/symbol-es6","owner":"rousan","description":":snowman: ES6 Symbol polyfill in pure ES5","archived":false,"fork":false,"pushed_at":"2020-01-26T10:48:51.000Z","size":34,"stargazers_count":18,"open_issues_count":3,"forks_count":9,"subscribers_count":4,"default_branch":"master","last_synced_at":"2024-06-18T19:53:05.081Z","etag":null,"topics":["es","es-symbol","es5","es6","es6-symbol","harmony","harmony-symbol","implementation","js","js-symbol","polyfill","ponyfill","symbol"],"latest_commit_sha":null,"homepage":"https://rousan.io/symbol-es6/","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-13T12:52:30.000Z","updated_at":"2024-04-08T10:08:12.000Z","dependencies_parsed_at":"2022-09-11T20:01:05.272Z","dependency_job_id":null,"html_url":"https://github.com/rousan/symbol-es6","commit_stats":null,"previous_names":[],"tags_count":3,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rousan%2Fsymbol-es6","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rousan%2Fsymbol-es6/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rousan%2Fsymbol-es6/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rousan%2Fsymbol-es6/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/rousan","download_url":"https://codeload.github.com/rousan/symbol-es6/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":225844842,"owners_count":17533160,"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":["es","es-symbol","es5","es6","es6-symbol","harmony","harmony-symbol","implementation","js","js-symbol","polyfill","ponyfill","symbol"],"created_at":"2024-11-22T04:36:11.688Z","updated_at":"2024-11-22T04:36:12.272Z","avatar_url":"https://github.com/rousan.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"[![NPM version](https://img.shields.io/npm/v/symbol-es6.svg)](https://www.npmjs.com/package/symbol-es6)\n[![NPM total downloads](https://img.shields.io/npm/dt/symbol-es6.svg)](https://www.npmjs.com/package/symbol-es6)\n[![Contributors](https://img.shields.io/github/contributors/rousan/symbol-es6.svg)](https://github.com/rousan/symbol-es6/graphs/contributors)\n[![License](https://img.shields.io/github/license/rousan/symbol-es6.svg)](https://github.com/rousan/symbol-es6/blob/master/LICENSE)\n\n# Symbol-ES6\n\nProvides support for `ES6` Symbol API in `ES5` for older JS environments i.e. older browsers or NodeJS.\n\n\u003e ES6 Symbol polyfill 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 symbol-es6\n```\n\n```javascript\nrequire(\"symbol-es6\");\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```html\n\u003cscript src=\"https://cdn.jsdelivr.net/npm/symbol-es6/dist/symbol-es6.min.js\"\u003e\u003c/script\u003e\n```\n\n## Examples\n\n```javascript\n\"use strict\";\n\nvar ES6 = require(\"symbol-es6\");\n\nconsole.log(Symbol(\"bar\") === Symbol(\"bar\")); //false\n\nvar sym = Symbol.for(\"bar\");\nvar sym2 = Symbol(\"bar\");\n\nconsole.log(Symbol.for(\"bar\") === sym); //true\nconsole.log(sym === sym2); //false\nconsole.log(Symbol.keyFor(sym)); //bar\nconsole.log(Symbol.keyFor(sym2)); //undefined\n\nconsole.log(Array.from(\"Hello\")); //[ 'H', 'e', 'l', 'l', 'o' ]\n\nvar it = [1, 2].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: true, value: undefined }\n\nit = [1, 2].keys();\n\nconsole.log(it.next()); //{ done: false, value: 0 }\nconsole.log(it.next()); //{ done: false, value: 1 }\nconsole.log(it.next()); //{ done: true, value: undefined }\n\nfunction Bar() {\n}\nconsole.log(Object.prototype.toString.call(new Bar())); //[object Object]\n\nBar.prototype[Symbol.toStringTag] = \"Bar\";\n\nconsole.log(Object.prototype.toString.call(new Bar())); //[object Bar]\n\nit = \"Bar\"[Symbol.iterator]();\n\nconsole.log(it.next()); //{ done: false, value: 'B' }\nconsole.log(it.next()); //{ done: false, value: 'a' }\nconsole.log(it.next()); //{ done: false, value: 'r' }\n\n\nconsole.log(ES6.isSymbol({})); //fasle\nconsole.log(ES6.isSymbol(sym)); ///true\n\nfunction Baz() {\n\n}\nconsole.log(ES6.instanceOf(89, Baz)); //false\nObject.defineProperty(Baz, Symbol.hasInstance, {\n   value: function (value) {\n       return typeof value === \"number\";\n   }\n});\nconsole.log(ES6.instanceOf(89, Baz)); //true\n\nES6.forOf([1, 2], function (v) {\n    console.log(v);\n});\n//1\n//2\n\nconsole.log(ES6.spreadOperator([]).spread(\"Bar\").array()); //[ 'B', 'a', 'r' ]\n\nfunction TestSpread() {\n    return Array.prototype.reduce.call(arguments, function (acc, currvalue) {\n        return acc + currvalue;\n    }, 0);\n}\n\nconsole.log(ES6.spreadOperator(TestSpread).spread([1, 2, 3, 4, 5]).call()); //15\n\nfunction Student(name, roll) {\n    this.name = name;\n    this.roll = roll;\n}\n\nconsole.log(ES6.spreadOperator(Student).spread([\"Ariyan\", 10]).new().name); //Ariyan\n```\n\n## Polyfills\n\n* `Symbol`\n    * `for()`\n    * `keyFor`\n    * `@@hasInstance`\n    * `@@isConcatSpreadable`\n    * `@@iterator`\n    * `@@toStringTag`\n    * `Symbol.prototype.toString()`\n    * `Symbol.prototype.valueOf()`\n    \n* `Function`\n    * `Function.prototype[@@hasInstance]()`\n    \n* `Array`\n    * `Array.prototype.concat()` (ES6 version, addition of `@@isConcatSpreadable` support)\n    * `Array.prototype[@@iterator]()`\n    * `Array.from()`\n    * `Array.prototype.entries()`\n    * `Array.prototype.keys()`\n\n* `Object`\n    * `Object.prototype.toString()` (ES6 version, addition of `@@toStringTag` support)\n\n* `String`\n    * `String.prototype[@@iterator]()`\n\n\n## Limitation\n\nSome `ES6` features can't be implemented in `ES5` natively like `spread operator`, `for..of` loop,\n`ES6` version of `instanceOf` operator etc. So this module exports a object named `ES6` globally,\nthat 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 of: `typeof symbol === 'symbol'`)\n* `instanceOf()` (Provides ES6 version of `instanceOf`)\n* `forOf()` (This method behaves exactly same as ES6 `for...of` loop)\n* `spreadOperator` (Gives same functionality of the `spread operator` of ES6)\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/symbol-es6.git\n$ cd symbol-es6\n$ git checkout develop\n$ npm i\n$ npm run build\n```","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frousan%2Fsymbol-es6","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Frousan%2Fsymbol-es6","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frousan%2Fsymbol-es6/lists"}