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.5.1 to 1.5.2

4

dist/atoolbox.min.js

@@ -1259,5 +1259,5 @@ (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}],19:[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={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},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]}}},walk:function walk(obj,path){var _steps=path.split('.');var _cursor=obj;var _iteratorNormalCompletion=true;var _didIteratorError=false;var _iteratorError=undefined;try{for(var _iterator=_steps[Symbol.iterator](),_step2;!(_iteratorNormalCompletion=(_step2=_iterator.next()).done);_iteratorNormalCompletion=true){var _step=_step2.value;_cursor=_cursor[_step]}}catch(err){_didIteratorError=true;_iteratorError=err}finally{try{if(!_iteratorNormalCompletion&&_iterator.return){_iterator.return()}}finally{if(_didIteratorError){throw _iteratorError}}}return _cursor},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 tools={array:require('./array')};var object={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},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]}}},walk:function walk(obj,path){var _steps=path.split('.');var _cursor=obj;var _iteratorNormalCompletion=true;var _didIteratorError=false;var _iteratorError=undefined;try{for(var _iterator=_steps[Symbol.iterator](),_step2;!(_iteratorNormalCompletion=(_step2=_iterator.next()).done);_iteratorNormalCompletion=true){var _step=_step2.value;_cursor=_cursor[_step]}}catch(err){_didIteratorError=true;_iteratorError=err}finally{try{if(!_iteratorNormalCompletion&&_iterator.return){_iterator.return()}}finally{if(_didIteratorError){throw _iteratorError}}}return _cursor},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){console.log(fkey);var _path=fkey.split('.').map(function(path){if(path.indexOf('[')===-1){return{t:'{}',s:path}}var _array=path.substr(0,path.length-1).split('[');return[{t:'{}',s:_array[0]},{t:'[]',s:parseInt(_array[1])}]});_path=tools.array.flat(_path);var _walk=obj;for(var i=0;i<_path.length;i++){var _step=_path[i];if(i===_path.length-1){_walk[_step.s]=val;return}if(!_walk[_step.s]){_walk[_step.s]=_path[i+1].t==='{}'?{}:[]}_walk=_walk[_step.s]}_walk=val;console.log(obj)}};module.exports=object;
},{}],20:[function(require,module,exports){
},{"./array":16}],20:[function(require,module,exports){
'use strict';var _hash=require('./hash');var random={rnd:function rnd(max){if(!max){return 0}return Math.floor(max*Math.random())},number:function number(min,max){if(!max){return random.rnd(min)}min=Math.floor(min);max=Math.floor(max);return min+random.rnd(1+max-min)},string:function string(){var length=arguments.length>0&&arguments[0]!==undefined?arguments[0]:8;var set=arguments.length>1&&arguments[1]!==undefined?arguments[1]:'abcdefghijklmnopqrstuvwxyz';var _str='';for(var i=0;i<length;i++){_str+=random.element(set)}return _str},hex:function hex(){var length=arguments.length>0&&arguments[0]!==undefined?arguments[0]:8;return random.string(length,'0123456789abcdef')},hash:function hash(){var salt=arguments.length>0&&arguments[0]!==undefined?arguments[0]:'';return _hash.sha256(new Date().toISOString()+salt)},element:function element(array,not){if(!not){return array[random.number(0,array.length-1)]}else{var _item=void 0;var i=0;do{_item=random.element(array)}while(not.indexOf(_item)!==-1&&++i<array.length);return _item}}};module.exports=random;

@@ -1264,0 +1264,0 @@

@@ -0,1 +1,4 @@

const tools = {
array: require('./array')
}
/**

@@ -223,18 +226,31 @@ * @namespace tools.object

* {}, 'a.b.c', 1 > &{ a: { b: {c: 1} } }
* {}, 'a', 2 > &{ a: 2 }
* {}, 'ann[0].b[1].cic', 1 > &{ ann: [{ b: [null, {cic: 1}] }] }
*/
setByFlatKey: function (obj, fkey, val) {
let _path = fkey.split('.')
console.log(fkey)
let _path = fkey
.split('.')
.map((path) => {
if (path.indexOf('[') === -1) {
return {t: '{}', s: path}
}
const _array = path.substr(0, path.length - 1).split('[')
return [{t: '{}', s: _array[0]}, {t: '[]', s: parseInt(_array[1])}]
})
_path = tools.array.flat(_path)
let _walk = obj
for (let i = 0; i < _path.length; i++) {
if (!_walk[_path[i]]) {
// if it's the last step, add key as undefined
if (i === _path.length - 1) {
_walk[_path[i]] = undefined
return
}
_walk[_path[i]] = {}
let _step = _path[i]
if (i === _path.length - 1) {
_walk[_step.s] = val
return
}
_walk = _walk[_path[i]]
if (!_walk[_step.s]) {
_walk[_step.s] = _path[i + 1].t === '{}' ? {} : []
}
_walk = _walk[_step.s]
}
_walk = val
console.log(obj)
}

@@ -241,0 +257,0 @@ }

{
"name": "a-toolbox",
"version": "1.5.1",
"version": "1.5.2",
"description": "isomorphic javascript lightweight basic tools",

@@ -5,0 +5,0 @@ "main": "index.js",

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

creates a new array with all sub-array elements concatted into it recursively up to the specified depth, as ``Array.prototype.flatten()``
creates a new array with all sub-array elements concatted into it recursively like ``Array.prototype.flatten()``

@@ -883,2 +883,6 @@

v. 1.5.1
- ``object.setByFlatKey`` support also Array
v. 1.5.0

@@ -885,0 +889,0 @@

@@ -0,1 +1,4 @@

const tools = {
array: require('./array')
}
/**

@@ -223,18 +226,31 @@ * @namespace tools.object

* {}, 'a.b.c', 1 > &{ a: { b: {c: 1} } }
* {}, 'a', 2 > &{ a: 2 }
* {}, 'ann[0].b[1].cic', 1 > &{ ann: [{ b: [null, {cic: 1}] }] }
*/
setByFlatKey: function (obj, fkey, val) {
let _path = fkey.split('.')
console.log(fkey)
let _path = fkey
.split('.')
.map((path) => {
if (path.indexOf('[') === -1) {
return {t: '{}', s: path}
}
const _array = path.substr(0, path.length - 1).split('[')
return [{t: '{}', s: _array[0]}, {t: '[]', s: parseInt(_array[1])}]
})
_path = tools.array.flat(_path)
let _walk = obj
for (let i = 0; i < _path.length; i++) {
if (!_walk[_path[i]]) {
// if it's the last step, add key as undefined
if (i === _path.length - 1) {
_walk[_path[i]] = undefined
return
}
_walk[_path[i]] = {}
let _step = _path[i]
if (i === _path.length - 1) {
_walk[_step.s] = val
return
}
_walk = _walk[_path[i]]
if (!_walk[_step.s]) {
_walk[_step.s] = _path[i + 1].t === '{}' ? {} : []
}
_walk = _walk[_step.s]
}
_walk = val
console.log(obj)
}

@@ -241,0 +257,0 @@ }

@@ -34,3 +34,3 @@ const time = require('./time')

* @method Worker.todo
* @param {!string} id
* @param {!string} id task identifier
* @test.mode EVENT

@@ -49,3 +49,3 @@ * @test.case 'task#1'

* @method Worker.done
* @param {!string} id
* @param {!string} id task identifier
* @return {Object|null} if options.chrono is enabled, return elapsed time as {chrono: time ms}

@@ -52,0 +52,0 @@ * @test.case 'task#1'

@@ -34,3 +34,3 @@ const time = require('./time')

* @method Worker.todo
* @param {!string} id
* @param {!string} id task identifier
* @test.mode EVENT

@@ -49,3 +49,3 @@ * @test.case 'task#1'

* @method Worker.done
* @param {!string} id
* @param {!string} id task identifier
* @return {Object|null} if options.chrono is enabled, return elapsed time as {chrono: time ms}

@@ -52,0 +52,0 @@ * @test.case 'task#1'

@@ -5,133 +5,24 @@ const tester = require('tollo')

module.exports = {
'object.flat': {
'object.setByFlatKey': {
describe: '',
mode: tester.mode.SYNC,
act: instance.flat,
act: instance.setByFlatKey,
cases: [
{
input: [{ a: { a1: 1, a2: 2 }, b: 3 }],
output: { 'a.a1': 1, 'a.a2': 2, 'b': 3 }
}
],
assert: tester.assert.equal
},
'object._rflat': {
describe: '',
mode: tester.mode.SYNC,
act: instance._rflat,
cases: [
]
},
'object.merge': {
describe: '',
mode: tester.mode.SYNC,
act: instance.merge,
cases: [
{
input: [{a: 1, b: 'ciao'}, {a: 4, c: { d: 8, e: 9}}],
output: { a: 4, b: 'ciao', c: { d: 8, e: 9 } }
}
],
assert: tester.assert.mutation
},
'object.clone': {
describe: '',
mode: tester.mode.SYNC,
act: instance.clone,
cases: [
{
input: [{a: 1, b: 'ciao'}],
output: {a: 1, b: 'ciao'}
input: [{}, 'a', 2],
output: { a: 2 }
},
{
input: [{a: 4, c: { d: 8, e: 9}}],
output: {a: 4, c: { d: 8, e: 9}}
input: [{}, 'a.b.c', 1],
output: { a: { b: {c: 1} } }
},
{
input: [{a: 4, b: 'ciao', c: { d: 8, e: 9 }}],
output: {a: 4, b: 'ciao', c: { d: 8, e: 9 }}
},
{
input: [{a: [4, function() { console.log('hi') }, {a1: 0, a2: null}], b: 'ciao', c: { d: 8, e: 9 }}],
could: '{a: [4, function() { console.log("hi") }, {a1: 0, a2: null}], b: "ciao", c: { d: 8, e: 9 }}'
// deep-equal in checkv fail to compare
disabled: true,
input: [{}, 'ann[0].b[1].cic', 1],
output: { ann: [{ b: [null, {cic: 1}] }] }
}
],
assert: tester.assert.equal
},
'object.getKeys': {
describe: '',
mode: tester.mode.SYNC,
act: instance.getKeys,
cases: [
{
input: [{a: () => { }, b: 1, c: 'ciao'}],
output: ['a','b','c']
}
],
assert: tester.assert.equal
},
'object.inherits': {
describe: '',
mode: tester.mode.SYNC,
act: instance.inherits,
cases: [
{
input: [{}, {f0: () => { }, p1: 1, p2: 'ciao'}],
output: {f0: () => { }, p1: 1, p2: 'ciao'}
}
],
assert: tester.assert.mutation
},
'object.empty': {
describe: '',
mode: tester.mode.SYNC,
act: instance.empty,
cases: [
{
input: [{a:0,b:1,c:2,d:[],e:{f:-1}}],
output: {}
},
{
input: [{}],
output: {}
}
],
assert: tester.assert.mutation
},
'object.raise': {
describe: '',
mode: tester.mode.SYNC,
act: instance.raise,
cases: [
{
input: [{ 'a.a1': 1, 'a.a2': 2, 'b': 3 }],
output: { a: { a1: 1, a2: 2 }, b: 3 }
}
],
assert: tester.assert.equal
},
'object.getByFlatKey': {
describe: '',
mode: tester.mode.SYNC,
act: instance.getByFlatKey,
cases: [
{
input: [{ a: { b: {c: 1} } }, 'a.b.c'],
output: 1
}
],
assert: tester.assert.equal
},
'object.setByFlatKey': {
describe: '',
mode: tester.mode.SYNC,
act: instance.setByFlatKey,
cases: [
{
input: [{}, 'a.b.c', 1],
output: { a: { b: {c: 1} } }
}
],
assert: tester.assert.mutation
}
}

@@ -12,13 +12,4 @@

// tester.bulk(require('./modules/array.js'))
tester.bulk(require('./modules/fs.js'))
tester.bulk(require('./modules/hash.js'))
//tester.bulk(require('./modules/object.js'))
tester.bulk(require('./modules/random.js'))
tester.bulk(require('./modules/string.js'))
tester.bulk(require('./modules/sys.js'))
tester.bulk(require('./modules/time.js'))
// tester.bulk(require('./modules/task.js'))
// tester.bulk(require('./modules/event.js'))
tester.bulk(require('./modules/object.js'))
tester.run()

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