0.1.7 • Published 11 years ago
jstk v0.1.7
JSTK
(JavaScript Toolkit)
Usage
var _ = require('jstk').bind(require('lodash'));Features
Matcher
var numberMatcher = _.matcher({
	'1': function() {
		return 'one'
	},
	'2': function() {
		return 'two'
	}	
});
console.log(numberMatcher(1)); // 'one'
console.log(numberMatcher(2)); // 'two'toInt
Always uses 10 as radix.
var integer = _.toInt('012');
console.log(integer); // 12getProperty
Able to handle nested objects using array or the '.' notation in the keys.
var people = [{
  name: {
    first: 'John',
    second: 'Smith'
  },
  age: 45
},
{
  name: {
    first: 'Sheela',
    second: 'Smith'
  },
  age: 34
}];
var names = _.map(people, _.getProperty('name.first'));
console.log(names); // ['John', 'Sheela']
var names = _.map(people, _.getProperty(['name', 'first']));
console.log(names); // ['John', 'Sheela']repeat
var letters = _.repeat(5, 'w');
console.log(letters); // ['w', 'w', 'w', 'w', 'w']recursiveMapValues
Recursive version of mapValues. Keys are returned as an array in the iterator function.
var obj = recursiveMapValues({a: 1, b: {c: 1}}, function(e) {
  return e * 2;
});
console.log(obj); // {a: 2, b: {c: 2}}
var obj2 = recursiveMapValues({a: 1, b: {c: 1}}, function(value, keys) {
  return keys.join('.');
});
console.log(obj2); // {a: 'a', b: {c: 'b.c'}}