Comparing version 0.0.3 to 0.0.4
85
main.js
@@ -14,6 +14,6 @@ | ||
* @param {Array} array | ||
* @param {*} value | ||
* @param {*} item | ||
*/ | ||
remove: function (array, value) { | ||
var _index = array.indexOf(value); | ||
remove: function (array, item) { | ||
var _index = array.indexOf(item); | ||
if (_index != -1) | ||
@@ -31,9 +31,33 @@ array.splice(_index, 1); | ||
/** | ||
* get last element of array or null | ||
* @param {Array} array | ||
* @returns {*} last element of the array or null | ||
*/ | ||
last: function (array) { | ||
return array[array.length - 1] || null; | ||
}, | ||
/** | ||
* get first element of array or null | ||
* @param {Array} array | ||
* @returns {*} last element of the array or null | ||
*/ | ||
first: function (array) { | ||
return array[0]; | ||
}, | ||
/** | ||
* get length of the array | ||
* @param {Array} array | ||
* @returns {number} | ||
*/ | ||
count: function (array) { | ||
return array.length; | ||
}, | ||
/** | ||
* check if array contains an element | ||
* @param {Array} array | ||
* @param {*} value | ||
* @param {*} item | ||
* @returns {Boolean} | ||
*/ | ||
contains: function (array, value) { | ||
return array.indexOf(value) != -1; | ||
contains: function (array, item) { | ||
return array.indexOf(item) != -1; | ||
}, | ||
@@ -60,3 +84,3 @@ /** | ||
if (!not) | ||
return array[tools.math.random(0, array.length - 1)]; | ||
return array[tools.random.number(0, array.length - 1)]; | ||
else { | ||
@@ -81,12 +105,12 @@ var _item, i = 0; | ||
/** | ||
* math (?) utils | ||
* random utils | ||
*/ | ||
math: { | ||
random: { | ||
/** | ||
* return random int from 0 to val | ||
* @param {number} val max value | ||
* get random int from 0 to val | ||
* @param {number} val max item | ||
* @returns {number} | ||
*/ | ||
rnd: function (val) { | ||
if(!val) | ||
if (!val) | ||
return 0; | ||
@@ -96,3 +120,3 @@ return Math.floor(val * (Math.random() % 1)); | ||
/** | ||
* return random int from min to max | ||
* get random int from min to max | ||
* @param {number} min | ||
@@ -102,11 +126,35 @@ * @param {number} max | ||
*/ | ||
random: function (min, max) { | ||
number: function (min, max) { | ||
if (!max) | ||
return tools.math.rnd(min); | ||
return tools.random.rnd(min); | ||
min = Math.floor(min); | ||
max = Math.floor(max); | ||
return min + tools.math.rnd(1 + max - min); | ||
return min + tools.random.rnd(1 + max - min); | ||
}, | ||
/** | ||
* get random string | ||
* @param {number} [length=8] | ||
* @param {Array} [set=qwertyuiopasdfghjklzxcvbnm] | ||
* @returns {String} | ||
*/ | ||
string: function (length, set) { | ||
if(!length) | ||
lenght = 8; | ||
if(!set) | ||
set = 'qwertyuiopasdfghjklzxcvbnm'; | ||
var _str = ''; | ||
for(var i = 0; i < length; i++) | ||
_str += tools.array.randomElement(set); | ||
return _str; | ||
} | ||
}, | ||
object: { | ||
// merge obj2 into obj1 | ||
merge: function(obj1, obj2) { | ||
for(var i in obj2) { | ||
obj1[i] = obj2[i]; | ||
} | ||
} | ||
}, | ||
/** | ||
@@ -138,2 +186,5 @@ * tasks (promises) async manage | ||
if (typeof window == 'undefined') | ||
module.exports = tools; | ||
module.exports = tools; | ||
{ | ||
"name": "a-toolbox", | ||
"version": "0.0.3", | ||
"version": "0.0.4", | ||
"description": "lightweight tools", | ||
@@ -5,0 +5,0 @@ "keywords": ["tools", "lib", "misc", "toolbox", "array", "task", "random"], |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
9786
4
177