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

underscore-keypath

Package Overview
Dependencies
Maintainers
1
Versions
21
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

underscore-keypath - npm Package Compare versions

Comparing version 0.0.2 to 0.0.3

lib/underscore-keypath.min.js

31

lib/underscore-keypath.js

@@ -26,2 +26,24 @@ (function(){

function getArrayProperty(array, name){
if(name == "@first"){
return _.first(array);
}
else if(name == "@last"){
return _.last(array);
}
else if(name == "@max"){
return _.max(array);
}
else if(name == "@min"){
return _.min(array);
}
else if(name == "@size"){
return _.size(array);
}
};
function getProperty(obj, name){

@@ -31,2 +53,6 @@ if(name == ""){

}
else if(name.indexOf("@") === 0){
return getArrayProperty(obj, name);
}

@@ -158,4 +184,9 @@ var target = obj["get" + capitalize(name)];

};
var alisas = {
"getValueForKeyPath" : mixins.valueForKeyPath
};
_.mixin(mixins);
_.mixin(alisas);

@@ -162,0 +193,0 @@ if(isNodeJS){

8

package.json
{
"name" : "underscore-keypath",
"version" : "0.0.2",
"version" : "0.0.3",

@@ -10,3 +10,3 @@ "author" : "Jeeeyul Lee <jeeeyul@gmail.com>",

"main" : "./lib/underscore-keypath",
"main" : "./lib/underscore-keypath.min.js",

@@ -28,8 +28,10 @@ "repository" : {

"mocha" : "1.0.x",
"should" : "3.1.2"
"should" : "3.1.2",
"uglify-js" : "2.4.x"
},
"scripts" : {
"minify" : "uglifyjs lib/underscore-keypath.js -o lib/underscore-keypath.min.js --source-map lib/underscore-keypath.min.js.map -m",
"test" : "mocha -R spec"
}
}

@@ -38,2 +38,2 @@ # underscore-keypath

see [API](https://github.com/jeeeyul/underscore-obj/wiki/API) Document
see [API](https://github.com/jeeeyul/underscore-keypath/wiki/API) Document

@@ -9,3 +9,5 @@ var _ = require("../lib/underscore-keypath");

"name" : "a",
"tag" : "foo"
"tag" : "foo",
"age" : 1,
"data" : [1, 3, 5, 7, 9]
}

@@ -15,3 +17,4 @@ },

"entry" : {
"name" : "b"
"name" : "b",
"age" : 2
}

@@ -22,3 +25,4 @@ },

"name" : "c",
"tag" : "foo"
"tag" : "foo",
"age" : 3
}

@@ -56,1 +60,29 @@ }

});
describe("@property", function(){
it("@first should have to return first element", function(){
_(arr).valueForKeyPath("@first.entry.name").should.be.exactly("a");
});
it("@last should have to return last element", function(){
_(arr).valueForKeyPath("@last.entry.name").should.be.exactly("c");
});
it("@max should have to return max value of list", function(){
_.chain(arr)
.pluckByKeyPath("entry.age")
.max()
.value().should.be.exactly(3);
_(arr).valueForKeyPath("@first.entry.data.@max").should.be.exactly(9);
});
it("@min should have to return min value of list", function(){
_(arr).valueForKeyPath("@first.entry.data.@min").should.be.exactly(1);
});
it("@size should have to return size of list", function(){
_(arr).valueForKeyPath("@size").should.be.exactly(3);
});
});

@@ -64,3 +64,12 @@ var _ = require("../lib/underscore-keypath");

describe("plain property", function(){
it("valueForKeyPath returns value of given keypath", function(){
_(foo).valueForKeyPath("bar.name").should.be.exactly("bar");
});
it("getValueForKeyPath must be act same as valueForKeyPath", function(){
_(foo).getValueForKeyPath("bar.name").should.be.exactly("bar");
});
});
});
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