0.9.3 • Published 10 years ago
underscore-keypath v0.9.3
underscore-keypath
key-path mechanism extensions for underscore (mixin).
underscore-keypath let you access JavaScript objects and arrays with keypath easily.
var foo = {
bar : {
name : "Cool!"
},
scores : [55, 27, 100, 33]
};
_(foo).valueForKeyPath("bar.name"); // --> "Cool!"
_(foo).setValueForKeyPath("bar.name", "BAR"); // --> sets foo.bar.name as "BAR"
_(foo).valueForKeyPath("scores.@max"); // --> 100Install
NodeJS
$ npm install underscore-keypathvar _ = require("underscore-keypath");or you may want to use origianl underscore:
var _ = require("underscore");
require("underscore-keypath"); // it will extend original underscorein this case, please install "underscore" first.
$ npm install underscore
$ npm install underscore-keypathOtherwise, underscore-keypath extends separated underscore in sandbox.
Meteor
$ meteor add jeeeyul:underscore-keypathFront-end
$ bower install underscore-keypathOr just download underscore-keypath.js manually.
Examples
var list = [{
name : "foo",
info : {
favoriteColor : "red",
age : 20
}
},{
name : "bar",
info : {
favoriteColor : "green",
age : 17
}
},{
name : "zar",
info : {
favoriteColor : "red",
age : 34
}
}];
_(list).pluckByKeyPath("info.age"); // --> [20, 17, 34]
_(list).sortByKeyPath("info.age"); // --> [{name:"bar", ..}, {name:"foo", ..}, {name:"zar", ..}]
_(list).groupByKeyPath("info.favoriteColor"); // --> {red:2, green:1}See API Document
0.9.3
10 years ago
0.9.2
10 years ago
0.9.1
10 years ago
0.9.0
10 years ago
0.0.22
11 years ago
0.0.21
11 years ago
0.0.20
11 years ago
0.0.19
11 years ago
0.0.18
11 years ago
0.0.17
11 years ago
0.0.15
12 years ago
0.0.14
12 years ago
0.0.13
12 years ago
0.0.12
12 years ago
0.0.11
12 years ago
0.0.10
12 years ago
0.0.7
12 years ago
0.0.5
12 years ago
0.0.4
12 years ago
0.0.3
12 years ago
0.0.2
12 years ago
