Research
Security News
Malicious npm Package Targets Solana Developers and Hijacks Funds
A malicious npm package targets Solana developers, rerouting funds in 2% of transactions to a hardcoded address.
fromentries
Advanced tools
The 'fromentries' npm package provides a polyfill for the Object.fromEntries method, which transforms a list of key-value pairs into an object. This is particularly useful for converting Map objects or arrays of pairs into plain JavaScript objects.
Convert Array of Pairs to Object
This feature allows you to convert an array of key-value pairs into a plain JavaScript object. This is useful for scenarios where data is received in a pair format and needs to be transformed into an object.
const fromEntries = require('fromentries');
const entries = [['name', 'Alice'], ['age', 30]];
const obj = fromEntries(entries);
console.log(obj); // { name: 'Alice', age: 30 }
Convert Map to Object
This feature allows you to convert a Map object into a plain JavaScript object. This is useful for scenarios where data is stored in a Map and needs to be transformed into an object for easier manipulation.
const fromEntries = require('fromentries');
const map = new Map([['name', 'Bob'], ['age', 25]]);
const obj = fromEntries(map);
console.log(obj); // { name: 'Bob', age: 25 }
The 'object.fromentries' package is another polyfill for the Object.fromEntries method. It provides similar functionality to 'fromentries' by converting arrays of key-value pairs or Map objects into plain JavaScript objects. Both packages serve the same purpose, but 'object.fromentries' might have different implementation details or additional features.
Lodash is a utility library that provides a wide range of functions for manipulating arrays, objects, and other data types. While it is not a direct polyfill for Object.fromEntries, Lodash offers similar functionality through its '_.fromPairs' method, which converts arrays of key-value pairs into objects. Lodash is more comprehensive and includes many other utility functions beyond just converting pairs to objects.
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 (c) Feross Aboukhadijeh.
FAQs
Object.fromEntries() ponyfill (in 6 lines)
We found that fromentries demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
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.
Research
Security News
A malicious npm package targets Solana developers, rerouting funds in 2% of transactions to a hardcoded address.
Security News
Research
Socket researchers have discovered malicious npm packages targeting crypto developers, stealing credentials and wallet data using spyware delivered through typosquats of popular cryptographic libraries.
Security News
Socket's package search now displays weekly downloads for npm packages, helping developers quickly assess popularity and make more informed decisions.