0.2.1 • Published 1 month ago

jstkstarks v0.2.1

Weekly downloads
-
License
MIT
Repository
github
Last release
1 month 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.2.1

1 month ago

0.2.0

1 month ago

0.1.9

1 month ago

0.1.8

2 months ago

0.1.7

2 months ago