https://github.com/octet-stream/object-deep-from-entries
Make an object or collection from entries deeply.
https://github.com/octet-stream/object-deep-from-entries
es6 javascript javascript-library library object-deep-from-entries object-from-entries
Last synced: 12 months ago
JSON representation
Make an object or collection from entries deeply.
- Host: GitHub
- URL: https://github.com/octet-stream/object-deep-from-entries
- Owner: octet-stream
- License: mit
- Created: 2018-03-20T22:17:36.000Z (over 8 years ago)
- Default Branch: main
- Last Pushed: 2024-03-28T19:20:29.000Z (over 2 years ago)
- Last Synced: 2025-03-18T10:49:21.808Z (over 1 year ago)
- Topics: es6, javascript, javascript-library, library, object-deep-from-entries, object-from-entries
- Language: JavaScript
- Homepage: https://www.npmjs.com/package/object-deep-from-entries
- Size: 628 KB
- Stars: 3
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: readme.md
- License: license
Awesome Lists containing this project
README
# object-deep-from-entries
Make an object or collection from entries deeply.
[](https://codecov.io/github/octet-stream/object-deep-from-entries?branch=master)
[](https://github.com/octet-stream/object-deep-from-entries/actions/workflows/ci.yml)
[](https://github.com/octet-stream/object-deep-from-entries/actions/workflows/eslint.yml)
## Installation
You can install this package from Yarn:
```sh
yarn add object-deep-from-entries
```
Or NPM:
```sh
# Since ~5.x version you can omit the --save flag
npm install object-deep-from-entries
```
## API
`objectDeepFromEntries(entries) -> {object | object[] | any[]}`
* **{Array<[string | number | Array, any]>}** – An array of
tuples with paths and values. Path might be a **string**,
**number** or an **array** of those to types. Value may have any type.
### Usage
```js
import objectDeepFromEntries from "object-deep-from-entries"
// You can create a flat object using entries in the same format
const flat = [
[
"name", "John Doe"
],
[
"age", 25
],
[
"gender", "Male"
]
]
objectDeepFromEntries(flat)
// -> {name: "John Doe", age: 25, gender: "Male"}
// This function is also useful for making "deep" objects. Let's take a look:
const deep = [
[
"name", "John Doe"
],
[
["skills", 0], "Node.js"
],
[
["skills", 1], "JavaScript"
],
[
["skills", 2], "Preact"
]
]
objectDeepFromEntries(deep)
// -> {name: "John Doe", skills: [Node.js, "JavaScript", "Preact"]}
```