This is a lightweight(less than 10KB) polyfill lib which includes some common polyfills.
Just simply include one of the following script tags in your HTML to get the polyfills:
<!-- via jsdelivr -->
<script type="text/javascript" crossorigin="anonymous" src="https://cdn.jsdelivr.net/npm/hpolyfill@latest/dist/index.js"></script>
<!-- or via unpkg -->
<script type="text/javascript" crossorigin="anonymous" src="https://unpkg.com/hpolyfill@latest/dist/index.js"></script>By the way, as a polyfill lib, this lib should be loaded first in most cases.
- Set
- basic functionality
- constructor arguments
- convert
-0key into+0 set.add()returning thisset.forEach()set.delete()set.clear()set.sizeset[Symbol.iterator]()
- Map
- basic functionality
- constructor arguments
- convert
-0key into+0 map.set()returning thismap.forEach()map.delete()map.clear()map.sizemap[Symbol.iterator]()
- Promise
- basic functionality
Promise.all()Promise.allSettled()Promise.race()Promise.resolve()Promise.reject()promise.finally()
- Array
Array.from()Array.of()array.includes()array.fill()array.find()array.findIndex()array.flat()array.flatMap()array.keys()array.values()array.entries()array[Symbol.iterator]()
- Object
Object.assign()Object.is()Object.keys()Object.values()Object.entries()Object.fromEntries()
- Number
Number.isNaN()Number.isFinite()
- Math
Math.sign()Math.trunc()
- String
String.raw()string.includes()string.repeat()string.startsWith()string.endsWith()string.padStart()string.padEnd()string.trimStart()string.trimEnd()string[Symbol.iterator]()
- Symbol
- basic functionality
Symbol.for()Symbol.keyFor()Symbol.iteratorsymbol.description
- RAF
requestAnimationFrame()cancelAnimationFrame()
- Performance
performance.timeOriginperformance.now()
- Fetch (partial)
fetch()Headers()Request()Response()
This polyfill lib only provides a partial implemention of the Fetch APIs. Since XMLHttpRequest is used internally, some features are not available.
Here are the polyfill details:
fetch(resource, init?)resourcecan be either an url string or an instance ofRequestinitis optional and only accepts the following options:method- request methodcredentials- no cookies if set to'omit'; otherwise, attach cookiesheaders- either an instance ofHeaders, or an array of string arrays, or a plain object representing headers
Headers(init?)- full support
Request(resource?, init?)resourceandinitare similar tofetch()request.clone(),request.json()andrequest.text()are supported
Response(body?, init?)body- optional response bodyinit- optional optionsresponse.ok-trueif the status code is between 200 and 299;falseotherwiseresponse.clone(),response.json()andresponse.text()are supported
If you find any problem with this lib or something necessary but not included, feel free to open an issue.