Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@arg-def/dot-notation

Package Overview
Dependencies
Maintainers
1
Versions
7
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@arg-def/dot-notation

Object readings and transformations using dot notation syntax

  • 0.1.6
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
7
increased by16.67%
Maintainers
1
Weekly downloads
 
Created
Source

@arg-def/dot-notation

Object readings and transformations using dot notation syntax

NPM Version Build Status Downloads Stats GitHub stars Known Vulnerabilities GitHub issues Awesome install size gzip size

Demo

Play around with dot-notation and experience the magic!

Edit @arg-def/dot-notation

Installation

npm install @arg-def/dot-notation --save
#or
yarn add @arg-def/dot-notation

How to use

Picking a value

import dot from '@arg-def/dot-notation';

const source = {
  person: {
    name: {
      firstName: 'John',
      lastName: 'Doe'
    },
    address: [
      {
        street: 'Infinite Loop',
        city: 'Cupertino',
        state: 'CA',
        postalCode: 95014,
        country: 'United States'
      },
    ]
  }
};

dot.pick('person.name', source);
//outputs { firstName: 'John', lastName: 'Doe' }

dot.pick('person.address[0].street', source);
//outputs "Infinite Loop"

Parsing an object

Conventional parsing
import dot from '@arg-def/dot-notation';

const source = {
  'person.name.firstName': 'John',
  'person.name.lastName': 'Doe',
  'person.address[].street': 'Infinite Loop',
  'person.address[].city': 'Cupertino',
  'person.address[].postalCode': 95014,
};

dot.parse(source);

/* outputs
{
  person: {
    name: {
      firstName: 'John',
      lastName: 'Doe',
    },
    address: [
      {
        street: 'Infinite Loop',
        city: 'Cupertino',
        postalCode: 95014,
      },
    ],
  },
}
*/
With multiple array items
import dot from '@arg-def/dot-notation';

const source = {
  'person.name.firstName': 'John',
  'person.name.lastName': 'Doe',
  'person.address[0].street': 'Infinite Loop',
  'person.address[0].city': 'Cupertino',
  'person.address[0].postalCode': 95014,
  'person.address[1].street': '1600 Amphitheatre',
  'person.address[1].city': 'Mountain View',
  'person.address[1].postalCode': 94043,
};


dot.parse(source);


/* outputs
{
  person: {
    name: {
      firstName: 'John',
      lastName: 'Doe',
    },
    address: [
      {
        street: 'Infinite Loop',
        city: 'Cupertino',
        postalCode: 95014,
      },
      {
        street: 'g1600 Amphitheatre',
        city: 'Mountain View',
        postalCode: 94043,
      },
    ],
  },
}
*/

Parsing single key

import dot from '@arg-def/dot-notation';

const source = 'person.name';
const value = 'John Doe';

dot.parseKey(source, value);

/* outputs
{
  person: {
    name: 'John Doe',
  },
}
*/

Keywords

FAQs

Package last updated on 13 Jul 2020

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

SocketSocket SOC 2 Logo

Product

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

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc