What is es6-shim?
The es6-shim package is designed to provide compatibility shims so that legacy JavaScript engines behave as closely as possible to ECMAScript 6 (ES6). It includes shims for new methods and functions introduced in ES6, allowing developers to use these features in environments that do not yet support them natively.
What are es6-shim's main functionalities?
Array.prototype methods
Adds new methods to Array.prototype like find, findIndex, etc., enabling more expressive operations on arrays.
[1, 2, 3].find(x => x == 2)
String.prototype methods
Introduces new String methods such as startsWith, endsWith, and includes for easier string manipulation.
'hello'.startsWith('hell')
Number properties
Provides new static properties and methods on the Number object like isNaN and isFinite for improved number checking.
Number.isNaN(NaN)
Promises
Implements Promises for asynchronous programming, following the ES6 specification.
new Promise(function(resolve, reject) { resolve(42); })
Maps and Sets
Adds support for new collection types such as Map and Set, offering more options for data storage and manipulation.
new Map([[1, 'one'], [2, 'two']])
Other packages similar to es6-shim
core-js
A modular standard library for JavaScript, including polyfills for ECMAScript up to 2021. Offers broader coverage than es6-shim, including proposals not yet standardized.
babel-polyfill
Part of Babel, this package includes a custom regenerator runtime and core-js. It's more comprehensive but has been deprecated in favor of directly including core-js and the regenerator-runtime.
es5-shim
Focuses on ensuring ECMAScript 5 compatibility, providing shims for older JavaScript engines. It's more focused on ES5, making it complementary rather than directly comparable to es6-shim.
ES6 Shim
Provides compatibility shims so that legacy JavaScript engines behave as
closely as possible to ECMAScript 6 (Harmony).
Project targets engines that support ES5 (Firefox, Chrome, Safari, Opera). With
ES5-shim it could also work in older
browsers.
Installation
npm install es6-shim
Safe shims
- Maps & Sets
- String.prototype.repeat, String.prototype.startsWith,
String.prototype.endsWith, String.prototype.contains, String.prototype.toArray
- Array.from, Array.of
- Number.isNaN, Number.toInteger, Number.isInteger, Number.isFinite
- Object.getOwnPropertyDescriptors, Object.getPropertyDescriptor,
Object.getPropertyNames, Object.is, Object.isnt
- Math.sign
License
The project was initially based on es6-shim by Axel Rauschmayer.
The MIT License (MIT)
Copyright (c) 2012 Paul Miller (http://paulmillr.com)
Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in
the Software without restriction, including without limitation the rights to
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
of the Software, and to permit persons to whom the Software is furnished to do
so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.