ponyfill

? Like polyfill but with pony pureness

Github星跟蹤圖

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 to 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.

主要指標

概覽
名稱與所有者sindresorhus/ponyfill
主編程語言
編程語言 (語言數: 0)
平台
許可證
所有者活动
創建於2016-09-29 14:19:54
推送於2024-02-06 09:31:52
最后一次提交
發布數0
用户参与
星數1.2k
關注者數18
派生數25
提交數15
已啟用問題?
問題數8
打開的問題數1
拉請求數5
打開的拉請求數0
關閉的拉請求數3
项目设置
已啟用Wiki?
已存檔?
是復刻?
已鎖定?
是鏡像?
是私有?