Skip to content
Make an object or collection from entries deeply.
JavaScript
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
.editorconfig
.eslintrc.json
.gitignore
.huskyrc.json
.lintstagedrc
.npmignore
.size-limit.js
.travis.yml
getTag.js
isNaN.js
isNumber.js
isPlainObject.js
license
objectDeepFromEntries.d.ts
objectDeepFromEntries.js
package.json
readme.md
test.js
yarn.lock

readme.md

object-deep-from-entries

Make an object or collection from entries deeply.

devDependencies Status Build Status Code Coverage

Installation

You can install this package from Yarn:

yarn add object-deep-from-entries

Or NPM:

# 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<string | number>, 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

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"]}
You can’t perform that action at this time.