New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details →
Socket
Book a DemoSign in
Socket

flat-the-object

Package Overview
Dependencies
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

flat-the-object

Convert the Object into flatten object

latest
Source
npmnpm
Version
1.0.2
Version published
Maintainers
1
Created
Source

Flat the object

The purpose of the package is to convert the nested object into faltten object

Installation

$ npm install flat-the-object

Example

This is the practical example of how to use

const getFlattenObject = require('flat-the-object')

const user = {
    name: "Your Name",
    address: {
        personal: {
            city: "NY",
            state: "WX",
            coordinates: {
                x: 35.12,
                y: -21.49,
            },
        },
    },
    contact: {
        phone: {
            home: "xxx",
            office: "yyy",
        },
        email: {
            home: "xxx",
            office: "yyy"
        },
    },
};

//convert the object by passing the object in the function
//there are 2 parameters 
//1. the actual object
//2. give the name and object key will start with that name

console.log(getFlattenObject(user, "data"));

// result will be like this:
// {
//   data_name: 'Your Name',
//   data_address_personal_city: 'NY',
//   data_address_personal_state: 'WX',
//   data_address_personal_coordinates_x: 35.12,
//   data_address_personal_coordinates_y: -21.49,
//   data_contact_phone_home: 'xxx',
//   data_contact_phone_office: 'yyy',
//   data_contact_email_home: 'xxx',
//   data_contact_email_office: 'yyy'
// }

Keywords

flat

FAQs

Package last updated on 08 Sep 2022

Did you know?

Socket

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.

Install

Related posts