Giter Club home page Giter Club logo

ponyfill's Introduction

Ponyfill

Like polyfill but with pony pureness




Use ponyfill.com for linking here.

Pony pureness, really?

While polyfills are naughty, ponyfills are pure, just like ponies.

How are ponyfills better than polyfills?

A polyfill is code that adds missing functionality by monkey patching an API. Unfortunately, it usually globally patches built-ins, which affects all code running in the environment. This is especially problematic when a polyfill is not fully spec compliant (which in some cases is impossible), as it could cause very hard to debug bugs and inconsistencies. Or when the spec for a new feature changes and your code depends on behavior that a module somewhere else in the dependency tree polyfills differently. In general, you should not modify API's you don't own.

A ponyfill, in contrast, doesn't monkey patch anything, but instead exports the functionality as a normal module, so you can use it locally without affecting other code.

tl;dr; Polyfills are naughty as they patch native APIs, while ponyfills are pure and don't affect the environment.

Polyfill

Number.isNaN = Number.isNaN || function (value) {
	return value !== value;
};
require('is-nan-polyfill');

Number.isNaN(5);

Ponyfill

module.exports = function (value) {
	return value !== value;
};
var isNanPonyfill = require('is-nan-ponyfill');

isNanPonyfill(5);

Ponyfills should never use the native API, even if available, as it might have slightly different behavior between environments, which can cause bugs.

Where can I find ponyfills?

Search npm.

How do I make a ponyfill?

  • Read the specification or source code of the feature you want ponyfill.
  • Initialize an npm package.
  • Write some tests to ease writing the ponyfill logic.
  • Link to documentation about the feature in your readme. Example.
  • Link to https://ponyfill.com in your readme. Example.
  • Add ponyfill to the keywords section in package.json.
  • Publish!

Resources

License

CC0

To the extent possible under law, Sindre Sorhus has waived all copyright and related or neighboring rights to this work.

Header based on work by Mary Winkler.

ponyfill's People

Watchers

Subhash Ramesh 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.