Socket
Socket
Sign inDemoInstall

simple-flat-object

Package Overview
Dependencies
5
Maintainers
1
Versions
1
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    simple-flat-object

Flatten/Unflatten JS Objects


Version published
Maintainers
1
Created

Readme

Source

Simple Flat Object

A small library that converts an object into a flat (depth=1) object. Useful if you need to change the values of all instances of a key with the same name.

Installation

yarn install

Usage

import FlatObject from 'simple-flat-object';

var data = {
  "foo": "bar",
  "bar": [
    {
      "c": "d",
      "foo": "d"
    }
  ]
};

const flatData = FlatObject.flatten(data);
console.log(flatData);
/*
{ 
  foo: 'bar',
  'bar[0].c': 'd',
  'bar[0].foo': 'd'
}
*/

for (let key in flatData) {
  if (key.includes('foo')) {
    flatData[key] = `Updated ${flatData[key]}`;
  }
}
data = FlatObject.unflatten(flatData);
console.log(data);
/*
{ 
  foo: 'Updated bar',
  bar: [
    {
      c: 'd',
      foo: 'Updated d'
    }
  ]
}
*/

Tests

Unit

Unit tests use the Mocha test framework with Chai assertions. To run the tests, execute the following command in the top-level application directory:

npm test

Keywords

FAQs

Last updated on 25 Apr 2017

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.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc