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

dotty

Package Overview
Dependencies
Maintainers
1
Versions
5
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

dotty - npm Package Compare versions

Comparing version 0.0.1 to 0.0.2

.travis.yml

6

example.js

@@ -33,2 +33,8 @@ var dotty = require("./lib/index");

console.log(dotty.remove(object, "a.b.x"));
console.log(dotty.remove(object, "a.b.y"));
console.log(dotty.deepKeys(object));
console.log(dotty.deepKeys(object).map(function(e) { return e.join("."); }));
console.log(object);

@@ -160,1 +160,75 @@ //

};
//
// `remove` is like `put` in reverse!
//
// The return value is `true` in the case that the value existed and was removed
// successfully, or `false` otherwise.
//
var remove = module.exports.remove = function remove(object, path, value) {
if (typeof path === "string") {
path = path.split(".");
}
if (!(path instanceof Array) || path.length === 0) {
return false;
}
path = path.slice();
var key = path.shift();
if (typeof object !== "object" || object === null) {
return false;
}
if (path.length === 0) {
if (!Object.hasOwnProperty.call(object, key)) {
return false;
}
delete object[key];
return true;
} else {
return remove(object[key], path, value);
}
};
//
// `deepKeys` creates a list of all possible key paths for a given object.
//
// The return value is always an array, the members of which are paths in array
// format. If you want them in dot-notation format, do something like this:
//
// ```js
// dotty.deepKeys(obj).map(function(e) {
// return e.join(".");
// });
// ```
//
// *Note: this will probably explode on recursive objects. Be careful.*
//
var deepKeys = module.exports.deepKeys = function deepKeys(object, prefix) {
if (typeof prefix === "undefined") {
prefix = [];
}
var keys = [];
for (var k in object) {
if (!Object.hasOwnProperty.call(object, k)) {
continue;
}
keys.push(prefix.concat([k]));
if (typeof object[k] === "object" && object[k] !== null) {
keys = keys.concat(deepKeys(object[k], prefix.concat([k])));
}
}
return keys;
};

6

package.json
{
"name": "dotty",
"version": "0.0.1",
"version": "0.0.2",
"description": "Access properties of nested objects using dot-path notation",

@@ -24,5 +24,5 @@ "main": "lib/index.js",

"devDependencies": {
"vows": "~0.6.3",
"docco": "~0.3.0"
"vows": "~0.7.0",
"docco": "~0.6.2"
}
}

@@ -1,2 +0,2 @@

Dotty
Dotty [![build status](https://secure.travis-ci.org/deoxxa/dotty.png)](http://travis-ci.org/deoxxa/dotty)
=====

@@ -12,2 +12,11 @@

Installation
------------
Here's a link to the [npm](https://npmjs.org/package/dotty) page.
npm install dotty
Usage

@@ -52,2 +61,8 @@ -----

console.log(dotty.remove(object, "a.b.x"));
console.log(dotty.remove(object, "a.b.y"));
console.log(dotty.deepKeys(object));
console.log(dotty.deepKeys(object).map(function(e) { return e.join("."); }));
console.log(object);

@@ -54,0 +69,0 @@ ```

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

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