Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

a-toolbox

Package Overview
Dependencies
Maintainers
1
Versions
64
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

a-toolbox - npm Package Compare versions

Comparing version 0.0.11 to 0.0.12

184

main.js

@@ -13,3 +13,4 @@ var tools = {

var _index = array.indexOf(item)
if (_index !== -1) array.splice(_index, 1)
if (_index !== -1)
array.splice(_index, 1)
},

@@ -33,6 +34,6 @@ /**

/**
* get first element of array or null
* @param {Array} array
* @returns {*} last element of the array or null
*/
* get first element of array or null
* @param {Array} array
* @returns {*} last element of the array or null
*/
first: function (array) {

@@ -42,7 +43,7 @@ return array[0]

/**
* check if array contains an element
* @param {Array} array
* @param {*} item
* @returns {Boolean}
*/
* check if array contains an element
* @param {Array} array
* @param {*} item
* @returns {Boolean}
*/
contains: function (array, item) {

@@ -52,7 +53,7 @@ return array.indexOf(item) !== -1

/**
* insert an item into array at index position
* @param {Array} array
* @param {number} index
* @param {*} item
*/
* insert an item into array at index position
* @param {Array} array
* @param {number} index
* @param {*} item
*/
insert: function (array, index, item) {

@@ -70,7 +71,7 @@ if (index > array.length) {

/**
* get random element from array
* @param {Array} array
* @param {*} not
* @returns {*} element
*/
* get random element from array
* @param {Array} array
* @param {*} not
* @returns {*} element
*/
randomElement: function (array, not) {

@@ -101,3 +102,4 @@ if (!not) {

empty: function (array) {
while (array[0]) array.pop()
while (array[0])
array.pop()
}

@@ -115,3 +117,4 @@ },

rnd: function (val) {
if (!val) return 0
if (!val)
return 0
return Math.floor(val * (Math.random() % 1))

@@ -126,3 +129,4 @@ },

number: function (min, max) {
if (!max) return tools.random.rnd(min)
if (!max)
return tools.random.rnd(min)
min = Math.floor(min)

@@ -139,4 +143,6 @@ max = Math.floor(max)

string: function (length, set) {
if (!length) length = 8
if (!set) set = 'qwertyuiopasdfghjklzxcvbnm'
if (!length)
length = 8
if (!set)
set = 'qwertyuiopasdfghjklzxcvbnm'
var _str = ''

@@ -147,2 +153,7 @@ for (var i = 0; i < length; i++) {

return _str
},
hex: function (length) {
if (!length)
length = 8
return tools.random.string(length, '0123456789abcdef')
}

@@ -167,2 +178,31 @@ },

/**
* Clone an array or an object in input
* @function
* @param {Object|Array} obj The array or the object to clone
* @returns {Object|Array}
*/
clone: function (obj) {
if (obj === null || obj === undefined)
return obj
var _type = (obj instanceof Array) ? _type = 'array' : typeof obj
if (_type === 'object' || _type === 'array') {
if (obj instanceof Date) {
return new Date(obj.getTime())
} else if (typeof window !== 'undefined' && (obj instanceof File || obj instanceof Blob)) {
return obj
} else {
if (obj.clone)
return obj.clone()
/**
* @type {Array|Object}
*/
var _clone = _type === 'array' ? [] : {}
for (var key in obj)
_clone[key] = tools.object.clone(obj[key])
return _clone
}
}
return obj
},
/**
* @see http://google.github.io/closure-library/api/source/closure/goog/object/object.js.src.html#l225

@@ -187,3 +227,3 @@ * @param {object} obj

var _obj = {}
for(var i = 0; i < _keys.length; i++)
for (var i = 0; i < _keys.length; i++)
_obj[_keys[i]] = obj[_keys[i]]

@@ -198,4 +238,8 @@ return _obj

*/
Tasks: function (done) {
Tasks: function (done, options) {
var __tasks = []
var __chronos = {}
if (!options)
options = {}
return {

@@ -207,2 +251,6 @@ /**

todo: function (id) {
if (options.chrono) {
__chronos[id] = new tools.time.Chrono(id)
__chronos[id].check()
}
__tasks.push(id)

@@ -216,5 +264,8 @@ },

tools.array.remove(__tasks, id)
if(__tasks.length < 1) {
if (__tasks.length < 1) {
done && done()
}
if (options.chrono) {
return {chrono: __chronos[id].check()}
}
}

@@ -258,5 +309,78 @@ }

}
},
time: {
Chrono: function (tag) {
if (!tag)
tag = 'chrono'
var __tick
var __time
/**
* return milliseconds from the last checkpoint
* @function
* @returns {string}
*/
return {
check: function () {
if (!__tick) {
__tick = new Date()
return 0
}
/**
* @type {number}
*/
__time = (new Date()).getTime() - __tick.getTime()
__tick = new Date()
return __time
},
time: function () {
__time
}
}
}
},
console: {
/**
*
* @param {object} options
* @param {number} [options.tick=10] millisec
* @param {object} [options.spinner=['. ', '.. ', '... ', '.... ', '.....']]
*/
Wait: function (options) {
if (!options)
options = {}
var __wait = null
var __timer = 0
var __tick = options.tick || 100
var __spin = options.spinner || ['. ', '.. ', '... ', '.... ', '.....']
var __spinner = 0
var start = function () {
if (__wait)
return
__timer = 0
__spinner = 0
__wait = setInterval(function () {
if (!__wait)
return
process.stdout.write(__spin[__spinner % __spin.length] + ' ' + (__timer / 1000).toFixed(2) + ' sec \r')
__timer += __tick
__spinner++
}, __tick)
}
var end = function () {
clearInterval(__wait)
__wait = null
}
return {
start: start,
end: end
}
}
}
}
// compatibilty < 0.0.10 - to remove

@@ -266,2 +390,3 @@ tools.tasks = tools.Tasks

String.prototype.replaceAll = function (from, to) {
console.warn('String.replaceAll is deprecated, please use tools.string.replaceAll')
return tools.string.replaceAll(this, from, to)

@@ -271,2 +396,3 @@ }

String.prototype.capitalize = function () {
console.warn('String.capitalize is deprecated, please use tools.string.capitalize')
return tools.string.capitalize(this)

@@ -273,0 +399,0 @@ }

4

package.json
{
"name": "a-toolbox",
"version": "0.0.11",
"version": "0.0.12",
"description": "lightweight tools",

@@ -33,2 +33,2 @@ "keywords": [

"main": "main"
}
}

@@ -132,7 +132,7 @@ # a-toolbox

#### replaceAll in String prototype
#### string replaceAll
```js
console.log("no replace all in js native code that replace all the replace".replaceAll(' ', '_'));
console.log(tools.string.replaceAll("no replace all in js native code that replace all the replace", ' ', '_'));

@@ -253,3 +253,3 @@ //> no_replace_all_in_js_native_code_that_replace_all_the_replace

Copyright (c) 2015 Simone Sanfratello
Copyright (c) 2015-2016 Simone Sanfratello

@@ -256,0 +256,0 @@ Permission is hereby granted, free of charge, to any person obtaining a copy

@@ -6,3 +6,3 @@ // var tools = require('./main')

console.log('no replace all in js native code that replace all the replace'.replaceAll(' ', '_'))
console.log(tools.string.replaceAll("no replace all in js native code that replace all the replace", ' ', '_'));

@@ -9,0 +9,0 @@ // > no_replace_all_in_js_native_code_that_replace_all_the_replace

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc