0.0.32 • Published 9 years ago

polyfiller v0.0.32

Weekly downloads
109
License
MIT
Repository
github
Last release
9 years ago

Polyfiller

npm version Build Status Coverage Status Dependency Status License Codacy Badge

Sauce Test Status

A polyfill combinator

Getting Started

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:

npm install polyfiller --save-dev

Once the package has been installed, it may be used inside your files with this line of JavaScript:

var Polyfiller = require('polyfiller');

Usage Example

var fs = require('fs');

var polyfiller = new Polyfiller;
var list = polyfiller.find([ 'Promise', 'Fetch', 'URL' ]);

fs.writeFile('./polyfills.js', polyfiller.pack(list));

Catalog

A list of available features

FeatureWhat's included?TypeLicense
Array.fromArray.fromMIT
Array.prototype.findArray.prototype.findMIT
Array.prototype.findIndexArray.prototype.findIndexMIT
CSS.escapeCSS.escapeMIT
Object.observeObject.observeMIT
ReflectReflectProxy handlerApache License, MPL
CollectionsSetMapWeakSetWeakMapMIT
DOM4CustomEventElement#appendElement#prependElement#afterElement#beforeElement#replaceWithElement#removeElement#queryElement#queryAllElement#matchesElement#closestElement#classList MIT
Element.prototype.datasetElement.prototype.dataset MIT
EventSourceEventSourceMIT
Fetchwindow.fetchBodyHeadersRequestResponseMIT
PromisePromiseMIT
KeyboardEventURLMIT
NotificationNotificationMIT
Number.prototype.toLocaleStringNumber.prototype.toLocaleStringPublic Domain
Object.create (patch)Object.createMIT
Object.getOwnPropertySymbolsObject.getOwnPropertySymbolsMIT
PointerEventsPointerEventsApache License
window.setImmediatewindow.setImmediatewindow.clearImmediateMIT
RegExp.prototype.matchRegExp.prototype.matchMIT
RegExp.prototype.searchRegExp.prototype.searchMIT
String.fromCodePointRegExp.prototype.searchMIT
String.prototype.atString.prototype.atMIT
String.prototype.codePointAtString.prototype.codePointAtMIT
String.prototype.endsWithString.prototype.endsWithMIT
String.prototype.includesString.prototype.includesMIT
String.prototype.normalizeString.prototype.normalizeMIT, GPL
String.prototype.repeatString.prototype.repeatMIT
String.prototype.startsWithString.prototype.startsWithMIT
SystemSystemMIT
TextEncoderTextEncoderApache License
TypedArrayTypedArrayArrayBufferDataViewMIT
URLURLMIT
UserTimingwindow.performance.clearMarkswindow.performance.clearMeasureswindow.performance.getEntrieswindow.performance.getEntriesByNamewindow.performance.getEntriesByTypewindow.performance.markwindow.performance.measureMIT
WindowBase64WindowBase64 WTFPL
document.currentScriptdocument.scrollingElementMIT
document.scrollingElementdocument.scrollingElementMIT
window.location.originwindow.location.originMIT
window.navigator.geolocationwindow.navigator.geolocationMIT
window.navigator.getUserMediawindow.navigator.getUserMediaMIT
window.navigator.languagewindow.location.originMIT
window.performance.nowwindow.performance.nowMIT
window.requestAnimationFramewindow.requestAnimationFramewindow.cancelAnimationFrameMIT

Compatibility

Theoretically compatible with all contemporary browsers since IE9. For IE8 only it's recommended to include ie8 script before your build

Methods

find

Type: Function (Array, [ Function (feature, name, features) ]) Returns: Array

Returns an unordered bundle of polyfills as an array of objects

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):

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]) Returns: Array

Returns a list of all available features as an array of strings.

var polyfiller = new Polyfiller;

polyfiller.list(); // ['Promise', 'Reflect', 'URL', ...]

extended option

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) Returns: String

Packs a list of polyfills into one string

var polyfiller = new Polyfiller;

var list = polyfiller.find([ 'Promise' ]),
	code = polyfiller.pack(list);

Options

exclude

Type: Array Default: []

Some polyfills have dependencies that you can exclude here

var polyfiller = new Polyfiller({
	exclude: ['setImmediate']
});

verbose

Type: Boolean Default: false

Verbose mode is an option that provides additional details as to what the package is doing.

var polyfiller = new Polyfiller({
	verbose: true
});

wrapper

Type: Function Default (find): None Default (pack): see

A custom wrapper for your environment.

var polyfiller = new Polyfiller({
	wrapper: function (source) {
		return ';(function () {' + source + '}.call(self));'
	}
});

Also this option is available like a method:

var polyfiller = new Polyfiller;

polyfiller.options.wrapper(function (source) {
	return source;
});

modules

Do you want to use some specific npm or bower modules?

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 Default: [trunk/catalog]

Have custom polyfills? Add paths to their location here.

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

{
	"name": "Promise"
}

There are dependencies?

"dependencies": ["window.setImmediate"]

index.js

module.exports = [
	{
		type: 'npm',
		name: 'es6-promises'
	}
];

type

Type: string [npm | bower | file] Default: None

name

Type: string Default: None

The files are located locally?

catalog
	Promise
		files
			index.js — your polyfill

		index.json
		index.js
// index.js

var path = require('path');

module.exports = [
	{
		type: 'file',
		name: path.join(__dirname, './files/index.js')
	}
];

Tests

npm test

Contributing

Please see our contributing guide

Have an interesting and well-tested polyfill?

License

MIT

Task submitted by Alexander Abashkin

Analytics

0.0.32

9 years ago

0.0.31

9 years ago

0.0.30

9 years ago

0.0.29

9 years ago

0.0.28

9 years ago

0.0.27

9 years ago

0.0.26

9 years ago

0.0.25

9 years ago

0.0.24

9 years ago

0.0.23

9 years ago

0.0.22

9 years ago

0.0.21

9 years ago

0.0.20

9 years ago

0.0.19

9 years ago

0.0.18

9 years ago

0.0.17

9 years ago

0.0.16

9 years ago

0.0.15

9 years ago

0.0.14

9 years ago

0.0.13

9 years ago

0.0.12

9 years ago

0.0.11

9 years ago

0.0.10

9 years ago

0.0.9

9 years ago

0.0.8

9 years ago

0.0.7

9 years ago

0.0.6

9 years ago

0.0.5

9 years ago

0.0.3

9 years ago

0.0.2

9 years ago

0.0.1

9 years ago