toolbox
v0.1.1
Published
A collection of useful JavaScript utilities
Downloads
35
Readme
JavaScript Toolbox
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.49KB (5.21KB gzipped) | Download |
| toolbox.min.js
| compressed, without comments | 12.96KB (4.2KB gzipped) | Download |
Documentation
Methods
- getRandomNum
- getRandomNums
- getUid
- getAvg
- getMax
- getMin
- getSum
- detectMimeType
- removeDuplicates
- shuffle
- rgbToHex
- hexToRgb
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(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(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(numbers)
Examples
Toolbox.getAvg([1, 2, 3, 4, 5]); // => 2
getMax(numbers)
Examples
Toolbox.getMax([1, 2, 3, 4, 5]); // => 5
getMin(numbers)
Examples
Toolbox.getMin([1, 2, 3, 4, 5]); // => 1
getMin(numbers)
Examples
Toolbox.getSum([1, 2, 3, 4, 5]); // => 15
detectMimeType(input)
Examples
Toolbox.detectMimeType('json'); // => application/json
Toolbox.detectMimeType('application/json'); // => json
removeDuplicates(input)
Examples
Toolbox.removeDuplicates([1, 1, 2, 2, 3, 3, 4, 4, 5, 5]); // => [1, 2, 3, 4, 5]
shuffle(input)
Examples
Toolbox.shuffle([1, 2, 3, 4, 5]); // => [2, 1, 4, 3, 5]
rgbToHex(input)
Examples
Toolbox.rgbToHex([255, 255, 255]); // => #ffffff
hexToRgb(input)
Examples
Toolbox.hexToRgb('#ffffff'); // => [255, 255, 255]
Running Tests
$ npm tests/
License
(The MIT License)
Copyright (c) 2011 František Hába <[email protected]>
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.