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

dot-get

Package Overview
Dependencies
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

dot-get

Utilities for setting and clearing deep object properties using mongo-style dotted paths

  • 1.0.0
  • npm
  • Socket score

Version published
Weekly downloads
1K
increased by184.97%
Maintainers
1
Weekly downloads
 
Created
Source

dot-get

Simple utilities for setting, getting, and clearing object properties using mongo-style dot paths.

Installation

Install with npm:

npm install dot-get

or with bower:

bower install dot-get

Usage

In node:

var dot = require("dot-get");
var obj = {
  first: {
    second: 1
  },
  array: [1, {subobject: "good"}, 3]
};

// retrieving values
dot.get(obj, "first.second"); // <= 1
dot.get(obj, "first"); // <= {second: 1}
dot.get(obj, "missing.whatever.ok"); // <= undefined
dot.get(obj, "array.1.subobject"); // <= "good"

// setting values
dot.set(obj, "first.second", 2);
dot.set(obj, "new.key", "ok");
dot.set(obj, "array.0", {subobject: "grand"});

// clearing values
dot.clear(obj, "new.key");
dot.clear(obj, "first");
dot.clear(obj, "array.2");

// flattening objects
var obj = {
  first: {
    second: 1
  },
  array: [1, {subobject: "good"}, 3]
};
dot.flatten(obj);
console.log(obj)
{
 "first.second": 1,
 "array.0": 1,
 "array.1.subobject": "good",
 "array.2": 3
}

// Create a mongo replacement modifier for two objects.
var orig = {a: 1, b: 2};
var desired = {a: 2, c: 3};
dot.mongoReplacementModifier(desired, orig);
// {$set: {a: 2, c: 3}, $unset: {b: ""}}

FAQs

Package last updated on 22 Oct 2015

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