Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
A collection of useful JavaScript utilities
JavaScript
branch: master

Fetching latest commit…

Cannot retrieve the latest commit at this time

Failed to load latest commit information.
dist
src
tests
.gitignore
.npmignore
.travis.yml
README.md
package.json

README.md

JavaScript Toolbox

Build Status

A collection of useful JavaScript utilities.

Features

  • Can be used with Node.js and in the browser
  • AMD compatible, you can load it via RequireJS
  • Lightweight
  • Fully documented
  • Tested

Example

Toolbox.getRandomNum(0, 100); // => 51
Toolbox.getRandomNums(0, 100, 3); // => [10, 54, 12]
Toolbox.getUid(); // => e80Ewq08td3QurK
Toolbox.detectMimeType('json'); // => application/json

Download

To install Toolbox, use NPM.

$ npm install toolbox

Releases are available for download from GitHub.

Version Description Size Action
toolbox.js uncompressed, with comments 18.49 KB (5.21 KB gzipped) Download
toolbox.min.js compressed, without comments 12.95 KB (4.19 KB gzipped) Download

Documentation

Methods

GetRandomNum

getRandomNum(min, max[, except])

Examples

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

GetRandomNums

getRandomNums(min, max, count[, except])

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]

GetUid

getUid(length[, resources])

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

GetAvg

getAvg(numbers)

Examples

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

GetMax

getMax(numbers)

Examples

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

GetMin

getMin(numbers)

Examples

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

GetSum

getMin(numbers)

Examples

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

DetectMimeType

detectMimeType(input)

Examples

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

RemoveDuplicates

removeDuplicates(input)

Examples

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

Shuffle

shuffle(input)

Examples

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

RgbToHex

rgbToHex(input)

Examples

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

HexToRgb

hexToRgb(input)

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.

Something went wrong with that request. Please try again.