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

keypather

Package Overview
Dependencies
Maintainers
1
Versions
26
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

keypather - npm Package Compare versions

Comparing version 1.4.0 to 1.5.0

test/has.js

52

index.js

@@ -39,2 +39,30 @@ var valueForKeypath = module.exports = function (opts) {

};
Keypather.prototype.in = function (obj, keypath) {
this.obj = obj;
keypath = keypath + '';
this.create = false;
if (last(keypath) === ')') {
throw new TypeError('keypath should not end in a function');
}
this.keypathSplit = keypath.split('.');
var lastKey = this.getLastKey();
var val = this.getLastObj(arguments);
return lastKey in val;
};
Keypather.prototype.has = function (obj, keypath) {
this.obj = obj;
keypath = keypath + '';
this.create = false;
if (last(keypath) === ')') {
throw new TypeError('keypath should not end in a function');
}
this.keypathSplit = keypath.split('.');
var lastKey = this.getLastKey();
var val = this.getLastObj(arguments);
return val.hasOwnProperty(lastKey);
};
Keypather.prototype.del = function (obj, keypath /*, fnArgs... */) {

@@ -46,3 +74,3 @@ this.obj = obj;

// deletes function result..does nothing. equivalent to invoking function and returning true
this.get(obj, keypath);
// this.get(obj, keypath); // not even necessary since this doesnt actually do anything
return true;

@@ -53,11 +81,3 @@ }

var lastKey = this.getLastKey();
var val;
if (this.keypathSplit.length === 0) {
val = obj;
}
else {
var getArgs = Array.prototype.slice.call(arguments);
getArgs[1] = this.keypathSplit.join('.');
val = this.get.apply(this, getArgs);
}
var val = this.getLastObj(arguments);

@@ -163,2 +183,14 @@ delete val[lastKey];

};
Keypather.prototype.getLastObj = function (args) {
var val;
if (this.keypathSplit.length === 0) {
val = args[0];
}
else {
var getArgs = Array.prototype.slice.call(args);
getArgs[1] = this.keypathSplit.join('.');
val = this.get.apply(this, getArgs);
}
return val;
};
Keypather.prototype.createPath = function (val /*, keys */) {

@@ -165,0 +197,0 @@ var keys = Array.prototype.slice.call(arguments, 1);

2

package.json
{
"name": "keypather",
"version": "1.4.0",
"version": "1.5.0",
"description": "Get or set a object values from a keypath string. Supports bracket notation, dot notation, and functions",

@@ -5,0 +5,0 @@ "main": "index.js",

@@ -130,5 +130,17 @@ # keypather [![Build Status](https://travis-ci.org/tjmehta/keypather.png?branch=master)](https://travis-ci.org/tjmehta/keypather)

## IN
Equivalent to `key in obj`
## HAS
Equivalent to `obj.hasOwnProperty`
## DEL
mixed notation, dot notation, and bracket notation all supported:
Equivalent to `delete obj.key`

@@ -135,0 +147,0 @@ ```js

var keypather = require('../index')();
describe('del', function () {
describe("valueForKeyPath.del(obj, 'foo.bar', 'value')", del("foo.bar", 'value'));
describe("valueForKeyPath.del(obj, 'foo.bar', 'value')", del("['foo'].bar", 'value'));
describe("valueForKeyPath.del(obj, 'foo['bar']', 'value')", del("foo['bar']", 'value'));
describe("valueForKeyPath.del(obj, 'foo['bar']', 'value')", del("['foo']['bar']", 'value'));
describe("keypather.del(obj, 'foo.bar')", del("foo.bar"));
describe("keypather.del(obj, 'foo.bar')", del("['foo'].bar"));
describe("keypather.del(obj, 'foo['bar']')", del("foo['bar']"));
describe("keypather.del(obj, 'foo['bar']')", del("['foo']['bar']"));
});
function del (keypath, value) {
function del (keypath) {
return function () {

@@ -12,0 +12,0 @@ before(function () {

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