Socket
Socket
Sign inDemoInstall

fromentries

Package Overview
Dependencies
0
Maintainers
1
Versions
10
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    fromentries

Object.fromEntries() ponyfill (in 6 lines)


Version published
Weekly downloads
3.5M
decreased by-7.35%
Maintainers
1
Install size
5.60 kB
Created
Weekly downloads
 

Readme

Source

fromentries travis npm downloads javascript style guide

Object.fromEntries() ponyfill (in 6 lines)

Install

npm install fromentries

Why this package?

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:

  • Chrome
  • Firefox
  • Edge
  • Safari
  • Opera

It does not work in browsers like IE11 and older (unless you transpile it first).

Usage

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' }

What is a ponyfill?

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.

See also

License

MIT. Copyright (c) Feross Aboukhadijeh.

Keywords

FAQs

Last updated on 04 Nov 2020

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc