0.1.7 • Published 10 years ago

jstk v0.1.7

Weekly downloads
2
License
-
Repository
github
Last release
10 years ago

JSTK

(JavaScript Toolkit)

Usage

var _ = require('jstk').bind(require('lodash'));

Features

Matcher

Scala like match syntax

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); // 12

getProperty

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'}}
0.1.7

10 years ago

0.1.6

10 years ago

0.1.5

10 years ago

0.1.4

10 years ago

0.1.3

10 years ago

0.1.2

10 years ago

0.1.1

10 years ago

0.1.0

10 years ago

0.0.18

10 years ago

0.0.17

10 years ago

0.0.13

11 years ago

0.0.12

11 years ago

0.0.11

11 years ago

0.0.10

11 years ago

0.0.9

11 years ago