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

polyfills

Package Overview
Dependencies
Maintainers
1
Versions
45
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

polyfills

user-agent-based polyfill combinator

  • 0.3.2
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
2.8K
increased by13.95%
Maintainers
1
Weekly downloads
 
Created
Source

Polyfills

A user-agent-based polyfill combinator. Create polyfill builds based on the client's browser and only send only what's needed.

  • Parses user agent strings for <family> <major>.<minor>.<version> and creates polyfill bundles based on these variables.
  • Caches builds locally to a cache/ folder.
  • Optionally minimizes builds (defaults to true in production).
  • Stores nothing in memory, allowing you to use it within your app with minimal overhead.

This is based on jonathantneal/polyfill, but it has a couple of different philosophies:

  • It does not use its own polyfills and instead uses well tested polyfill libraries instead.
  • It does not try to optimize bundle sizes.
  • It does not use its own user agent parsing.

This library will only use small, well tested polyfills. The only exception are ECMAScript bundles such as es5-shim. An ES6 shim will be included once ES6 is finalized and a majority of browsers support all ES6 features. Until then, ES6 features will be included piecewise.

Included Polyfills

Installation

npm install polyfills

This library uses promises. If you're running a version of node that does not support Promises (anything lower than 0.11.13), then you must install bluebird as well:

npm install bluebird

Usage

var polyfill = Polyfills([options])

var polyfill = require('polyfills')({
  include: []
})

Return a new instance of polyfill based on options.

  • include - which polyfills to include. This is an inclusive list. The names are included in lib/polyfills.js.
  • cache - folder to cache polyfill bundles.

var js = yield* polyfill(useragent).build([minified], [gzipped])

This is the primary function.

  • minified - defaults to process.env.NODE_ENV === 'production'
  • gzipped - whether to return a compressed buffer instead of a string.

js is the final JS bundle that you can serve to the client.

Example Express usage:

app.use(function (req, res) {
  if (req.path !== '/polyfills.js') return next()

  co(polyfill(req.headers['user-agent']).build())(function (err, string) {
    if (err) return next(err)

    res.set('Content-Type', 'application/javascript')
    res.send(string)
  })
})

Adding polyfills

Feel free to create PRs to add polyfills. Checkout lib/polyfills.js to see what is needed.

FAQs

Package last updated on 09 Jul 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