toolbox

A collection of useful JavaScript utilities

JavaScript Toolbox

A collection of useful JavaScript utilities.

  • Can be used with Node.js and in the browser
  • AMD compatible, you can load it via RequireJS
  • Lightweight
  • Fully documented
  • Tested
Toolbox.getRandomNum(0, 100); // => 51 
Toolbox.getRandomNums(0, 100, 3); // => [10, 54, 12] 
Toolbox.getUid(); // => e80Ewq08td3QurK 
Toolbox.detectMimeType('json'); // => application/json 

To install Toolbox, use NPM.

$ npm install toolbox

Releases are available for download from GitHub.

VersionDescriptionSizeAction
toolbox.jsuncompressed, with comments18.49KB (5.21KB gzipped)Download
toolbox.min.jscompressed, without comments12.96KB (4.2KB gzipped)Download

Documentation

Methods

Examples

Toolbox.getRandomNum(0, 5); // => 2 
Toolbox.getRandomNum(0, 5, 3); // => 2 
Toolbox.getRandomNum(0, 5, [0, 1, 2, 3, 4]); // => 5 

Examples

Toolbox.getRandomNums(0, 5, 3); // => [4, 1, 2] 
Toolbox.getRandomNums(0, 5, 3, 4); // => [3, 2, 0] 
Toolbox.getRandomNums(0, 5, 3, [0, 1, 2]); // => [4, 5, 3] 

Examples

Toolbox.getUid(); // => I1pRhV31R1x5iAY 
Toolbox.getUid(25); // => N9JydVi0A2zot9wg8413QGV3j 
var collections = { 
  numbers: false
};
 
Toolbox.getUid(25, collections); // => ConnMxWPZcvZwxvNoMAQpJHUr 
var collections = { 
  numbers: false,
  lowercase: false
};
 
Toolbox.getUid(25, collections); // => HGXWGZFIQBBWTIRZPGYXELPMP 
var collections = { 
  numbers: false,
  lowercase: false,
  myCollection: '@#${}<>()'
};
 
Toolbox.getUid(25, collections); // => Z@}LI(Q<}U}#Q(K$S}L}CC<@Z 

Examples

Toolbox.getAvg([1, 2, 3, 4, 5]); // => 2 

Examples

Toolbox.getMax([1, 2, 3, 4, 5]); // => 5 

Examples

Toolbox.getMin([1, 2, 3, 4, 5]); // => 1 

Examples

Toolbox.getSum([1, 2, 3, 4, 5]); // => 15 

Examples

Toolbox.detectMimeType('json'); // => application/json 
Toolbox.detectMimeType('application/json'); // => json 

Examples

Toolbox.removeDuplicates([1, 1, 2, 2, 3, 3, 4, 4, 5, 5]); // => [1, 2, 3, 4, 5] 

Examples

Toolbox.shuffle([1, 2, 3, 4, 5]); // => [2, 1, 4, 3, 5] 

Examples

Toolbox.rgbToHex([255, 255, 255]); // => #ffffff 

Examples

Toolbox.hexToRgb('#ffffff'); // => [255, 255, 255] 

Running Tests

$ npm tests/

License

(The MIT License)

Copyright (c) 2011 František Hába <hello@frantisekhaba.com>

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.