Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

autopolyfiller

Package Overview
Dependencies
Maintainers
1
Versions
18
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

autopolyfiller

Precise polyfills. Like Autoprefixer, but for JavaScript polyfills

  • 1.0.10
  • Source
  • npm
  • Socket score

Version published
Maintainers
1
Created
Source

Autopolyfiller — Precise polyfills

NPM Version Build Status Coverage Status Dependency Status

This is like Autoprefixer, but for JavaScript polyfills

How it works:

  • Using AST matchers it scans your code and finds all polyfills
  • If target browsers are specified, then it reduces the list of polyfills according to the "feature database"
  • It generates polyfills code which precisely fixes only required features

It will not work if:

  • You eval code with polyfills. Eg eval('Object.keys(this)')
  • You doing something odd. Eg Object['k' + 'eys']()

Installation

autopolyfiller can be installed using npm:

npm install autopolyfiller

CLI Example

$ autopolyfiller lib/**/*.js -b "Explorer 7, Chrome >= 10"
$ cat lib/*.js | autopolyfiller

Grunt & Gulp tasks

Example

// Polyfills + Code
require('autopolyfiller')().add(code) + code;

List of polyfills without browsers filtering

var autopolyfiller = require('autopolyfiller');

autopolyfiller()
.add('"".trim();')
.polyfills;
// ['String.prototype.trim']

Filtering using Autoprefixer-style browser matchers

var autopolyfiller = require('autopolyfiller');

autopolyfiller('IE 11', 'Chrome >= 31')
.add('"".trim();Object.create();new Promise()')
.polyfills;
// ['Promise']

Default autoprefixer browsers

var autopolyfiller = require('autopolyfiller'),
    autoprefixer = require('autopolyfiller');

autopolyfiller(autoprefixer.default)
.add('new Promise();')
.polyfills;
// ['Promise']

Custom polyfill matchers

var query = require('grasp-equery').query;
var autopolyfiller = require('autopolyfiller');

autopolyfiller.use({
    // AST tree pattern matching
    test: function (ast) {
        return query('Object.newFeature(_$)', ast).length > 0 ? ['Object.newFeature'] : [];
    },
    support: {
        // For chrome 29 fix Object.newFeature
        'Chrome': [{
            only: '29',
            fill: 'Object.newFeature'
        }]
    },
    polyfill: {
        'Object.newFeature': 'Object.newFeature = function () {};'
    }
});

autopolyfiller()
.add('Object.create();Object.newFeature();');
.polyfills;
// ['Object.create', 'Object.newFeature']

autopolyfiller('Chrome >= 20')
.add('Object.create();Object.newFeature();');
.polyfills;
// []

Keywords

FAQs

Package last updated on 13 Mar 2014

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc