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.2.6 to 1.2.7

4

dist/atoolbox.min.js

@@ -1256,3 +1256,3 @@ (function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s})({1:[function(require,module,exports){

},{"hash.js":1}],18:[function(require,module,exports){
'use strict';var _typeof=typeof Symbol==='function'&&typeof Symbol.iterator==='symbol'?function(obj){return typeof obj}:function(obj){return obj&&typeof Symbol==='function'&&obj.constructor===Symbol&&obj!==Symbol.prototype?'symbol':typeof obj};var object={flat:function flat(obj){var _obj={};return object._rflat(obj,'',_obj)},_rflat:function _rflat(obj,base,flat){for(var key in obj){try{if(obj[key].constructor==Object){object._rflat(obj[key],base+key+'.',flat)}else{flat[base+key]=obj[key]}}catch(e){flat[base+key]=obj[key]}}},merge:function merge(a,b){if(!a){a=b||{};return}if(!b){return a}for(var i in b){if(_typeof(b[i])==='object'){if(b[i]instanceof Array){a[i]=object.clone(b[i]);continue}if(!a[i]||_typeof(a[i])!=='object'){a[i]={}}object.merge(a[i],b[i])}else{a[i]=b[i]}}},clone:function clone(obj){if(obj===null||obj===undefined){return obj}var _type=obj instanceof Array?'array':typeof obj==='undefined'?'undefined':_typeof(obj);if(_type==='object'||_type==='array'){if(obj instanceof Date){return new Date(obj.getTime())}else if(typeof window!=='undefined'){return obj}else{if(obj.clone){return obj.clone()}var _clone=_type==='array'?[]:{};for(var key in obj){_clone[key]=object.clone(obj[key])}return _clone}}return obj},getKeys:function getKeys(obj){if(Object.keys){return Object.keys(obj)}var _keys=[];for(var key in obj){_keys.push(key)}return _keys},inherits:function inherits(destination,source){Object.getOwnPropertyNames(source).forEach(function(property){destination[property]=source[property]})},empty:function empty(obj){for(var i in obj){delete obj[i]}},raise:function raise(obj){var _raise={};var _f=function _f(flat,raise){var _loop=function _loop(path){var _keys=path.split('.');var _cursor=raise;_keys.forEach(function(key,i){if(i<_keys.length-1){if(!_cursor[key]){_cursor[key]={}}_cursor=_cursor[key]}else{_cursor[key]=flat[path]}})};for(var path in flat){_loop(path)}};_f(obj,_raise);return _raise},getByFlatKey:function getByFlatKey(obj,fkey){var _path=fkey.split('.');var _walk=obj;for(var i=0;i<_path.length;i++){if(!_walk[_path[i]]){return undefined}_walk=_walk[_path[i]]}return _walk},setByFlatKey:function setByFlatKey(obj,fkey,val){var _path=fkey.split('.');var _walk=obj;for(var i=0;i<_path.length;i++){if(!_walk[_path[i]]){if(i===_path.length-1){_walk[_path[i]]=undefined;return}_walk[_path[i]]={}}_walk=_walk[_path[i]]}_walk=val}};module.exports=object;
'use strict';var _typeof=typeof Symbol==='function'&&typeof Symbol.iterator==='symbol'?function(obj){return typeof obj}:function(obj){return obj&&typeof Symbol==='function'&&obj.constructor===Symbol&&obj!==Symbol.prototype?'symbol':typeof obj};var object={flat:function flat(obj){var _flat={};object._rflat(obj,'',_flat);return _flat},_rflat:function _rflat(obj,base,flat){for(var key in obj){try{if(obj[key].constructor==Object){object._rflat(obj[key],base+key+'.',flat)}else{flat[base+key]=obj[key]}}catch(e){flat[base+key]=obj[key]}}},merge:function merge(a,b){if(!a){a=b||{};return}if(!b){return a}for(var i in b){if(_typeof(b[i])==='object'){if(b[i]instanceof Array){a[i]=object.clone(b[i]);continue}if(!a[i]||_typeof(a[i])!=='object'){a[i]={}}object.merge(a[i],b[i])}else{a[i]=b[i]}}},clone:function clone(obj){if(obj===null||obj===undefined){return obj}var _type=obj instanceof Array?'array':typeof obj==='undefined'?'undefined':_typeof(obj);if(_type==='object'||_type==='array'){if(obj instanceof Date){return new Date(obj.getTime())}else if(typeof window!=='undefined'){return obj}else{if(obj.clone){return obj.clone()}var _clone=_type==='array'?[]:{};for(var key in obj){_clone[key]=object.clone(obj[key])}return _clone}}return obj},getKeys:function getKeys(obj){if(Object.keys){return Object.keys(obj)}var _keys=[];for(var key in obj){_keys.push(key)}return _keys},inherits:function inherits(destination,source){Object.getOwnPropertyNames(source).forEach(function(property){destination[property]=source[property]})},empty:function empty(obj){for(var i in obj){delete obj[i]}},raise:function raise(flat){var _raise={};var _loop=function _loop(path){var _keys=path.split('.');var _cursor=_raise;_keys.forEach(function(key,i){if(i<_keys.length-1){if(!_cursor[key]){_cursor[key]={}}_cursor=_cursor[key]}else{_cursor[key]=flat[path]}})};for(var path in flat){_loop(path)}return _raise},getByFlatKey:function getByFlatKey(obj,fkey){var _path=fkey.split('.');var _walk=obj;for(var i=0;i<_path.length;i++){if(!_walk[_path[i]]){return undefined}_walk=_walk[_path[i]]}return _walk},setByFlatKey:function setByFlatKey(obj,fkey,val){var _path=fkey.split('.');var _walk=obj;for(var i=0;i<_path.length;i++){if(!_walk[_path[i]]){if(i===_path.length-1){_walk[_path[i]]=undefined;return}_walk[_path[i]]={}}_walk=_walk[_path[i]]}_walk=val}};module.exports=object;

@@ -1263,3 +1263,3 @@ },{}],19:[function(require,module,exports){

},{"./hash":17}],20:[function(require,module,exports){
'use strict';var string={template:function template(str,obj){var remove=arguments.length>2&&arguments[2]!==undefined?arguments[2]:false;if(!str){return''}return str.replace(/\{([\w.]+)\}/g,function(str,key){return obj[key]?obj[key]:remove?'':str})},trim:function trim(str,cuts){if(!cuts){return str.replace(/^[\s\xa0]+|[\s\xa0]+$/g,'')}else{var _cuts=cuts.map(function(c){if(c==='['||c===']'){return'\\'+c}return c}).join();return str.replace(new RegExp('^['+_cuts+']+|['+_cuts+']+$','gm'),'')}},replaceAll:function replaceAll(str,from,to){return str.split(from).join(to)},capitalize:function capitalize(str){return str.substr(0,1).toUpperCase()+str.substr(1).toLowerCase()},prependMissing:function prependMissing(prefix,str){if(str.indexOf(prefix)===0){return str}return prefix+str},matchAll:function matchAll(str,regexp){var _matches=[];var _match=regexp.exec(str);while(_match){_matches.push(_match);_match=regexp.exec(str)}return _matches}};module.exports=string;
'use strict';var string={template:function template(str,obj){var remove=arguments.length>2&&arguments[2]!==undefined?arguments[2]:false;if(!str){return''}return str.replace(/\{([\w.]+)\}/g,function(str,key){return obj[key]?obj[key]:remove?'':str})},trim:function trim(str,cuts){if(!cuts){return str.replace(/^[\s\xa0]+|[\s\xa0]+$/g,'')}else{var _cuts=cuts.map(function(c){if(c==='['||c===']'){return'\\'+c}return c}).join();return str.replace(new RegExp('^['+_cuts+']+|['+_cuts+']+$','gm'),'')}},replaceAll:function replaceAll(str,from,to){if(!str){return''}return str.split(from).join(to)},capitalize:function capitalize(str){return str.substr(0,1).toUpperCase()+str.substr(1).toLowerCase()},prependMissing:function prependMissing(prefix,str){if(str.indexOf(prefix)===0){return str}return prefix+str},matchAll:function matchAll(str,regexp){var _matches=[];var _match=regexp.exec(str);while(_match){_matches.push(_match);_match=regexp.exec(str)}return _matches}};module.exports=string;

@@ -1266,0 +1266,0 @@ },{}],21:[function(require,module,exports){

@@ -0,1 +1,457 @@

### array
#### array.remove(array, item)
- _array_ \<Array<*>\>
- _item_ \<*\>
remove an element from array\nit removes only the first occurrence
_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
````
#### 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]
````
---
### fs
#### fs.exists(path)
- _path_ \<string\> file path
- _return:_ Promise.\<boolean\> true if file exists - and it's a file
replace deprecated fs.exists
_Example_
````js
tools.fs.exists('/tmp/file')
// > true
````
#### fs.touch(path, [mode=0o666])
- _path_ \<string\> file path
- _[mode=0o666]_ \<number\>
- _return:_ Promise.\<void\>
create an empty file if not exists
_Example_
````js
tools.fs.touch('/tmp/touch-me')
````
#### fs.unlink(path, [safe=true])
- _path_ \<string\> file path
- _[safe=true]_ \<boolean\> if safe do not throw exception
- _return:_ Promise.\<void\>
delete file, optionally in safe mode
_Example_
````js
tools.fs.unlink('/tmp/file')
````
---
### 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'
````
---
### object
#### object.flat(obj)
- _obj_ \<Object\>
- _return:_ Object
flat keys in object
_Example_
````js
tools.object.flat({ a: { a1: 1, a2: 2 }, b: 3 })
// > { 'a.a1': 1, 'a.a2': 2, 'b': 3 }
````
#### object.merge(a, b)
- _a_ \<Object\>
- _b_ \<Object\>
merge b into a
_Example_
````js
let a = {a:1,b:'ciao'}
tools.object.merge(a, {a:4,c:{d:8,e:9}})
// > a = { a: 4, b: 'ciao', c: { d: 8, e: 9 } }
````
#### object.clone(obj)
- _obj_ \<Object|Array\> The array or the object to clone
- _return:_ Object|Array
Clone an array or an object in input
_Example_
````js
tools.object.clone({a: 1, b: 'ciao'})
// > {a: 1, b: 'ciao'}
````
#### object.getKeys(obj)
- _obj_ \<Object\>
- _return:_ Array\<string\>
_Example_
````js
tools.object.getKeys({a: () => { }, b: 1, c: 'ciao'})
// > ['a','b','c']
````
#### object.inherits(destination, source)
- _destination_ \<Object\>
- _source_ \<Object\>
it use ``Object.getOwnPropertyNames`` to inherits child from parent, without prototype
_Example_
````js
let a = {}
tools.object.inherits(a, {f0:() => { },p1:1,p2:'ciao'})
// > a = {f0: () => { }, p1: 1, p2: 'ciao'}
````
#### object.empty(obj)
- _obj_ \<Object\>
empty object - need to keep references
_Example_
````js
let a = {a:0,b:1,c:2,d:[],e:{f:-1}}
tools.object.empty(a)
// > a = {}
````
#### object.raise(flat)
- _flat_ \<Object\>
- _return:_ Object
restore flat object
_Example_
````js
tools.object.raise({ 'a.a1': 1, 'a.a2': 2, 'b': 3 })
// > { a: { a1: 1, a2: 2 }, b: 3 }
````
#### object.getByFlatKey(obj, fkey)
- _obj_ \<Object\>
- _fkey_ \<string\>
- _return:_ Object
get value in object using a flat key
_Example_
````js
tools.object.getByFlatKey({ a: { b: {c: 1} } }, 'a.b.c')
// > 1
````
#### object.setByFlatKey(obj, fkey, val)
- _obj_ \<Object\>
- _fkey_ \<string\>
- _val_ \<*\>
set value in object using a flat key
_Example_
````js
let a = {}
tools.object.setByFlatKey(a, 'a.b.c', 1)
// > a = { a: { b: {c: 1} } }
````
---
### 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
---
### string
#### string.template(str, obj, [remove=false])
- _str_ \<string\>
- _obj_ \<Object\>
- _[remove=false]_ \<boolean\> remove missing placeholders from obj, default false
- _return:_ string
replace placeholders inside graph brackets {} with obj dictionary\n~ES6 template string without $
_Example_
````js
tools.string.template('hi {name} how are you?', {name: 'Alice'})
// > 'hi Alice how are you?'
````
#### string.trim(str, cuts)
- _str_ \<string\>
- _cuts_ \<Array<string>\>
- _return:_ string
trim string
_Example_
````js
tools.string.trim(' regular trim ')
// > 'regular trim'
````
#### string.replaceAll(str, from, to)
- _str_ \<string\>
- _from_ \<string\>
- _to_ \<string\>
- _return:_ string
_Example_
````js
tools.string.replaceAll('abcadaeafaga', 'a', '')
// > 'bcdefg'
````
#### string.capitalize(str)
- _str_ \<string\>
- _return:_ string
_Example_
````js
tools.string.capitalize('alice')
// > 'Alice'
````
#### string.prependMissing(prefix, str)
- _prefix_ \<string\>
- _str_ \<string\>
- _return:_ string
_Example_
````js
tools.string.prependMissing('miss ', 'Alice')
// > 'miss Alice'
````
---
### random

@@ -89,1 +545,13 @@

````
---
### sys
#### sys.isRoot()
- _return:_ bool is root or not
check if running user is root

@@ -13,4 +13,5 @@ /**

flat: function (obj) {
const _obj = {}
return object._rflat(obj, '', _obj)
const _flat = {}
object._rflat(obj, '', _flat)
return _flat
},

@@ -88,5 +89,5 @@

}
/**
* @type {Array|Object}
*/
/**
* @type {Array|Object}
*/
var _clone = _type === 'array' ? [] : {}

@@ -150,26 +151,23 @@ for (var key in obj) {

* @method tools.object.raise
* @param {Object} obj
* @param {Object} flat
* @return {Object}
* @test.case { 'a.a1': 1, 'a.a2': 2, 'b': 3 } > { a: { a1: 1, a2: 2 }, b: 3 }
*/
raise: function (obj) {
raise: function (flat) {
const _raise = {}
const _f = function (flat, raise) {
for (const path in flat) {
const _keys = path.split('.')
let _cursor = raise
_keys.forEach((key, i) => {
if (i < _keys.length - 1) {
if (!_cursor[key]) {
_cursor[key] = {}
}
_cursor = _cursor[key]
} else {
_cursor[key] = flat[path]
for (const path in flat) {
const _keys = path.split('.')
let _cursor = _raise
_keys.forEach((key, i) => {
if (i < _keys.length - 1) {
if (!_cursor[key]) {
_cursor[key] = {}
}
})
}
_cursor = _cursor[key]
} else {
_cursor[key] = flat[path]
}
})
}
_f(obj, _raise)

@@ -215,3 +213,3 @@ return _raise

if (!_walk[_path[i]]) {
// if it's the last step, add key as undefined
// if it's the last step, add key as undefined
if (i === _path.length - 1) {

@@ -218,0 +216,0 @@ _walk[_path[i]] = undefined

{
"name": "a-toolbox",
"version": "1.2.6",
"version": "1.2.7",
"description": "javascript lightweight basic tools, isomorphic",
"main": "index.js",
"dependencies": {
"hash.js": "^1.1.3"
"hash.js": "^1.x"
},

@@ -9,0 +9,0 @@ "devDependencies": {

@@ -385,4 +385,4 @@ # a-toolbox

#### _f.raise(obj)
- _obj_ \<Object\>
#### object.raise(flat)
- _flat_ \<Object\>
- _return:_ Object

@@ -400,16 +400,2 @@

#### object.raise(obj)
- _obj_ \<Object\>
- _return:_ Object
restore flat object
_Example_
````js
tools.object.raise({ 'a.a1': 1, 'a.a2': 2, 'b': 3 })
// > { a: { a1: 1, a2: 2 }, b: 3 }
````
#### object.getByFlatKey(obj, fkey)

@@ -416,0 +402,0 @@ - _obj_ \<Object\>

@@ -13,4 +13,5 @@ /**

flat: function (obj) {
const _obj = {}
return object._rflat(obj, '', _obj)
const _flat = {}
object._rflat(obj, '', _flat)
return _flat
},

@@ -88,5 +89,5 @@

}
/**
* @type {Array|Object}
*/
/**
* @type {Array|Object}
*/
var _clone = _type === 'array' ? [] : {}

@@ -150,26 +151,23 @@ for (var key in obj) {

* @method tools.object.raise
* @param {Object} obj
* @param {Object} flat
* @return {Object}
* @test.case { 'a.a1': 1, 'a.a2': 2, 'b': 3 } > { a: { a1: 1, a2: 2 }, b: 3 }
*/
raise: function (obj) {
raise: function (flat) {
const _raise = {}
const _f = function (flat, raise) {
for (const path in flat) {
const _keys = path.split('.')
let _cursor = raise
_keys.forEach((key, i) => {
if (i < _keys.length - 1) {
if (!_cursor[key]) {
_cursor[key] = {}
}
_cursor = _cursor[key]
} else {
_cursor[key] = flat[path]
for (const path in flat) {
const _keys = path.split('.')
let _cursor = _raise
_keys.forEach((key, i) => {
if (i < _keys.length - 1) {
if (!_cursor[key]) {
_cursor[key] = {}
}
})
}
_cursor = _cursor[key]
} else {
_cursor[key] = flat[path]
}
})
}
_f(obj, _raise)

@@ -215,3 +213,3 @@ return _raise

if (!_walk[_path[i]]) {
// if it's the last step, add key as undefined
// if it's the last step, add key as undefined
if (i === _path.length - 1) {

@@ -218,0 +216,0 @@ _walk[_path[i]] = undefined

@@ -70,2 +70,5 @@ /**

replaceAll: function (str, from, to) {
if (!str) {
return ''
}
return str.split(from).join(to)

@@ -72,0 +75,0 @@ },

@@ -70,2 +70,5 @@ /**

replaceAll: function (str, from, to) {
if (!str) {
return ''
}
return str.split(from).join(to)

@@ -72,0 +75,0 @@ },

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