npm install polyfiller






> A polyfill combinator
This package requires Node ~0.10.0
If you haven't used npm before, be sure to check out the Getting Started guide, as it explains how to install npm and use a package.json file.
Once you're familiar with that process, you may install this package with this command:
``shell`
npm install polyfiller --save-dev
Once the package has been installed, it may be used inside your files with this line of JavaScript:
`js`
var Polyfiller = require('polyfiller');
`js
var fs = require('fs');
var polyfiller = new Polyfiller;
var list = polyfiller.find([ 'Promise', 'Fetch', 'URL' ]);
fs.writeFile('./polyfills.js', polyfiller.pack(list));
`
A list of available features
| Feature | What's included? | Type | License |
|:--------|:-----------------|:----:|:-------:|
Array.from | Array.from
|
| MIT |
Array.prototype.find | Array.prototype.find
|
| MIT |
Array.prototype.findIndex | Array.prototype.findIndex
|
| MIT |
CSS.escape | CSS.escape
|
| MIT |
Object.observe | Object.observe
|
| MIT |
Reflect | Reflect
Proxy handler
|
| Apache License, MPL |
Collections | Set
Map
WeakSet
WeakMap
|
| MIT |
DOM4 | CustomEvent
Element#append
Element#prepend
Element#after
Element#before
Element#replaceWith
Element#remove
Element#query
Element#queryAll
Element#matches
Element#closest
Element#classList
|
| MIT |
Element.prototype.dataset | Element.prototype.dataset
|
| MIT |
EventSource | EventSource
|
| MIT |
Fetch | window.fetch
Body
Headers
Request
Response
|
| MIT |
Promise | Promise
|
| MIT |
KeyboardEvent | URL
|
| MIT |
Notification | Notification
|
| MIT |
Number.prototype.toLocaleString | Number.prototype.toLocaleString
|
| Public Domain |
Object.create (patch) | Object.create
|
| MIT |
Object.getOwnPropertySymbols | Object.getOwnPropertySymbols
|
| MIT |
PointerEvents | PointerEvents
|
| Apache License |
window.setImmediate | window.setImmediate
window.clearImmediate
|
| MIT |
RegExp.prototype.match | RegExp.prototype.match
|
| MIT |
RegExp.prototype.search | RegExp.prototype.search
|
| MIT |
String.fromCodePoint | RegExp.prototype.search
|
| MIT |
String.prototype.at | String.prototype.at
|
| MIT |
String.prototype.codePointAt | String.prototype.codePointAt
|
| MIT |
String.prototype.endsWith | String.prototype.endsWith
|
| MIT |
String.prototype.includes | String.prototype.includes
|
| MIT |
String.prototype.normalize | String.prototype.normalize
|
| MIT, GPL |
String.prototype.repeat | String.prototype.repeat
|
| MIT |
String.prototype.startsWith | String.prototype.startsWith
|
| MIT |
System | System
|
| MIT |
TextEncoder | TextEncoder
|
| Apache License |
TypedArray | TypedArray
ArrayBuffer
DataView
|
| MIT |
URL | URL
|
| MIT |
UserTiming | window.performance.clearMarks
window.performance.clearMeasures
window.performance.getEntries
window.performance.getEntriesByName
window.performance.getEntriesByType
window.performance.mark
window.performance.measure
|
| MIT |
WindowBase64 | WindowBase64
|
| WTFPL |
document.currentScript | document.scrollingElement
|
| MIT |
document.scrollingElement | document.scrollingElement
|
| MIT |
window.location.origin | window.location.origin
|
| MIT |
window.navigator.geolocation | window.navigator.geolocation
|
| MIT |
window.navigator.getUserMedia | window.navigator.getUserMedia
|
| MIT |
window.navigator.language | window.location.origin
|
| MIT |
window.performance.now | window.performance.now
|
| MIT |
window.requestAnimationFrame | window.requestAnimationFrame
window.cancelAnimationFrame
|
| MIT |
Theoretically compatible with all contemporary browsers since IE9.
For IE8 only it's recommended to include ie8 script before your build
#### find
Type: Function (Array, [ Function (feature, name, features) ]) Array
Returns:
Returns an unordered bundle of polyfills as an array of objects
`js
var polyfiller = new Polyfiller;
var list = polyfiller.find([
'Promise'
],
function (feature, name) {
console.log(feature.source, feature.config, name);
});
list[0].source; // source code
list[0].config.name; // Promise
`
Also available the second format (it may be useful in the future versions):
`js
var polyfiller = new Polyfiller;
var list = polyfiller.find([
{
name: 'Promise'
}
],
function (feature, name) {
console.log(name, feature.source, feature.config);
});
`
#### list
Type: Function ([extended=false]) Array
Returns:
Returns a list of all available features as an array of strings.
`js
var polyfiller = new Polyfiller;
polyfiller.list(); // ['Promise', 'Reflect', 'URL', ...]
`
extended option
`js
var polyfiller = new Polyfiller;
var list = polyfiller.list(true);
list; // [{ config }, ...]
list[0].name; // Array.from
list[0].author; // Mathias Bynens
list[0].licenses[0].type; // MIT
...
`
For more information see the config format
#### pack
Type: Function (features) String
Returns:
Packs a list of polyfills into one string
`js
var polyfiller = new Polyfiller;
var list = polyfiller.find([ 'Promise' ]),
code = polyfiller.pack(list);
`
#### exclude
Type: Array []
Default:
Some polyfills have dependencies that you can exclude here
`js`
var polyfiller = new Polyfiller({
exclude: ['setImmediate']
});
#### verbose
Type: Boolean false
Default:
Verbose mode is an option that provides additional details as to what the package is doing.
`js`
var polyfiller = new Polyfiller({
verbose: true
});
#### wrapper
Type: Function find
Default (): None pack
Default (): see
A custom wrapper for your environment.
`js`
var polyfiller = new Polyfiller({
wrapper: function (source) {
return ';(function () {' + source + '}.call(self));'
}
});
Also this option is available like a method:
`js
var polyfiller = new Polyfiller;
polyfiller.options.wrapper(function (source) {
return source;
});
`
#### modules
Do you want to use some specific npm or bower modules?
`js
var path = require('path');
var polyfiller = new Polyfiller({
modules: [
path.join(__dirname, '../your_catalog/npm_modules'),
path.join(__dirname, '../your_catalog/bower_components')
]
});
`
NOTE: Please use only with the option catalog.
#### catalog
Type: Array [trunk/catalog]
Default:
Have custom polyfills? Add paths to their location here.
`js
var path = require('path');
var polyfiller = new Polyfiller({
catalog: [
path.resolve(__dirname, '../your/catalog')
]
});
`
If you want to use npm or bower packages in your catalog, please see modules section.
Required file structure for each new package:
``
catalog
Promise
index.json
index.js
index.json
`json`
{
"name": "Promise"
}
There are dependencies?
``
"dependencies": ["window.setImmediate"]
index.js
`js`
module.exports = [
{
type: 'npm',
name: 'es6-promises'
}
];
type
Type: string [npm | bower | file] None
Default:
name
Type: string None
Default:
The files are located locally?
`
catalog
Promise
files
index.js — your polyfill
index.json
index.js
`
`js
// index.js
var path = require('path');
module.exports = [
{
type: 'file',
name: path.join(__dirname, './files/index.js')
}
];
`
```
npm test
Please see our contributing guide
Have an interesting and well-tested polyfill?
MIT
Task submitted by Alexander Abashkin
