Coder Social home page Coder Social logo

wenjoy / polyfill-library Goto Github PK

View Code? Open in Web Editor NEW

This project forked from jakechampion/polyfill-library

0.0 0.0 0.0 24.46 MB

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

License: MIT License

JavaScript 99.46% Handlebars 0.54%

polyfill-library's Introduction

Polyfill-library · license PRs Welcome

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

Install

npm install polyfill-library --save

Usage

const polyfillLibrary = require('polyfill-library');

const polyfillBundle = polyfillLibrary.getPolyfillString({
	uaString: '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 uaString, minify, unknown, excludes, rum 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 {String} [opts.uaString=''] - The user-agent string to check each feature against.
  • @param {Boolean} [opts.rum=false] - Whether to include a script that reports anonymous usage data in the polyfill bundle.

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.uaString, and return a promise of set of canonical (unaliased) features (with flags) and polyfills.

  • @param {object} opts - Valid keys are uaString, minify, unknown, excludes, rum 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 {String} [opts.uaString=''] - The user-agent string to check each feature against.
  • @param {Boolean} [opts.rum=false] - Whether to include a script that reports anonymous usage data in the polyfill bundle.

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 uaString, minify, unknown, excludes, rum 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 {String} [opts.uaString=''] - The user-agent string to check each feature against.
  • @param {Boolean} [opts.rum=false] - Whether to include a script that reports anonymous usage data in the polyfill bundle.
  • @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 polyfill-library happens on GitHub. Read below to learn how you can take part in contributing to Polyfill.io.

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

# To test on BrowserStack you will need to have a BrowserStack account
# We test pull-requests using BrowserStack
npm run test-all-polyfills # Run the tests for all polyfills using BrowserStack
npm run test-polyfills -- --features=Array.from # Run the tests for Array.from
npm run test-polyfills -- --features=Array.from --browserstack # Run the tests for Array.from using BrowserStack

License

Polyfill-library is MIT licensed.

polyfill-library's People

Contributors

actions-user avatar alenaksu avatar andrewgadziksonos avatar cdaringe avatar chee avatar christophehurpeau avatar cyjake avatar dependabot-preview[bot] avatar dependabot[bot] avatar doniyor2109 avatar github-actions[bot] avatar hewholived avatar jakechampion avatar juliyvchirkov avatar longlho avatar magic-akari avatar marshallycheng avatar matzimowski avatar mhassan1 avatar mridgway avatar neenhouse avatar nickcolley avatar nicksrandall avatar notlee avatar radeno avatar romainmenke avatar sbinlondon avatar sebastians90 avatar snyk-bot avatar undefinedbehaviour avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.