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

dotty

Package Overview
Dependencies
Maintainers
3
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.2 to 0.1.0

.jshintrc

3

example.js

@@ -37,4 +37,5 @@ var dotty = require("./lib/index");

console.log(dotty.deepKeys(object));
console.log(dotty.deepKeys(object).map(function(e) { return e.join("."); }));
console.log(dotty.deepKeys(object, {leavesOnly: true}));
console.log(dotty.deepKeys(object, {leavesOnly: true, asStrings: true}));
console.log(object);

@@ -84,4 +84,7 @@ //

//
// If an action function is specified, that action will be applied to each
// match. Action params are value, parent and key.
//
var search = module.exports.search = function search(object, path) {
var search = module.exports.search = function search(object, path, action) {
if (typeof path === "string") {

@@ -112,5 +115,11 @@ path = path.split(".");

if (path.length === 0) {
return Object.keys(object).filter(key.test.bind(key)).map(function(k) { return object[k]; });
return Object.keys(object).filter(key.test.bind(key)).map(function(k) {
var value = object[k];
if(action){
action(value, object, k);
}
return value;
});
} else {
return Array.prototype.concat.apply([], Object.keys(object).filter(key.test.bind(key)).map(function(k) { return search(object[k], path); }));
return Array.prototype.concat.apply([], Object.keys(object).filter(key.test.bind(key)).map(function(k) { return search(object[k], path, action); }));
}

@@ -120,2 +129,14 @@ };

//
// Perform a search and remove the matched keys.
// The return value is the same object argument with modifications.
//
var removeSearch = module.exports.removeSearch = function removeSearch(object, path){
search(object, path, function(value, object, key){
delete object[key];
});
return object;
};
//
// The first two arguments for `put` are the same as `exists` and `get`.

@@ -216,3 +237,5 @@ //

var deepKeys = module.exports.deepKeys = function deepKeys(object, prefix) {
var deepKeys = module.exports.deepKeys = function deepKeys(object, options, prefix) {
options = options || {};
if (typeof prefix === "undefined") {

@@ -229,10 +252,16 @@ prefix = [];

keys.push(prefix.concat([k]));
if (!options.leavesOnly || typeof object[k] !== "object") {
keys.push(prefix.concat([k]));
}
if (typeof object[k] === "object" && object[k] !== null) {
keys = keys.concat(deepKeys(object[k], prefix.concat([k])));
keys = keys.concat(deepKeys(object[k], {leavesOnly: options.leavesOnly}, prefix.concat([k])));
}
}
if (options.asStrings) {
keys = keys.map(function(e) { return e.join("."); });
}
return keys;
};

@@ -0,0 +0,0 @@ Copyright (c) 2012, Deoxxa Development

{
"name": "dotty",
"version": "0.0.2",
"version": "0.1.0",
"description": "Access properties of nested objects using dot-path notation",

@@ -8,3 +8,3 @@ "main": "lib/index.js",

"test": "vows",
"prepublish": "docco lib/*"
"prepare": "docco \"./lib/index.js\""
},

@@ -23,7 +23,7 @@ "repository": {

"author": "Conrad Pankoff <deoxxa@fknsrs.biz> (http://www.fknsrs.biz/)",
"license": "BSD",
"license": "BSD-3-Clause",
"devDependencies": {
"vows": "~0.7.0",
"docco": "~0.6.2"
"vows": "^0.8.0",
"docco": "^0.8.0"
}
}

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

Dotty [![build status](https://secure.travis-ci.org/deoxxa/dotty.png)](http://travis-ci.org/deoxxa/dotty)
Dotty [![build status](https://secure.travis-ci.org/deoxxa/dotty.png)](http://travis-ci.org/deoxxa/dotty) [![npm](https://img.shields.io/npm/v/dotty.svg)](https://www.npmjs.com/package/dotty)
=====

@@ -16,3 +16,3 @@

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

@@ -50,3 +50,3 @@ npm install dotty

console.log(dotty.get(object, "a.b.z")); // undefined
console.log(dotty.get(object, ["a", "b", "z"])); // undefine
console.log(dotty.get(object, ["a", "b", "z"])); // undefined

@@ -61,2 +61,5 @@ dotty.put(object, "a.b.hello", "hi");

console.log(dotty.search(object, ["a", "*", /..+/]));
console.log(dotty.search(object, 'a.b.*', function(value, parent, key){
parent[key] = value + '!';
}));

@@ -66,4 +69,7 @@ console.log(dotty.remove(object, "a.b.x"));

console.log(dotty.removeSearch(object, 'a.*.x'));
console.log(dotty.deepKeys(object));
console.log(dotty.deepKeys(object).map(function(e) { return e.join("."); }));
console.log(dotty.deepKeys(object, {leavesOnly: true}));
console.log(dotty.deepKeys(object, {leavesOnly: true, asStrings: true}));

@@ -70,0 +76,0 @@ console.log(object);

@@ -0,0 +0,0 @@ var dotty = require("../lib/index"),

@@ -0,0 +0,0 @@ var dotty = require("../lib/index"),

@@ -0,0 +0,0 @@ var dotty = require("../lib/index"),

@@ -0,0 +0,0 @@ var dotty = require("../lib/index"),

@@ -0,0 +0,0 @@ var dotty = require("../lib/index"),

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