GithubHelp home page GithubHelp logo

polyfiller's Introduction

Polyfiller

Load polyfills on demand.

Install

npm install @wide/polyfiller --save

Usage

This exemple will load assets/polyfills/object-assign.js on IE 11 only:

import polyfiller from '@wide/polyfiller'

polyfiller({
  path: 'assets/polyfills/',
  load: {
    'object-assign.js': {
      ie: '<=11'
    }
  }
})
  • path public folder of compiled polyfills
  • load collection of polyfills to load, accept a key/value combination
    • key: filename or url of the polyfill
    • value: criteria to satisfies (see bowser.satisfied)

Built-in polyfills

@wide/polyfiller comes with a set of well-known polyfills:

  • babel.js: core-js/stable and regenerator-runtime/runtime
  • closest.js: element-closest-polyfill
  • object-fit.js: object-fit-images and object-fit-videos
  • picture-fill.js: picturefill
  • object-assign.js: es6-object-assign
  • fetch: whatwg-fetch
  • svg.js: svg4everybody

These polyfills can be loaded in two steps, first import the needed ones using the presets collection:

import polyfiller from '@wide/polyfiller'
import presets from '@wide/polyfiller/lib/presets'

polyfiller({
  path: 'assets/polyfills/',
  load: {
    ...preset.babel,
    ...preset.fetch,
  }
})

Then, you need to compile them into the assets/polyfills:

// assets/polyfills/babel.js
import '@wide/polyfiller/lib/presets/babel'
// assets/polyfills/fetch.js
import '@wide/polyfiller/lib/presets/fetch'

Capabilities

To resolve which polyfill must be loaded, @wide/polyfiller makes use of the bowser lib and expose the main feature of the browser:

import capabilities from '@wide/polyfiller/lib/capabilities'

capabilities.touch    // true | false
capabilities.platform // desktop | mobile
capabilities.os       // linux | macos | windows
capabilities.engine   // trident | gecko
capabilities.name     // ie | chrome | firefox
capabilities.version  // number
capabilities.chrome   // true | false
capabilities.opera    // true | false
capabilities.firefox  // true | false
capabilities.safari   // true | false
capabilities.edge     // true | false
capabilities.ie       // true | false
capabilities.webp     // true | false

These capabilities can be exposed as window.capabilities and body css classes:

import { expose } from '@wide/polyfiller/lib/capabilities'

expose()

Libraries

This package uses :

Authors

License

This project is licensed under the MIT License - see the licence file for details

polyfiller's People

Contributors

jdacosta avatar myeti avatar robiseb avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

polyfiller's Issues

Edge Chromium vs Edge

We should be able to differentiate Edge based on Chromium or Edge.
In both cases, it is -edge that is returned.

Proposal :

  • -edge --> Microsoft Edge (version 12 to 18)
  • -edge-chromium --> Microsoft Edge based on Chromium 

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.