Comparing version 0.0.5 to 0.0.6
24
main.js
@@ -46,10 +46,2 @@ | ||
/** | ||
* get length of the array | ||
* @param {Array} array | ||
* @returns {number} | ||
*/ | ||
count: function (array) { | ||
return array.length; | ||
}, | ||
/** | ||
* check if array contains an element | ||
@@ -70,2 +62,5 @@ * @param {Array} array | ||
insert: function (array, index, item) { | ||
if(index > array.length) | ||
index = array.length; | ||
if (array[index]) | ||
@@ -101,2 +96,9 @@ array.splice(index, 0, item); | ||
return Array.prototype.concat.apply(Array.prototype, arguments); | ||
}, | ||
/** | ||
* empty - need to not break references | ||
*/ | ||
empty: function (array) { | ||
while(array[0]) | ||
array.pop(); | ||
} | ||
@@ -150,3 +152,7 @@ }, | ||
object: { | ||
// merge obj2 into obj1 | ||
/** | ||
* merge obj2 into obj1 | ||
* @param {object} obj1 | ||
* @param {object} obj2 | ||
*/ | ||
merge: function(obj1, obj2) { | ||
@@ -153,0 +159,0 @@ for(var i in obj2) { |
{ | ||
"name": "a-toolbox", | ||
"version": "0.0.5", | ||
"version": "0.0.6", | ||
"description": "lightweight tools", | ||
@@ -5,0 +5,0 @@ "keywords": ["tools", "lib", "misc", "toolbox", "array", "task", "random"], |
133
README.md
@@ -31,2 +31,4 @@ # a-toolbox | ||
## Tools | ||
#### tasks (promises) async manage | ||
@@ -64,6 +66,39 @@ | ||
#### add replaceAll in String prototype | ||
#### object merge | ||
```js | ||
var _merge = {a: 1, b: 2}; | ||
console.log('to merge', _merge); | ||
tools.object.merge(_merge, {a: 4, c: { d: 8, e: 9}}); | ||
console.log('merged', _merge); | ||
//>to merge { a: 1, b: 2 } | ||
//>merged { a: 4, b: 2, c: { d: 8, e: 9 } } | ||
``` | ||
#### random | ||
```js | ||
console.log('random number from 1 to 100:', tools.random.number(1, 100)); | ||
//>random number from 1 to 100: 14 | ||
console.log('random string of 8 chars, default set:', tools.random.string(8)); | ||
//>random string of 8 chars, default set: dcglhcvr | ||
var _hex = '0123456789abcdef'; | ||
console.log('random string of 16 chars, custom set (hex)', _hex, ':', tools.random.string(16, _hex)); | ||
//>random string of 16 chars, custom set (hex) 0123456789abcdef : b4a61c1af5360fd4 | ||
``` | ||
#### replaceAll in String prototype | ||
```js | ||
console.log("no replace all in js native code that replace all the replace".replaceAll(' ', '_')); | ||
@@ -75,3 +110,3 @@ | ||
#### array function management, inspired to goog.array (to be continued) | ||
#### array remove | ||
@@ -89,2 +124,95 @@ ```js | ||
#### array removeAt | ||
```js | ||
tools.array.removeAt(_array, 4); | ||
console.log(_array); | ||
//>[ 'remove', 'elements', 'in', 'arrays' ] | ||
``` | ||
#### array first and last | ||
```js | ||
console.log('last element is', tools.array.last(_array)); | ||
//>last element is js | ||
console.log('first element is', tools.array.first(_array)); | ||
//>first element is remove | ||
``` | ||
#### array contains | ||
```js | ||
console.log('contains js?', tools.array.contains(_array, 'js')); | ||
//>contains js? true | ||
console.log('contains ruby?', tools.array.contains(_array, 'ruby')); | ||
//>contains ruby? false | ||
``` | ||
#### array insert | ||
```js | ||
tools.array.insert(_array, 0, 'something'); | ||
console.log('inserted something', _array); | ||
//>inserted something [ 'something', 'remove', 'elements', 'in', 'js' ] | ||
``` | ||
#### array get random element | ||
```js | ||
console.log('get random element:', tools.array.randomElement(_array)); | ||
//>get random element element: in | ||
``` | ||
#### array concat | ||
```js | ||
console.log('concat more arrays', tools.array.concat(_array, [0,1,2,3], ['a','b','c'])); | ||
//>concat more arrays [ 'something', | ||
//> 'remove', | ||
//> 'elements', | ||
//> 'in', | ||
//> 'js', | ||
//> 0, | ||
//> 1, | ||
//> 2, | ||
//> 3, | ||
//> 'a', | ||
//> 'b', | ||
//> 'c' ] | ||
``` | ||
#### array empty | ||
When you need to keep references | ||
```js | ||
tools.array.empty(_array); | ||
console.log('empty it', _array); | ||
//>empty it [] | ||
``` | ||
## License | ||
@@ -113,1 +241,2 @@ | ||
SOFTWARE. | ||
12127
186
238