fromentries
Object.fromEntries() ponyfill (in 6 lines)
Last updated 4 years ago by feross .
MIT · Repository · Bugs · Original npm · Tarball · package.json
$ gnpm install fromentries 
SYNC missed versions from official npm registry.

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.

Current Tags

  • 1.3.2                                ...           latest (4 years ago)

10 Versions

  • 1.3.2                                ...           4 years ago
  • 1.3.1                                ...           4 years ago
  • 1.3.0                                ...           4 years ago
  • 1.2.1                                ...           4 years ago
  • 1.2.0                                ...           5 years ago
  • 1.1.0                                ...           6 years ago
  • 1.0.3                                ...           6 years ago
  • 1.0.2                                ...           6 years ago
  • 1.0.1                                ...           6 years ago
  • 1.0.0                                ...           6 years ago
Maintainers (1)
Downloads
Today 1
This Week 1
This Month 1
Last Day 0
Last Week 0
Last Month 0
Dependencies (0)
None
Dev Dependencies (2)
Dependents (1)

Copyright 2013 - present © cnpmjs.org | Home |