toolbelt.js
v1.2.0
Published
[![Build Status](https://secure.travis-ci.org/MrBoolean/toolbelt.js.png)](https://travis-ci.org/MrBoolean/toolbelt.js/) [![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/MrBoolean/toolbelt.js/trend.png)](https://bitdeli.com/free "Bitdeli Badge")
Downloads
3
Readme
toolbelt.js
toolbelt.js
is a powerful and easy way to reduce the lines of code. It includes a lot of utility functions like camelize
or slugify
.
Install
npm install toolbelt.js
API
For the examples below you have to require toolbelt.js using:
var tb = require('toolbelt.js');
camelize
tb.camelize('this-is-awesome', '-'); // ThisIsAwesome
separate
tb.separate('ThisIsAwesome', '-'); // this-is-awesome
define
var Project = {},
tb = require('toolbelt.js')
Project.User = { firstname: 'Tool', lastname: 'Belt' };
tb.define(Project, 'User.children.first', { firstname: 'Jon', lastname: 'Doe' });
console.log(Project.User.children.first.firstname); // Jon
lcfirst
tb.lcfirst('Toolbelt.js'); // toolbelt.js
ucfirst
tb.ucfirst('toolbelt.js'); // Toolbelt.js
series
tb.series(1, 10).forEach(function(value) {
console.log(value);
}); // 1 2 3 4 5 6 7 8 9 10
slugify
tb.slugify('This is TOOLBELT'); // this-is-toolbelt
truncate
tb.truncate('Lorem ipsum set amet', 10); // Lorem ipsu...
clone
var data = { firstname: 'Jon', lastname: 'Doe' },
cloned;
cloned = tb.clone(data);
data.firstname = 'Max';
console.log(cloned.firstname); // Jon
scope
function Jon() {
this.firstname = 'Jon';
}
function display(lastname) {
console.log(this.firstname, lastname);
}
tb.scope(display, new Jon(), 'Doe')(); // Jon Doe
unique
tb.unique([1, 1, 2, 3]); // [1, 2, 3]
min
tb.min([1, 2, 3]); // 1
max
tb.max([1, 2, 3]); // 3
pluck
var data = [
{ name: 'Jon Doe', age: 20 },
{ name: 'Max Mustermann', age: 18 }
];
tb.pluck(data, 'name'); // ['Jon', 'Max']
size
tb.size({ firstname: 'Jon', lastname: 'Doe' }); // 2
grep
var data = [
{ name: 'Jon Doe', age: 20 },
{ name: 'Max Mustermann', age: 18 }
];
tb.grep(data, function(item) {
return item.age > 18;
}); // { name: 'Jon Doe', age: 20 }
Contribute
There are many ways to help me: Report issues, write code or simply: make it public!
Coding Standard
- Indent using four spaces
- The functions name === filename
- Write tests!
License
The MIT License (MIT)
Copyright (c) 2013 Marc Binder
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.