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

@mrhenry/polyfill-library

Package Overview
Dependencies
Maintainers
0
Versions
6
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@mrhenry/polyfill-library

A polyfill combinator

  • 5.2.1
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
444
decreased by-17.32%
Maintainers
0
Weekly downloads
 
Created
Source

@mhrenry/polyfill-library · license PRs Welcome

NodeJS module to create polyfill bundles tailored to individual user-agents

Install

npm install @mrhenry/polyfill-library --save

Usage

const polyfillLibrary = require('@mrhenry/polyfill-library');
const UA = require('@financial-times/polyfill-useragent-normaliser');

const polyfillBundle = polyfillLibrary.getPolyfillString({
	ua: new UA('Mozilla/5.0 (Windows; U; MSIE 7.0; Windows NT 6.0; en-US)'),
	minify: true,
	features: {
		'es6': { flags: ['gated'] }
	}
}).then(function(bundleString) {
	console.log(bundleString);
});

API

polyfillLibrary.listAllPolyfills()

Get a list of all the polyfills which exist within the collection of polyfill sources.

Returns a Promise which resolves with an array of all the polyfills within the collection.

polyfillLibrary.describePolyfill(featureName)

Get the metadata for a specific polyfill within the collection of polyfill sources.

  • @param {String} featureName - The name of a polyfill whose metadata should be returned.

Returns a Promise which resolves with the metadata or with undefined if no metadata exists for the polyfill.

polyfillLibrary.getOptions(opts = {})

Create an options object for use with getPolyfills or getPolyfillString.

  • @param {object} opts - Valid keys are ua, minify, unknown, excludes and features.
  • @param {Boolean} [opts.minify=true] - Whether to return the minified or raw implementation of the polyfills.
  • @param {'ignore'|'polyfill'} [opts.unknown='polyfill'] - Whether to return all polyfills or no polyfills if the user-agent is unknown or unsupported.
  • @param {Object} [opts.features={}] - Which features should be returned if the user-agent does not support them natively.
  • @param {Array<String>} [opts.excludes=[]] - Which features should be excluded from the returned object.
  • @param {Object} [opts.ua={}] - The user-agent object to check each feature against.

Returns an object which has merged opts with the defaults option values.

polyfillLibrary.getPolyfills(opts)

Given a set of features that should be polyfilled in 'opts.features' (with flags i.e. {<featurename>: {flags:Set[<flaglist>]}, ...}), determine which have a configuration valid for the given opts.ua, and return a promise of set of canonical (unaliased) features (with flags) and polyfills.

  • @param {object} opts - Valid keys are ua, minify, unknown, excludes and features.
  • @param {Boolean} [opts.minify=true] - Whether to return the minified or raw implementation of the polyfills.
  • @param {'ignore'|'polyfill'} [opts.unknown='polyfill'] - Whether to return all polyfills or no polyfills if the user-agent is unknown or unsupported.
  • @param {Object} [opts.features={}] - Which features should be returned if the user-agent does not support them natively.
  • @param {Array<String>} [opts.excludes=[]] - Which features should be excluded from the returned object.
  • @param {Object} [opts.ua={}] - The user-agent object to check each feature against.

Returns a Promise which resolves to an Object which contains the canonicalised feature definitions filtered for UA.

polyfillLibrary.getPolyfillString(opts)

Create a polyfill bundle.

  • @param {object} opts - Valid keys are ua, minify, unknown, excludes and features.
  • @param {Boolean} [opts.minify=true] - Whether to return the minified or raw implementation of the polyfills.
  • @param {'ignore'|'polyfill'} [opts.unknown='polyfill'] - Whether to return all polyfills or no polyfills if the user-agent is unknown or unsupported.
  • @param {Object} [opts.features={}] - Which features should be returned if the user-agent does not support them natively.
  • @param {Array<String>} [opts.excludes=[]] - Which features should be excluded from the returned object.
  • @param {Object} [opts.ua={}] - The user-agent object to check each feature against.
  • @param {Boolean} [opts.stream=false] - Whether to return a stream or a string of the polyfill bundle.

Returns a polyfill bundle as either a utf-8 ReadStream or as a Promise of a utf-8 String.

Contributing

Development of @mrhenry/polyfill-library happens on GitHub. Read below to learn how you can take part in contributing.

Contributing Guide

Read our contributing guide to learn about our development process, how to propose bugfixes and improvements, and how to build and test your changes.

npm run install
npm run watch

License

@mrhenry/polyfill-library is MIT licensed.

FAQs

Package last updated on 19 Oct 2024

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