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 1.1.2 to 1.2.0

doc/jsdoc.json

15

array.js

@@ -7,11 +7,12 @@ /**

/**
* remove an element from array, only once
* remove an element from array
* it removes only the first occurrence
* @method tools.array.remove
* @todo item=object, date, regexp ...
* @todo remove all item, not only first
* @todo remove all item, not only the first one
* @param {Array<*>} array
* @param {*} item
* @test.case ['js','ruby','python'], 'ruby' > &['js','python']
* @test.case [1,2,3], 2 > &[1,3]
* @test.case [1,2,3], 3 > &[1,2]
* @test.case ['js','ruby','python'], 1 > &['js','python']
*/

@@ -97,2 +98,4 @@ remove: function (array, item) {

* @return {boolean}
* @test.case [1,2,3], 1 > true
* @test.case [1,2,3], 4 > false
*/

@@ -153,5 +156,9 @@ contains: function (array, item) {

* @method tools.array.add
* @param {Array<*>} array
* @param {*} item
* @param {boolean} [unique=false]
* @test.case [0,1,2,3], 3, true > &[0,1,2,3]
*/
add: function (array, item, unique) {
if (unique && array.contains(array, item)) {
if (!!unique && array.contains(array, item)) {
return

@@ -158,0 +165,0 @@ }

@@ -12,2 +12,3 @@ ### fs

````js
tools.fs.exists('/tmp/file')

@@ -26,2 +27,3 @@ // > true

````js
tools.fs.touch('/tmp/touch-me')

@@ -33,3 +35,3 @@

- _path_ \<string\> file path
- _[safe=true]_ \<boolean\> safe do not throw exception
- _[safe=true]_ \<boolean\> if safe do not throw exception
- _return:_ Promise.\<void\>

@@ -42,2 +44,3 @@

````js
tools.fs.unlink('/tmp/file')

@@ -50,28 +53,187 @@

### util
### array
#### util.isSet()
#### array.remove(array, item)
- _array_ \<Array<*>\>
- _item_ \<*\>
- _return:_ bool
remove an element from array\nit removes only the first occurrence
check if ``val`` is setted, means it's not ``null`` or ``undefined``
_Example_
````js
let a = ['js','ruby','python']
tools.array.remove(a, 'ruby')
// > a = ['js','python']
````
#### array.removeAt(array, index)
- _array_ \<Array<*>\>
- _index_ \<number\>
remove an element from array at position
_Example_
````js
()
let a = [1,2,3]
tools.array.removeAt(a, 0)
// > a = [2,3]
````
#### array.last(array)
- _array_ \<Array<*>\>
- _return:_ * last element of the array or undefined
get last element of array or undefined
_Example_
````js
tools.array.last([1,2,3])
// > 3
````
#### util.onBrowser()
#### array.at(array)
- _array_ \<Array<*>\>
- _return:_ * nth element of array; if negative, start from end: -1 = last element; undefined if missing
- _return:_ bool
get nth element of array
check if you are on browser or not
_Example_
````js
tools.array.at([1,2,3], 0)
// > 1
````
#### array.first(array)
- _array_ \<Array<*>\>
- _return:_ * first element of the array or undefined
get first element of array or undefined
_Example_
````js
()
tools.array.first([1,2,3])
// > 1
````
#### array.contains(array, item)
- _array_ \<Array<*>\>
- _item_ \<*\>
- _return:_ boolean
check if array contains an element
_Example_
````js
tools.array.contains([1,2,3], 1)
// > true
````
#### array.insert(array, index, item)
- _array_ \<Array<*>\>
- _index_ \<number\>
- _item_ \<*\>
insert an item into array at index position
_Example_
````js
let a = ['john','alice','bob']
tools.array.insert(a, 0, 'mary')
// > a = ['mary', 'john', 'alice', 'bob']
````
#### array.concat(arrays)
- _arrays_ \<...Array<*>\> to chain
- _return:_ Array\<*\> chained arrays
concat arrays
_Example_
````js
tools.array.concat([0,1,2],[3,4,5])
// > [0,1,2,3,4,5]
````
#### array.empty()
empty array - need to keep references
_Example_
````js
let a = [0,1,2]
tools.array.empty(a)
// > a = []
````
#### array.add(array, item, [unique=false])
- _array_ \<Array<*>\>
- _item_ \<*\>
- _[unique=false]_ \<boolean\>
push item into array, optionally check if already exists
_Example_
````js
let a = [0,1,2,3]
tools.array.add(a, 3, true)
// > a = [0,1,2,3]
````
---
### hash
#### hash.sha256(data)
- _data_ \<string\> any string
- _return:_ string sha256 in hex format
Generate hash using sha256 in hex format
_Example_
````js
tools.hash.sha256('usk6fgbuygbu6')
// > 'ee42f619919727584b66fe25248ed4bba8e87dcfb3e62a90143ea17ba48df58e'
````
---
### util
#### util.isSet(val)
- _val_ \<*\>
- _return:_ bool
check if ``val`` is setted, means it's not ``null`` or ``undefined``
#### util.onBrowser()
- _return:_ bool
check if you are on browser or not

@@ -1,2 +0,2 @@

const crypto = require('crypto')
const lib = require('hash.js')

@@ -10,8 +10,8 @@ /**

* @method tools.hash.sha256
* @param {String} data any string
* @return {String} sha256 in hex format
* @param {string} data any string
* @return {string} sha256 in hex format
*
* @test
* @test.case
* 'usk6fgbuygbu6' > 'ee42f619919727584b66fe25248ed4bba8e87dcfb3e62a90143ea17ba48df58e'
* @test
* @test.case
* 'lorem ipsum %1283770tv8gv 6c6fgw ucthv iy'

@@ -21,3 +21,3 @@ * > '18d18c26ed98c0e88d9121132be48f42596e899ac50f15f854c9d0a82b9f2cb5'

sha256: function (data) {
return crypto.createHash('sha256')
return lib.sha256()
.update(data)

@@ -24,0 +24,0 @@ .digest('hex')

@@ -174,3 +174,3 @@ /**

* @param {Object} obj
* @param {String} fkey
* @param {string} fkey
* @return {Object}

@@ -196,3 +196,3 @@ * @test.case { a: { b: {c: 1} } }, 'a.b.c' > 1

* @param {Object} obj
* @param {String} fkey
* @param {string} fkey
* @param {*} val

@@ -199,0 +199,0 @@ * @test.case

{
"name": "a-toolbox",
"version": "1.1.2",
"description": "javascript lightweight basic tools, zero dependecies, isomorphic",
"version": "1.2.0",
"description": "javascript lightweight basic tools, isomorphic",
"main": "index.js",

@@ -32,3 +32,3 @@ "devDependencies": {

"doxdox": "mkdir -p doc/doxdox; doxdox './src/*.js' --layout markdown --output ./doc/README.md",
"jsdoc": "jsdoc -c jsdoc.json -t ./node_modules/ink-docstrap/template -R README.md src/*.js"
"jsdoc": "jsdoc -c doc/jsdoc.json -t ./node_modules/ink-docstrap/template -R README.md src/*.js"
},

@@ -43,6 +43,22 @@ "standard": {

"type": "git",
"url": "git+https://simone-sanfratello@github.com/simone-sanfratello/a-toolbox.git"
"url": "git+https://github.com/braceslab/a-toolbox.git"
},
"author": "Simone Sanfratello <simone@braceslab.com>",
"license": "MIT"
"license": "MIT",
"keywords": [
"library",
"toolkit",
"toolbox",
"array",
"fs",
"object",
"hash",
"task",
"async",
"random",
"string"
],
"dependencies": {
"hash.js": "^1.1.3"
}
}

@@ -39,3 +39,3 @@ const hash = require('./hash')

* @param {Array} [set=abcdefghijklmnopqrstuvwxyz]
* @return {String}
* @return {string}
*/

@@ -53,3 +53,3 @@ string: function (length = 8, set = 'abcdefghijklmnopqrstuvwxyz') {

* @param {number} [length=8]
* @return {String}
* @return {string}
*/

@@ -63,3 +63,3 @@ hex: function (length = 8) {

* @param {?string} salt
* @return {String}
* @return {string}
*/

@@ -66,0 +66,0 @@ hash: function (salt = '') {

@@ -8,3 +8,3 @@ # a-toolbox

javascript lightweight basic tools, zero dependecies, isomorphic
javascript lightweight basic tools, isomorphic

@@ -24,3 +24,3 @@ ## Purpose

```js
const tools = require('a-toolbox');
const tools = require('a-toolbox')

@@ -32,2 +32,12 @@ tools.string.trim('({cut these brackets please)}', ['{', '}', '(', ')'])

modular import
```js
const tools = {
string: require('a-toolbox/string'),
fs: require('a-toolbox/fs')
}
```
### On browser

@@ -58,2 +68,3 @@

- [hash](#hash)
- [util](#util)
- [object](#object)

@@ -65,10 +76,4 @@ - [random](#random)

- [time](#time)
- [util](#util)
### array
todo
### fs
note: not available on browser

@@ -84,2 +89,3 @@ #### fs.exists(path)

````js
tools.fs.exists('/tmp/file')

@@ -98,2 +104,3 @@ // > true

````js
tools.fs.touch('/tmp/touch-me')

@@ -105,3 +112,3 @@

- _path_ \<string\> file path
- _[safe=true]_ \<boolean\> safe do not throw exception
- _[safe=true]_ \<boolean\> if safe do not throw exception
- _return:_ Promise.\<void\>

@@ -114,2 +121,3 @@

````js
tools.fs.unlink('/tmp/file')

@@ -119,34 +127,180 @@

### hash
todo
---
### object
### array
todo
#### array.remove(array, item)
- _array_ \<Array<*>\>
- _item_ \<*\>
### random
remove an element from array\nit removes only the first occurrence
todo
_Example_
### string
````js
let a = ['js','ruby','python']
tools.array.remove(a, 'ruby')
// > a = ['js','python']
````
todo
#### array.removeAt(array, index)
- _array_ \<Array<*>\>
- _index_ \<number\>
### sys
note: not available on browser
remove an element from array at position
todo
_Example_
### task
````js
let a = [1,2,3]
tools.array.removeAt(a, 0)
// > a = [2,3]
````
todo
#### array.last(array)
- _array_ \<Array<*>\>
- _return:_ * last element of the array or undefined
### time
todo
get last element of array or undefined
_Example_
````js
tools.array.last([1,2,3])
// > 3
````
#### array.at(array)
- _array_ \<Array<*>\>
- _return:_ * nth element of array; if negative, start from end: -1 = last element; undefined if missing
get nth element of array
_Example_
````js
tools.array.at([1,2,3], 0)
// > 1
````
#### array.first(array)
- _array_ \<Array<*>\>
- _return:_ * first element of the array or undefined
get first element of array or undefined
_Example_
````js
tools.array.first([1,2,3])
// > 1
````
#### array.contains(array, item)
- _array_ \<Array<*>\>
- _item_ \<*\>
- _return:_ boolean
check if array contains an element
_Example_
````js
tools.array.contains([1,2,3], 1)
// > true
````
#### array.insert(array, index, item)
- _array_ \<Array<*>\>
- _index_ \<number\>
- _item_ \<*\>
insert an item into array at index position
_Example_
````js
let a = ['john','alice','bob']
tools.array.insert(a, 0, 'mary')
// > a = ['mary', 'john', 'alice', 'bob']
````
#### array.concat(arrays)
- _arrays_ \<...Array<*>\> to chain
- _return:_ Array\<*\> chained arrays
concat arrays
_Example_
````js
tools.array.concat([0,1,2],[3,4,5])
// > [0,1,2,3,4,5]
````
#### array.empty()
empty array - need to keep references
_Example_
````js
let a = [0,1,2]
tools.array.empty(a)
// > a = []
````
#### array.add(array, item, [unique=false])
- _array_ \<Array<*>\>
- _item_ \<*\>
- _[unique=false]_ \<boolean\>
push item into array, optionally check if already exists
_Example_
````js
let a = [0,1,2,3]
tools.array.add(a, 3, true)
// > a = [0,1,2,3]
````
---
### hash
#### hash.sha256(data)
- _data_ \<string\> any string
- _return:_ string sha256 in hex format
Generate hash using sha256 in hex format
_Example_
````js
tools.hash.sha256('usk6fgbuygbu6')
// > 'ee42f619919727584b66fe25248ed4bba8e87dcfb3e62a90143ea17ba48df58e'
````
---
### util
#### util.isSet()
#### util.isSet(val)
- _val_ \<*\>
- _return:_ bool

@@ -156,2 +310,3 @@

#### util.onBrowser()

@@ -167,2 +322,6 @@

v. 1.2.0
- use [hash.js](https://github.com/indutny/hash.js) instead of ``crypto``
v. 1.0.0

@@ -169,0 +328,0 @@

@@ -7,11 +7,12 @@ /**

/**
* remove an element from array, only once
* remove an element from array
* it removes only the first occurrence
* @method tools.array.remove
* @todo item=object, date, regexp ...
* @todo remove all item, not only first
* @todo remove all item, not only the first one
* @param {Array<*>} array
* @param {*} item
* @test.case ['js','ruby','python'], 'ruby' > &['js','python']
* @test.case [1,2,3], 2 > &[1,3]
* @test.case [1,2,3], 3 > &[1,2]
* @test.case ['js','ruby','python'], 1 > &['js','python']
*/

@@ -97,2 +98,4 @@ remove: function (array, item) {

* @return {boolean}
* @test.case [1,2,3], 1 > true
* @test.case [1,2,3], 4 > false
*/

@@ -153,5 +156,9 @@ contains: function (array, item) {

* @method tools.array.add
* @param {Array<*>} array
* @param {*} item
* @param {boolean} [unique=false]
* @test.case [0,1,2,3], 3, true > &[0,1,2,3]
*/
add: function (array, item, unique) {
if (unique && array.contains(array, item)) {
if (!!unique && array.contains(array, item)) {
return

@@ -158,0 +165,0 @@ }

@@ -1,2 +0,2 @@

const crypto = require('crypto')
const lib = require('hash.js')

@@ -10,8 +10,8 @@ /**

* @method tools.hash.sha256
* @param {String} data any string
* @return {String} sha256 in hex format
* @param {string} data any string
* @return {string} sha256 in hex format
*
* @test
* @test.case
* 'usk6fgbuygbu6' > 'ee42f619919727584b66fe25248ed4bba8e87dcfb3e62a90143ea17ba48df58e'
* @test
* @test.case
* 'lorem ipsum %1283770tv8gv 6c6fgw ucthv iy'

@@ -21,3 +21,3 @@ * > '18d18c26ed98c0e88d9121132be48f42596e899ac50f15f854c9d0a82b9f2cb5'

sha256: function (data) {
return crypto.createHash('sha256')
return lib.sha256()
.update(data)

@@ -24,0 +24,0 @@ .digest('hex')

@@ -174,3 +174,3 @@ /**

* @param {Object} obj
* @param {String} fkey
* @param {string} fkey
* @return {Object}

@@ -196,3 +196,3 @@ * @test.case { a: { b: {c: 1} } }, 'a.b.c' > 1

* @param {Object} obj
* @param {String} fkey
* @param {string} fkey
* @param {*} val

@@ -199,0 +199,0 @@ * @test.case

@@ -39,3 +39,3 @@ const hash = require('./hash')

* @param {Array} [set=abcdefghijklmnopqrstuvwxyz]
* @return {String}
* @return {string}
*/

@@ -53,3 +53,3 @@ string: function (length = 8, set = 'abcdefghijklmnopqrstuvwxyz') {

* @param {number} [length=8]
* @return {String}
* @return {string}
*/

@@ -63,3 +63,3 @@ hex: function (length = 8) {

* @param {?string} salt
* @return {String}
* @return {string}
*/

@@ -66,0 +66,0 @@ hash: function (salt = '') {

@@ -9,6 +9,6 @@ /**

* @method tools.string.template
* @param {String} str
* @param {string} str
* @param {Object} obj
* @param {boolean} [remove=false] missing placeholders from obj, default false
* @return {String}
* @return {string}
*

@@ -35,5 +35,5 @@ * @test.case 'hi {name} how are you?', {name: 'Alice'} > 'hi Alice how are you?'

* @method tools.string.trim
* @param {String} str
* @param {string} str
* @param {?string[]} cuts
* @return {String}
* @return {string}
*

@@ -61,6 +61,6 @@ * @test.case ' regular trim ' > 'regular trim'

* @method tools.string.replaceAll
* @param {String} str
* @param {String} from
* @param {String} to
* @return {String}
* @param {string} str
* @param {string} from
* @param {string} to
* @return {string}
* @test.case 'abcadaeafaga', 'a', '' > 'bcdefg'

@@ -78,4 +78,4 @@ * @test.case '112233445544', '4', '9' > '112233995599'

* @method tools.string.capitalize
* @param {String} str
* @return {String}
* @param {string} str
* @return {string}
* @test.case 'alice' > 'Alice'

@@ -91,5 +91,5 @@ * @test.case 'alice smith' > 'Alice smith'

* @method tools.string.prependMissing
* @param {String} prefix
* @param {String} str
* @return {String}
* @param {string} prefix
* @param {string} str
* @return {string}
* @test.case 'miss ', 'Alice' > 'miss Alice'

@@ -107,3 +107,3 @@ * @test.case 'miss ', 'miss Alice' > 'miss Alice'

* @method tools.string.matchAll
* @param {String} str
* @param {string} str
* @param {RegExp} regexp

@@ -110,0 +110,0 @@ * @return {String[]}

@@ -14,3 +14,3 @@ const object = require('./object')

* @method tools.time.chrono.set
* @param {String} [tag=chrono]
* @param {string} [tag=chrono]
*/

@@ -26,3 +26,3 @@ set: function (tag = 'chrono') {

* @method tools.time.chrono.reset
* @param {String} [tag=chrono]
* @param {string} [tag=chrono]
*/

@@ -34,3 +34,3 @@ reset: function (tag = 'chrono') {

* @method tools.time.chrono.clear
* @param {String} [tag=chrono]
* @param {string} [tag=chrono]
*/

@@ -42,3 +42,3 @@ clear: function (tag = 'chrono') {

* @method tools.time.chrono.get
* @param {String} [tag=chrono]
* @param {string} [tag=chrono]
* @return {number} ms

@@ -45,0 +45,0 @@ */

@@ -9,6 +9,6 @@ /**

* @method tools.string.template
* @param {String} str
* @param {string} str
* @param {Object} obj
* @param {boolean} [remove=false] missing placeholders from obj, default false
* @return {String}
* @return {string}
*

@@ -35,5 +35,5 @@ * @test.case 'hi {name} how are you?', {name: 'Alice'} > 'hi Alice how are you?'

* @method tools.string.trim
* @param {String} str
* @param {string} str
* @param {?string[]} cuts
* @return {String}
* @return {string}
*

@@ -61,6 +61,6 @@ * @test.case ' regular trim ' > 'regular trim'

* @method tools.string.replaceAll
* @param {String} str
* @param {String} from
* @param {String} to
* @return {String}
* @param {string} str
* @param {string} from
* @param {string} to
* @return {string}
* @test.case 'abcadaeafaga', 'a', '' > 'bcdefg'

@@ -78,4 +78,4 @@ * @test.case '112233445544', '4', '9' > '112233995599'

* @method tools.string.capitalize
* @param {String} str
* @return {String}
* @param {string} str
* @return {string}
* @test.case 'alice' > 'Alice'

@@ -91,5 +91,5 @@ * @test.case 'alice smith' > 'Alice smith'

* @method tools.string.prependMissing
* @param {String} prefix
* @param {String} str
* @return {String}
* @param {string} prefix
* @param {string} str
* @return {string}
* @test.case 'miss ', 'Alice' > 'miss Alice'

@@ -107,3 +107,3 @@ * @test.case 'miss ', 'miss Alice' > 'miss Alice'

* @method tools.string.matchAll
* @param {String} str
* @param {string} str
* @param {RegExp} regexp

@@ -110,0 +110,0 @@ * @return {String[]}

@@ -14,3 +14,3 @@ const object = require('./object')

* @method tools.time.chrono.set
* @param {String} [tag=chrono]
* @param {string} [tag=chrono]
*/

@@ -26,3 +26,3 @@ set: function (tag = 'chrono') {

* @method tools.time.chrono.reset
* @param {String} [tag=chrono]
* @param {string} [tag=chrono]
*/

@@ -34,3 +34,3 @@ reset: function (tag = 'chrono') {

* @method tools.time.chrono.clear
* @param {String} [tag=chrono]
* @param {string} [tag=chrono]
*/

@@ -42,3 +42,3 @@ clear: function (tag = 'chrono') {

* @method tools.time.chrono.get
* @param {String} [tag=chrono]
* @param {string} [tag=chrono]
* @return {number} ms

@@ -45,0 +45,0 @@ */

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

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