Git Product home page Git Product logo

toolbox's Introduction

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

Examples

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

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

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

Examples

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

Examples

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

Examples

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

Examples

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

Examples

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

Examples

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

Examples

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

Examples

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

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.

toolbox's People

Stargazers

 avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.