{"id":13527994,"url":"https://github.com/es-shims/es5-shim","last_synced_at":"2025-05-14T09:06:14.287Z","repository":{"id":1073356,"uuid":"914603","full_name":"es-shims/es5-shim","owner":"es-shims","description":"ECMAScript 5 compatibility shims for legacy (and modern) JavaScript engines","archived":false,"fork":false,"pushed_at":"2022-11-08T06:12:06.000Z","size":2237,"stargazers_count":7108,"open_issues_count":45,"forks_count":892,"subscribers_count":214,"default_branch":"master","last_synced_at":"2025-05-14T09:02:26.938Z","etag":null,"topics":["ecmascript","es5","javascript","polyfill","shim"],"latest_commit_sha":null,"homepage":"","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/es-shims.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","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":"2010-09-16T05:54:16.000Z","updated_at":"2025-05-11T19:49:51.000Z","dependencies_parsed_at":"2022-08-16T12:00:12.607Z","dependency_job_id":null,"html_url":"https://github.com/es-shims/es5-shim","commit_stats":null,"previous_names":["kriskowal/es5-shim"],"tags_count":96,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/es-shims%2Fes5-shim","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/es-shims%2Fes5-shim/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/es-shims%2Fes5-shim/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/es-shims%2Fes5-shim/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/es-shims","download_url":"https://codeload.github.com/es-shims/es5-shim/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254110374,"owners_count":22016391,"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":["ecmascript","es5","javascript","polyfill","shim"],"created_at":"2024-08-01T06:02:09.500Z","updated_at":"2025-05-14T09:06:14.226Z","avatar_url":"https://github.com/es-shims.png","language":"JavaScript","funding_links":[],"categories":["JavaScript","Web 前端","Polyfill"],"sub_categories":["React Components"],"readme":"# es5-shim \u003csup\u003e[![Version Badge][npm-version-svg]][package-url]\u003c/sup\u003e\n\n[![github actions][actions-image]][actions-url]\n[![coverage][codecov-image]][codecov-url]\n[![dependency status][deps-svg]][deps-url]\n[![dev dependency status][dev-deps-svg]][dev-deps-url]\n[![License][license-image]][license-url]\n[![Downloads][downloads-image]][downloads-url]\n\n[![npm badge][npm-badge-png]][package-url]\n\n`es5-shim.js` and `es5-shim.min.js` monkey-patch a JavaScript context to\ncontain all EcmaScript 5 methods that can be faithfully emulated with a\nlegacy JavaScript engine.\n**Note:** As `es5-shim.js` is designed to patch the native Javascript\nengine, it should be the library that is loaded first.\n\n`es5-sham.js` and `es5-sham.min.js` monkey-patch other ES5 methods as\nclosely as possible.  For these methods, as closely as possible to ES5\nis not very close.  Many of these shams are intended only to allow code\nto be written to ES5 without causing run-time errors in older engines.\nIn many cases, this means that these shams cause many ES5 methods to\nsilently fail.  Decide carefully whether this is what you want.\n**Note:** `es5-sham.js` requires `es5-shim.js` to be able to work properly.\n\n## Tests\n\nThe tests are written with the Jasmine BDD test framework.\nTo run the tests, navigate to \u003croot-folder\u003e/tests/ , or,\nsimply `npm install` and `npm test`.\n\n## Shims\n\n### Complete tests ###\n\n* Array.prototype.every ([standalone shim](https://www.npmjs.com/package/array.prototype.every))\n* Array.prototype.filter ([standalone shim](https://www.npmjs.com/package/array.prototype.filter))\n* Array.prototype.forEach ([standalone shim](https://www.npmjs.com/package/array.prototype.foreach))\n* Array.prototype.indexOf ([standalone shim](https://www.npmjs.com/package/array.prototype.indexof))\n* Array.prototype.lastIndexOf ([standalone shim](https://www.npmjs.com/package/array.prototype.lastindexof))\n* Array.prototype.map ([standalone shim](https://www.npmjs.com/package/array.prototype.map))\n* Array.prototype.slice\n* Array.prototype.some ([standalone shim](https://www.npmjs.com/package/array.prototype.some))\n* Array.prototype.sort\n* Array.prototype.reduce ([standalone shim](https://www.npmjs.com/package/array.prototype.reduce))\n* Array.prototype.reduceRight ([standalone shim](https://www.npmjs.com/package/array.prototype.reduceright))\n* Array.prototype.push ([standalone shim](https://www.npmjs.com/package/array.prototype.push))\n* Array.prototype.join\n* Array.prototype.splice ([standalone shim](https://www.npmjs.com/package/array.prototype.splice))\n* Array.isArray\n* Date.now ([standalone shim](https://www.npmjs.com/package/date))\n* Date.prototype.toJSON ([standalone shim](https://www.npmjs.com/package/date))\n* Function.prototype.bind\n    * :warning: Caveat: the bound function has a prototype property.\n    * :warning: Caveat: bound functions do not try too hard to keep you\n      from manipulating their ``arguments`` and ``caller`` properties.\n    * :warning: Caveat: bound functions don't have checks in ``call`` and\n      ``apply`` to avoid executing as a constructor.\n* Number.prototype.toExponential ([standalone shim](https://www.npmjs.com/package/number.prototype.toexponential))\n* Number.prototype.toFixed\n* Number.prototype.toPrecision\n* Object.keys ([standalone shim](https://www.npmjs.com/package/object-keys))\n* String.prototype.split ([standalone shim](https://www.npmjs.com/package/string.prototype.split))\n* String.prototype.trim ([standalone shim](https://www.npmjs.com/package/string.prototype.trim))\n* String.prototype.lastIndexOf ([standalone shim](https://www.npmjs.com/package/string.prototype.lastindexof))\n* String.prototype.replace\n    * Firefox (through v29) natively handles capturing groups incorrectly.\n* Date.parse (for ISO parsing) ([standalone shim](https://www.npmjs.com/package/date))\n* Date.prototype.toISOString ([standalone shim](https://www.npmjs.com/package/date))\n* parseInt ([standalone shim](https://www.npmjs.com/package/parseint))\n* parseFloat\n* Error.prototype.toString\n* Error.prototype.name\n* Error.prototype.message\n* RegExp.prototype.toString\n\n## Shams\n\n* :warning: Object.create\n\n    For the case of simply \"begetting\" an object that inherits\n    prototypically from another, this should work fine across legacy\n    engines.\n\n    :warning: The second argument is passed to Object.defineProperties\n    which will probably fail either silently or with extreme prejudice.\n\n* :warning: Object.getPrototypeOf\n\n    This will return \"undefined\" in some cases.  It uses `__proto__` if\n    it's available.  Failing that, it uses constructor.prototype, which\n    depends on the constructor property of the object's prototype having\n    not been replaced.  If your object was created like this, it won't\n    work:\n\n        function Foo() {\n        }\n        Foo.prototype = {};\n\n    Because the prototype reassignment destroys the constructor\n    property.\n\n    This will work for all objects that were created using\n    `Object.create` implemented with this library.\n\n* :warning: Object.getOwnPropertyNames\n\n    This method uses Object.keys, so it will not be accurate on legacy\n    engines.\n\n* Object.isSealed\n\n    Returns \"false\" in all legacy engines for all objects, which is\n    conveniently guaranteed to be accurate.\n\n* Object.isFrozen\n\n    Returns \"false\" in all legacy engines for all objects, which is\n    conveniently guaranteed to be accurate.\n\n* Object.isExtensible\n\n    Works like a charm, by trying very hard to extend the object then\n    redacting the extension.\n\n### May fail\n\n* :warning: Object.getOwnPropertyDescriptor\n\n    The behavior of this shim does not conform to ES5.  It should\n    probably not be used at this time, until its behavior has been\n    reviewed and been confirmed to be useful in legacy engines.\n\n* :warning: Object.defineProperty\n\n    In the worst of circumstances, IE 8 provides a version of this\n    method that only works on DOM objects.  This sham will not be\n    installed.  The given version of `defineProperty` will throw an\n    exception if used on non-DOM objects.\n\n    In slightly better circumstances, this method will silently fail to\n    set \"writable\", \"enumerable\", and \"configurable\" properties.\n\n    Providing a getter or setter with \"get\" or \"set\" on a descriptor\n    will silently fail on engines that lack \"__defineGetter__\" and\n    \"__defineSetter__\", which include all versions of IE.\n\n    https://github.com/es-shims/es5-shim/issues#issue/5\n\n* :warning: Object.defineProperties\n\n    This uses the Object.defineProperty shim.\n\n* Object.seal\n\n    Silently fails on all legacy engines.  This should be\n    fine unless you are depending on the safety and security\n    provisions of this method, which you cannot possibly\n    obtain in legacy engines.\n\n* Object.freeze\n\n    Silently fails on all legacy engines.  This should be\n    fine unless you are depending on the safety and security\n    provisions of this method, which you cannot possibly\n    obtain in legacy engines.\n\n* Object.preventExtensions\n\n    Silently fails on all legacy engines.  This should be\n    fine unless you are depending on the safety and security\n    provisions of this method, which you cannot possibly\n    obtain in legacy engines.\n\n### Example of applying ES compatibility shims in a browser project\n\n```html\n\u003cscript src=\"https://cdnjs.cloudflare.com/ajax/libs/es5-shim/4.5.14/es5-shim.min.js\"\u003e\u003c/script\u003e\n\u003cscript src=\"https://cdnjs.cloudflare.com/ajax/libs/es5-shim/4.5.14/es5-sham.min.js\"\u003e\u003c/script\u003e\n\u003cscript src=\"https://cdnjs.cloudflare.com/ajax/libs/json3/3.3.2/json3.min.js\"\u003e\u003c/script\u003e\n\u003cscript src=\"https://cdnjs.cloudflare.com/ajax/libs/es6-shim/0.35.5/es6-shim.min.js\"\u003e\u003c/script\u003e\n\u003cscript src=\"https://cdnjs.cloudflare.com/ajax/libs/es6-shim/0.35.5/es6-sham.min.js\"\u003e\u003c/script\u003e\n\u003cscript src=\"other-libs.js\"\u003e\u003c/script\u003e\n```\n\n[package-url]: https://npmjs.org/package/es5-shim\n[npm-version-svg]: https://versionbadg.es/es-shims/es5-shim.svg\n[deps-svg]: https://david-dm.org/es-shims/es5-shim.svg\n[deps-url]: https://david-dm.org/es-shims/es5-shim\n[dev-deps-svg]: https://david-dm.org/es-shims/es5-shim/dev-status.svg\n[dev-deps-url]: https://david-dm.org/es-shims/es5-shim#info=devDependencies\n[npm-badge-png]: https://nodei.co/npm/es5-shim.png?downloads=true\u0026stars=true\n[license-image]: https://img.shields.io/npm/l/es5-shim.svg\n[license-url]: LICENSE\n[downloads-image]: https://img.shields.io/npm/dm/es5-shim.svg\n[downloads-url]: https://npm-stat.com/charts.html?package=es5-shim\n[codecov-image]: https://codecov.io/gh/es-shims/es5-shim/branch/main/graphs/badge.svg\n[codecov-url]: https://app.codecov.io/gh/es-shims/es5-shim/\n[actions-image]: https://img.shields.io/endpoint?url=https://github-actions-badge-u3jn4tfpocch.runkit.sh/es-shims/es5-shim\n[actions-url]: https://github.com/es-shims/es5-shim/actions\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fes-shims%2Fes5-shim","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fes-shims%2Fes5-shim","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fes-shims%2Fes5-shim/lists"}