Philipp Partosch 46a936d7de added all files to project | 2 years ago | |
---|---|---|
.. | ||
LICENSE | 2 years ago | |
README.md | 2 years ago | |
index.d.ts | 2 years ago | |
index.js | 2 years ago | |
package.json | 2 years ago |
npm install fromentries
Existing polyfill packages (like
object.fromentries
)
pull in a bunch of dependencies and adds over 8
KB to the browser bundle size. This allows them to work in ES3 environments
like IE6, but it’s also overkill; almost no one supports IE6 anymore.
I’d rather not ship tons of extra code to website visitors. A polyfill for this
feature can be implemented in a few short lines of code using modern language
features. That’s what fromentries
(this package) does.
This means that fromentries
only works in evergreen browsers like:
It does not work in browsers like IE11 and older (unless you transpile it first).
const fromEntries = require('fromentries')
const map = new Map([ [ 'a', 1 ], [ 'b', 2 ], [ 'c', 3 ] ])
const obj = fromEntries(map)
constole.log(obj) // { a: 1, b: 2, c: 3 }
const searchParams = new URLSearchParams('foo=bar&baz=qux')
const obj2 = fromEntries(searchParams)
console.log(obj2) // { foo: 'bar', 'baz': 'qux' }
A ponyfill is almost the same as a polyfill, but not quite. Instead of patching functionality for older browsers, a ponyfill provides that functionality as a standalone module you can use.
Read more at PonyFoo.
MIT. Copyright © Feross Aboukhadijeh.