entries-to-object

1.0.1 • Public • Published

Install

npm install entries-to-object

Usage

import entriesToObject from 'entries-to-object';

let object = entriesToObject(entries);

Example

let object = entriesToObject([
	['lastname', 'Doe'],
	['firstname', 'John'],
	['age', 30],
	['hobbies[]', 'hiking'],
	['hobbies[]', 'reading'],
	['hobbies[]', 'playing guitar'],
	['address.city', 'Anytown'],
	['address.street', '123 Main St'],
]);

/*
object = {
	lastname: 'Doe',
	firstanem: 'John,
	age: 30,
	hobbies: ['hiking', 'reading', 'playing guitar'],
	address: {
		city: 'Anytown',
		street: '123 Main St'
	}
}
*/

Anything that has an iterator with [key, value] pairs can also be used as entries:

  • Map
  • Headers
  • FormData
  • URLSearchParams

Readme

Keywords

none

Package Sidebar

Install

npm i entries-to-object

Weekly Downloads

1

Version

1.0.1

License

ISC

Unpacked Size

2.09 kB

Total Files

3

Last publish

Collaborators

  • subhero