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.3 to 1.5.5

test/modules/event.js

8

array.js

@@ -112,4 +112,4 @@ /**

* @test.case ['john', 'alice', 'bob'], 1, 'mary' > &['john', 'mary', 'alice', 'bob']
* @test.case ['john', 'alice', 'bob'], -1, 'mary' > &['john', 'alice', 'bob', 'mary']
* @test.case ['john', 'alice', 'bob'], -2, 'mary' > &['john', 'alice', 'mary', 'bob']
* @test.case ['john', 'alice', 'bob'], -1, 'mary' > &['john', 'alice', 'mary', 'bob']
* @test.case ['john', 'alice', 'bob'], -2, 'mary' > &['john', 'mary', 'alice', 'bob']
*/

@@ -121,3 +121,3 @@ insert: function (array, index, item) {

if (array[index]) {
if (array.length > index) {
array.splice(index, 0, item)

@@ -148,3 +148,3 @@ } else {

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

@@ -151,0 +151,0 @@ }

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

(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){
(function(){function r(e,n,t){function o(i,f){if(!n[i]){if(!e[i]){var c="function"==typeof require&&require;if(!f&&c)return c(i,!0);if(u)return u(i,!0);var a=new Error("Cannot find module '"+i+"'");throw a.code="MODULE_NOT_FOUND",a}var p=n[i]={exports:{}};e[i][0].call(p.exports,function(r){var n=e[i][1][r];return o(n||r)},p,p.exports,r,e,n,t)}return n[i].exports}for(var u="function"==typeof require&&require,i=0;i<t.length;i++)o(t[i]);return o}return r})()({1:[function(require,module,exports){
var hash = exports;

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

},{"./utils":12,"minimalistic-assert":14}],3:[function(require,module,exports){
},{"./utils":12,"minimalistic-assert":13}],3:[function(require,module,exports){
'use strict';

@@ -162,3 +162,3 @@

},{"./utils":12,"minimalistic-assert":14}],4:[function(require,module,exports){
},{"./utils":12,"minimalistic-assert":13}],4:[function(require,module,exports){
'use strict';

@@ -535,3 +535,3 @@

},{"../common":2,"../utils":12,"./common":11,"minimalistic-assert":14}],9:[function(require,module,exports){
},{"../common":2,"../utils":12,"./common":11,"minimalistic-assert":13}],9:[function(require,module,exports){
'use strict';

@@ -905,3 +905,3 @@

},{"../common":2,"../utils":12,"minimalistic-assert":14}],11:[function(require,module,exports){
},{"../common":2,"../utils":12,"minimalistic-assert":13}],11:[function(require,module,exports){
'use strict';

@@ -1212,3 +1212,16 @@

},{"inherits":13,"minimalistic-assert":14}],13:[function(require,module,exports){
},{"inherits":14,"minimalistic-assert":13}],13:[function(require,module,exports){
module.exports = assert;
function assert(val, msg) {
if (!val)
throw new Error(msg || 'Assertion failed');
}
assert.equal = function assertEqual(l, r, msg) {
if (l != r)
throw new Error(msg || ('Assertion failed: ' + l + ' != ' + r));
};
},{}],14:[function(require,module,exports){
if (typeof Object.create === 'function') {

@@ -1238,15 +1251,2 @@ // implementation from standard node.js 'util' module

},{}],14:[function(require,module,exports){
module.exports = assert;
function assert(val, msg) {
if (!val)
throw new Error(msg || 'Assertion failed');
}
assert.equal = function assertEqual(l, r, msg) {
if (l != r)
throw new Error(msg || ('Assertion failed: ' + l + ' != ' + r));
};
},{}],15:[function(require,module,exports){

@@ -1256,3 +1256,3 @@ 'use strict';window.tools={array:require('./array'),hash:require('./hash'),object:require('./object'),event:require('./event'),random:require('./random'),string:require('./string'),task:require('./task'),time:require('./time'),util:require('./util')};

},{"./array":16,"./event":17,"./hash":18,"./object":19,"./random":20,"./string":21,"./task":22,"./time":23,"./util":24}],16:[function(require,module,exports){
"use strict";var array={remove:function remove(array,item){var _index=array.indexOf(item);if(_index!==-1){array.splice(_index,1)}},removeAt:function removeAt(array,index){return Array.prototype.splice.call(array,index,1).length===1},last:function last(array){return array[array.length-1]},at:function at(array,p){if(p<0){p=array.length+p}return array[p]},first:function first(array){return array[0]},contains:function contains(array,item){return array.indexOf(item)!==-1},insert:function insert(array,index,item){if(index>array.length){index=array.length}if(array[index]){array.splice(index,0,item)}else{array[index]=item}},concat:function concat(args){return Array.prototype.concat.apply(Array.prototype,arguments)},empty:function empty(array){while(array[0]){array.pop()}},add:function add(array,item,unique){if(!!unique&&array.indexOf(item)!==-1){return}array.push(item)},flat:function flat(array_){var _flat=[];for(var i=0;i<array_.length;i++){var _e=array_[i];if(_e instanceof Array){_flat=_flat.concat(array.flat(_e))}else{_flat.push(_e)}}return _flat},sortingInsert:function sortingInsert(array_,item){var _end=array_.length-1;var _start=0;var i=void 0,_element=void 0;while(_start<=_end){i=(_start+_end)/2|0;_element=array_[i];if(_element<item){_start=i+1}else if(_element>item){_end=i-1}else{array.insert(array_,i,item);return}}if(_end<array_.length-1){array.insert(array_,_end+1,item)}else if(_start>0){array.insert(array_,_start,item)}else{array_.push(item)}},binaryIndexOf:function binaryIndexOf(array,item){var _end=array.length-1;var _start=0;var i=void 0,_element=void 0;while(_start<=_end){i=(_start+_end)/2|0;_element=array[i];if(_element<item){_start=i+1}else if(_element>item){_end=i-1}else{return i}}return-1}};module.exports=array;
"use strict";var array={remove:function remove(array,item){var _index=array.indexOf(item);if(_index!==-1){array.splice(_index,1)}},removeAt:function removeAt(array,index){return Array.prototype.splice.call(array,index,1).length===1},last:function last(array){return array[array.length-1]},at:function at(array,p){if(p<0){p=array.length+p}return array[p]},first:function first(array){return array[0]},contains:function contains(array,item){return array.indexOf(item)!==-1},insert:function insert(array,index,item){if(index>array.length){index=array.length}if(array.length>index){array.splice(index,0,item)}else{array[index]=item}},concat:function concat(args){return Array.prototype.concat.apply(Array.prototype,arguments)},empty:function empty(array){while(array.length>0){array.pop()}},add:function add(array,item,unique){if(!!unique&&array.indexOf(item)!==-1){return}array.push(item)},flat:function flat(array_){var _flat=[];for(var i=0;i<array_.length;i++){var _e=array_[i];if(_e instanceof Array){_flat=_flat.concat(array.flat(_e))}else{_flat.push(_e)}}return _flat},sortingInsert:function sortingInsert(array_,item){var _end=array_.length-1;var _start=0;var i=void 0,_element=void 0;while(_start<=_end){i=(_start+_end)/2|0;_element=array_[i];if(_element<item){_start=i+1}else if(_element>item){_end=i-1}else{array.insert(array_,i,item);return}}if(_end<array_.length-1){array.insert(array_,_end+1,item)}else if(_start>0){array.insert(array_,_start,item)}else{array_.push(item)}},binaryIndexOf:function binaryIndexOf(array,item){var _end=array.length-1;var _start=0;var i=void 0,_element=void 0;while(_start<=_end){i=(_start+_end)/2|0;_element=array[i];if(_element<item){_start=i+1}else if(_element>item){_end=i-1}else{return i}}return-1}};module.exports=array;

@@ -1266,3 +1266,3 @@ },{}],17:[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 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(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;
'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(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){if(Object.assign){Object.assign(destination,source);return}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;

@@ -1273,3 +1273,3 @@ },{"./array":16}],20:[function(require,module,exports){

},{"./hash":18}],21:[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){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;
'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 _words=void 0;var _cuts=cuts.map(function(c){if(c.length>1){_words=true;return c}if(c==='['||c===']'){return'\\'+c}return c});if(_words){var _subexpression2=_cuts.join('|');return str.replace(new RegExp('^('+_subexpression2+')+|('+_subexpression2+')+$','gm'),'')}var _subexpression=_cuts.join();return str.replace(new RegExp('^['+_subexpression+']+|['+_subexpression+']+$','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;

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

@@ -16,3 +16,3 @@ const nativeFs = require('fs')

* @test.arrange async function(input, sandbox) {
* const fs = require('a-toolbox').fs
* const fs = require('../../src/fs')
* return fs.touch('/tmp/file')

@@ -46,8 +46,8 @@ * }

* @test.case '/tmp/touch-me'
* @test.case '/none' ! new Error('EACCES')
* @test.case '/none' ! new tollo.Error({code: 'EACCES'})
* @test.assert async (result, input, output, sandbox) => {
* if(!await tester.assert.equal(result, input, output, sandbox)) {
* return false
* if(result) {
* return result.code === output.code
* }
* const fs = require('a-toolbox').fs
* const fs = require('../../src/fs')
* return fs.exists(input[0])

@@ -80,7 +80,7 @@ * }

* @test.arrange async function(input, sandbox) {
* const fs = require('a-toolbox').fs
* const fs = require('../../src/fs')
* return fs.touch('/tmp/file')
* }
* @test.case '/tmp/file'
* @test.case '/tmp/none', false ! new Error('EACCES')
* @test.case '/tmp/none', false ! new tollo.Error({code: 'ENOENT'})
* @test.case '/tmp/none', true

@@ -87,0 +87,0 @@ */

@@ -45,6 +45,6 @@ const tools = {

* @return {Object|Array}
* @todo test.case {a: 4, b: 'ciao', c: { d: 8, e: 9 }} > {a: 4, b: 'ciao', c: { d: 8, e: 9 }}
* @todo test.case {a: [4, function() { console.log('hi') }, {a1: 0, a2: null}], b: 'ciao', c: { d: 8, e: 9 }} > {a: [4, function() { console.log('hi') }, {a1: 0, a2: null}], b: 'ciao', c: { d: 8, e: 9 }}
* @test.case {a: 1, b: 'ciao'} > {a: 1, b: 'ciao'}
* @test.case {a: 4, c: { d: 8, e: 9}} > {a: 4, c: { d: 8, e: 9}}
* @test.case {a: 4, b: 'ciao', c: { d: 8, e: 9 }} > {a: 4, b: 'ciao', c: { d: 8, e: 9 }}
* @test.case {a: [4, function() { console.log('hi') }, {a1: 0, a2: null}], b: 'ciao', c: { d: 8, e: 9 }} > {a: [4, function() { console.log('hi') }, {a1: 0, a2: null}], b: 'ciao', c: { d: 8, e: 9 }}
*/

@@ -95,3 +95,3 @@ clone: function (obj) {

/**
* it use ``Object.getOwnPropertyNames`` to inherits child from parent, without prototype
* perform ``Object.assign`` if native or copy object using ``Object.getOwnPropertyNames`` to inherits child from parent, without prototype
* @method tools.object.inherits

@@ -101,5 +101,10 @@ * @todo check if both are objects

* @param {Object} source
* @test.case {}, {f0: () => { }, p1: 1, p2: 'ciao'} > &{f0: () => { }, p1: 1, p2: 'ciao'}
* @todo fix checkv isEqual test.case {}, {f0: () => { }, p1: 1, p2: 'ciao'} > &{f0: () => { }, p1: 1, p2: 'ciao'}
* @test.case {}, {p1: 1, p2: 'ciao'} > &{p1: 1, p2: 'ciao'}
*/
inherits: function (destination, source) {
if (Object.assign) {
Object.assign(destination, source)
return
}
Object.getOwnPropertyNames(source).forEach((property) => {

@@ -225,6 +230,5 @@ destination[property] = source[property]

* @param {*} val
* @test.case
* {}, 'a.b.c', 1 > &{ a: { b: {c: 1} } }
* {}, 'a', 2 > &{ a: 2 }
* {}, 'ann[0].b[1].cic', 1 > &{ ann: [{ b: [null, {cic: 1}] }] }
* @todo checkv.isEqual fail test.case {}, 'ann[0].b[1].cic', 1 > &{ ann: [{ b: [null, {cic: 1}] }] }
* @test.case {}, 'a.b.c', 1 > &{ a: { b: {c: 1} } }
* @test.case {}, 'a', 2 > &{ a: 2 }
*/

@@ -231,0 +235,0 @@ setByFlatKey: function (obj, fkey, val) {

{
"name": "a-toolbox",
"version": "1.5.3",
"description": "javascript lightweight basic tools, isomorphic",
"version": "1.5.5",
"description": "javascript lightweight basic tools for node.js and browser",
"main": "index.js",
"dependencies": {
"hash.js": "^1.1.3"
"hash.js": "^1.1.5"
},
"devDependencies": {
"babel": "^6",
"babel-core": "^6",
"babel-preset-env": "^1.6",
"babel": "^6.23.0",
"babel-core": "^6.26.3",
"babel-preset-env": "^1.7.0",
"babel-preset-es2015": "^6",
"babelify": "^8",
"browserify": "^14",
"fs-extra": "^5",
"gulp": "^3",
"babelify": "^8.0.0",
"browserify": "^16.2.2",
"fs-extra": "^7.0.0",
"gulp": "^3.9.1",
"gulp-buffer": "^0",

@@ -23,5 +23,4 @@ "gulp-clean": "^0.3",

"pre-commit": "^1",
"standard": "^11",
"tap": "^11",
"tollo": "0.0.5-dev",
"standard": "^11.0.1",
"tap": "^12.0.1",
"vinyl-source-stream": "^1"

@@ -28,0 +27,0 @@ },

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

javascript lightweight basic tools, isomorphic
javascript lightweight basic tools for node.js and browser

@@ -11,0 +11,0 @@ ## Purpose

@@ -112,4 +112,4 @@ /**

* @test.case ['john', 'alice', 'bob'], 1, 'mary' > &['john', 'mary', 'alice', 'bob']
* @test.case ['john', 'alice', 'bob'], -1, 'mary' > &['john', 'alice', 'bob', 'mary']
* @test.case ['john', 'alice', 'bob'], -2, 'mary' > &['john', 'alice', 'mary', 'bob']
* @test.case ['john', 'alice', 'bob'], -1, 'mary' > &['john', 'alice', 'mary', 'bob']
* @test.case ['john', 'alice', 'bob'], -2, 'mary' > &['john', 'mary', 'alice', 'bob']
*/

@@ -121,3 +121,3 @@ insert: function (array, index, item) {

if (array[index]) {
if (array.length > index) {
array.splice(index, 0, item)

@@ -148,3 +148,3 @@ } else {

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

@@ -151,0 +151,0 @@ }

@@ -16,3 +16,3 @@ const nativeFs = require('fs')

* @test.arrange async function(input, sandbox) {
* const fs = require('a-toolbox').fs
* const fs = require('../../src/fs')
* return fs.touch('/tmp/file')

@@ -46,8 +46,8 @@ * }

* @test.case '/tmp/touch-me'
* @test.case '/none' ! new Error('EACCES')
* @test.case '/none' ! new tollo.Error({code: 'EACCES'})
* @test.assert async (result, input, output, sandbox) => {
* if(!await tester.assert.equal(result, input, output, sandbox)) {
* return false
* if(result) {
* return result.code === output.code
* }
* const fs = require('a-toolbox').fs
* const fs = require('../../src/fs')
* return fs.exists(input[0])

@@ -80,7 +80,7 @@ * }

* @test.arrange async function(input, sandbox) {
* const fs = require('a-toolbox').fs
* const fs = require('../../src/fs')
* return fs.touch('/tmp/file')
* }
* @test.case '/tmp/file'
* @test.case '/tmp/none', false ! new Error('EACCES')
* @test.case '/tmp/none', false ! new tollo.Error({code: 'ENOENT'})
* @test.case '/tmp/none', true

@@ -87,0 +87,0 @@ */

@@ -45,6 +45,6 @@ const tools = {

* @return {Object|Array}
* @todo test.case {a: 4, b: 'ciao', c: { d: 8, e: 9 }} > {a: 4, b: 'ciao', c: { d: 8, e: 9 }}
* @todo test.case {a: [4, function() { console.log('hi') }, {a1: 0, a2: null}], b: 'ciao', c: { d: 8, e: 9 }} > {a: [4, function() { console.log('hi') }, {a1: 0, a2: null}], b: 'ciao', c: { d: 8, e: 9 }}
* @test.case {a: 1, b: 'ciao'} > {a: 1, b: 'ciao'}
* @test.case {a: 4, c: { d: 8, e: 9}} > {a: 4, c: { d: 8, e: 9}}
* @test.case {a: 4, b: 'ciao', c: { d: 8, e: 9 }} > {a: 4, b: 'ciao', c: { d: 8, e: 9 }}
* @test.case {a: [4, function() { console.log('hi') }, {a1: 0, a2: null}], b: 'ciao', c: { d: 8, e: 9 }} > {a: [4, function() { console.log('hi') }, {a1: 0, a2: null}], b: 'ciao', c: { d: 8, e: 9 }}
*/

@@ -95,3 +95,3 @@ clone: function (obj) {

/**
* it use ``Object.getOwnPropertyNames`` to inherits child from parent, without prototype
* perform ``Object.assign`` if native or copy object using ``Object.getOwnPropertyNames`` to inherits child from parent, without prototype
* @method tools.object.inherits

@@ -101,5 +101,10 @@ * @todo check if both are objects

* @param {Object} source
* @test.case {}, {f0: () => { }, p1: 1, p2: 'ciao'} > &{f0: () => { }, p1: 1, p2: 'ciao'}
* @todo fix checkv isEqual test.case {}, {f0: () => { }, p1: 1, p2: 'ciao'} > &{f0: () => { }, p1: 1, p2: 'ciao'}
* @test.case {}, {p1: 1, p2: 'ciao'} > &{p1: 1, p2: 'ciao'}
*/
inherits: function (destination, source) {
if (Object.assign) {
Object.assign(destination, source)
return
}
Object.getOwnPropertyNames(source).forEach((property) => {

@@ -225,6 +230,5 @@ destination[property] = source[property]

* @param {*} val
* @test.case
* {}, 'a.b.c', 1 > &{ a: { b: {c: 1} } }
* {}, 'a', 2 > &{ a: 2 }
* {}, 'ann[0].b[1].cic', 1 > &{ ann: [{ b: [null, {cic: 1}] }] }
* @todo checkv.isEqual fail test.case {}, 'ann[0].b[1].cic', 1 > &{ ann: [{ b: [null, {cic: 1}] }] }
* @test.case {}, 'a.b.c', 1 > &{ a: { b: {c: 1} } }
* @test.case {}, 'a', 2 > &{ a: 2 }
*/

@@ -231,0 +235,0 @@ setByFlatKey: function (obj, fkey, val) {

@@ -42,2 +42,4 @@ /**

* @test.case '({cut these silly brackets please)}', ['{', '}', '(', ')'] > 'cut these silly brackets please'
* @test.case 'multiple words <li>Aliquam</li> to trim', ['multiple', 'words', 'to', 'trim', ' '] > '<li>Aliquam</li>'
* @test.case '<p><ul><li>Aliquam.</li></ul></p>', ['<p>', '</p>'] > '<ul><li>Aliquam.</li></ul>'
*/

@@ -48,3 +50,8 @@ trim: function (str, cuts) {

} else {
let _words
const _cuts = cuts.map(c => {
if (c.length > 1) {
_words = true
return c
}
if (c === '[' || c === ']') {

@@ -54,4 +61,9 @@ return '\\' + c

return c
}).join()
return str.replace(new RegExp('^[' + _cuts + ']+|[' + _cuts + ']+$', 'gm'), '')
})
if (_words) {
const _subexpression = _cuts.join('|')
return str.replace(new RegExp('^(' + _subexpression + ')+|(' + _subexpression + ')+$', 'gm'), '')
}
const _subexpression = _cuts.join()
return str.replace(new RegExp('^[' + _subexpression + ']+|[' + _subexpression + ']+$', 'gm'), '')
}

@@ -58,0 +70,0 @@ },

@@ -42,2 +42,4 @@ /**

* @test.case '({cut these silly brackets please)}', ['{', '}', '(', ')'] > 'cut these silly brackets please'
* @test.case 'multiple words <li>Aliquam</li> to trim', ['multiple', 'words', 'to', 'trim', ' '] > '<li>Aliquam</li>'
* @test.case '<p><ul><li>Aliquam.</li></ul></p>', ['<p>', '</p>'] > '<ul><li>Aliquam.</li></ul>'
*/

@@ -48,3 +50,8 @@ trim: function (str, cuts) {

} else {
let _words
const _cuts = cuts.map(c => {
if (c.length > 1) {
_words = true
return c
}
if (c === '[' || c === ']') {

@@ -54,4 +61,9 @@ return '\\' + c

return c
}).join()
return str.replace(new RegExp('^[' + _cuts + ']+|[' + _cuts + ']+$', 'gm'), '')
})
if (_words) {
const _subexpression = _cuts.join('|')
return str.replace(new RegExp('^(' + _subexpression + ')+|(' + _subexpression + ')+$', 'gm'), '')
}
const _subexpression = _cuts.join()
return str.replace(new RegExp('^[' + _subexpression + ']+|[' + _subexpression + ']+$', 'gm'), '')
}

@@ -58,0 +70,0 @@ },

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

const tester = require('tollo')
const tollo = require('tollo')
const instance = require('../../src/array.js')

@@ -7,3 +7,3 @@

describe: '',
mode: tester.mode.SYNC,
mode: tollo.mode.SYNC,
act: instance.remove,

@@ -24,7 +24,7 @@ cases: [

],
assert: tester.assert.mutation
assert: tollo.assert.mutation
},
'array.removeAt': {
describe: '',
mode: tester.mode.SYNC,
mode: tollo.mode.SYNC,
act: instance.removeAt,

@@ -49,7 +49,7 @@ cases: [

],
assert: tester.assert.mutation
assert: tollo.assert.mutation
},
'array.last': {
describe: '',
mode: tester.mode.SYNC,
mode: tollo.mode.SYNC,
act: instance.last,

@@ -81,8 +81,7 @@ cases: [

}
],
assert: tester.assert.equal
]
},
'array.at': {
describe: '',
mode: tester.mode.SYNC,
mode: tollo.mode.SYNC,
act: instance.at,

@@ -118,8 +117,7 @@ cases: [

}
],
assert: tester.assert.equal
]
},
'array.first': {
describe: '',
mode: tester.mode.SYNC,
mode: tollo.mode.SYNC,
act: instance.first,

@@ -151,8 +149,7 @@ cases: [

}
],
assert: tester.assert.equal
]
},
'array.contains': {
describe: '',
mode: tester.mode.SYNC,
mode: tollo.mode.SYNC,
act: instance.contains,

@@ -168,8 +165,7 @@ cases: [

}
],
assert: tester.assert.equal
]
},
'array.insert': {
describe: '',
mode: tester.mode.SYNC,
mode: tollo.mode.SYNC,
act: instance.insert,

@@ -187,14 +183,14 @@ cases: [

input: [['john', 'alice', 'bob'], -1, 'mary'],
output: ['john', 'alice', 'bob', 'mary']
output: ['john', 'alice', 'mary', 'bob']
},
{
input: [['john', 'alice', 'bob'], -2, 'mary'],
output: ['john', 'alice', 'mary', 'bob']
output: ['john', 'mary', 'alice', 'bob']
}
],
assert: tester.assert.mutation
assert: tollo.assert.mutation
},
'array.concat': {
describe: '',
mode: tester.mode.SYNC,
mode: tollo.mode.SYNC,
act: instance.concat,

@@ -210,8 +206,7 @@ cases: [

}
],
assert: tester.assert.equal
]
},
'array.empty': {
describe: '',
mode: tester.mode.SYNC,
mode: tollo.mode.SYNC,
act: instance.empty,

@@ -228,7 +223,7 @@ cases: [

],
assert: tester.assert.mutation
assert: tollo.assert.mutation
},
'array.add': {
describe: '',
mode: tester.mode.SYNC,
mode: tollo.mode.SYNC,
act: instance.add,

@@ -241,7 +236,7 @@ cases: [

],
assert: tester.assert.mutation
assert: tollo.assert.mutation
},
'array.flat': {
describe: '',
mode: tester.mode.SYNC,
mode: tollo.mode.SYNC,
act: instance.flat,

@@ -253,8 +248,7 @@ cases: [

}
],
assert: tester.assert.equal
]
},
'array.sortingInsert': {
describe: '',
mode: tester.mode.SYNC,
mode: tollo.mode.SYNC,
act: instance.sortingInsert,

@@ -279,7 +273,7 @@ cases: [

],
assert: tester.assert.mutation
assert: tollo.assert.mutation
},
'array.binaryIndexOf': {
describe: '',
mode: tester.mode.SYNC,
mode: tollo.mode.SYNC,
act: instance.binaryIndexOf,

@@ -299,5 +293,4 @@ cases: [

}
],
assert: tester.assert.equal
]
}
}

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

const tester = require('tollo')
const tollo = require('tollo')
const instance = require('../../src/fs.js')

@@ -7,3 +7,3 @@

describe: '',
mode: tester.mode.PROMISE,
mode: tollo.mode.PROMISE,
act: instance.exists,

@@ -24,7 +24,6 @@ cases: [

],
arrange: async function(input, sandbox) {
const fs = require('a-toolbox').fs
arrange: async function(input, sandbox) {
const fs = require('../../src/fs')
return fs.touch('/tmp/file')
},
assert: tester.assert.equal,
mocks: {

@@ -36,18 +35,18 @@ path: 'filePath'

describe: '',
mode: tester.mode.PROMISE,
mode: tollo.mode.PROMISE,
act: instance.touch,
cases: [
{
input: ['/tmp/touch-me']
input: [ '/tmp/touch-me']
},
{
input: ['/none'],
could: 'new Error("EACCES")'
throw: new tollo.Error({code: 'EACCES'})
}
],
assert: async (result, input, output, sandbox) => {
if(!await tester.assert.equal(result, input, output, sandbox)) {
return false
assert: async (result, input, output, sandbox) => {
if(result) {
return result.code === output.code
}
const fs = require('a-toolbox').fs
const fs = require('../../src/fs')
return fs.exists(input[0])

@@ -61,21 +60,20 @@ },

describe: '',
mode: tester.mode.PROMISE,
mode: tollo.mode.PROMISE,
act: instance.unlink,
cases: [
{
input: ['/tmp/file']
input: [ '/tmp/file']
},
{
input: ['/tmp/none', false],
could: 'new Error("EACCES")'
throw: new tollo.Error({code: 'ENOENT'})
},
{
input: ['/tmp/none', true]
input: [ '/tmp/none', true]
}
],
arrange: async function(input, sandbox) {
const fs = require('a-toolbox').fs
arrange: async function(input, sandbox) {
const fs = require('../../src/fs')
return fs.touch('/tmp/file')
},
assert: tester.assert.equal,
mocks: {

@@ -82,0 +80,0 @@ path: 'filePath'

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

const tester = require('tollo')
const tollo = require('tollo')
const instance = require('../../src/hash.js')

@@ -7,3 +7,3 @@

describe: '',
mode: tester.mode.SYNC,
mode: tollo.mode.SYNC,
act: instance.sha256,

@@ -19,5 +19,4 @@ cases: [

}
],
assert: tester.assert.equal
]
}
}

@@ -1,29 +0,142 @@

const tester = require('tollo')
const tollo = require('tollo')
const instance = require('../../src/object.js')
module.exports = {
'object.merge': {
describe: '',
mode: tollo.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: tollo.assert.mutation
},
'object.clone': {
describe: '',
mode: tollo.mode.SYNC,
act: instance.clone,
cases: [
{
input: [{a: 1, b: 'ciao'}],
output: {a: 1, b: 'ciao'}
},
{
input: [{a: 4, c: { d: 8, e: 9}}],
output: {a: 4, c: { d: 8, e: 9}}
}
]
},
'object.getKeys': {
describe: '',
mode: tollo.mode.SYNC,
act: instance.getKeys,
cases: [
{
input: [{a: () => { }, b: 1, c: 'ciao'}],
output: ['a','b','c']
}
]
},
'object.inherits': {
describe: '',
mode: tollo.mode.SYNC,
act: instance.inherits,
cases: [
{
input: [{}, {p1: 1, p2: 'ciao'}],
output: {p1: 1, p2: 'ciao'}
}
],
assert: tollo.assert.mutation
},
'object.empty': {
describe: '',
mode: tollo.mode.SYNC,
act: instance.empty,
cases: [
{
input: [{a:0,b:1,c:2,d:[],e:{f:-1}}],
output: {}
},
{
input: [{}],
output: {}
}
],
assert: tollo.assert.mutation
},
'object.raise': {
describe: '',
mode: tollo.mode.SYNC,
act: instance.raise,
cases: [
{
input: [{ 'a.a1': 1, 'a.a2': 2, 'b': 3 }],
output: { a: { a1: 1, a2: 2 }, b: 3 }
}
]
},
'object.flat': {
describe: '',
mode: tollo.mode.SYNC,
act: instance.flat,
cases: [
{
input: [{ a: { a1: 1, a2: 2 }, b: 3 }],
output: { 'a.a1': 1, 'a.a2': 2, 'b': 3 }
}
]
},
'object._rflat': {
describe: '',
mode: tollo.mode.SYNC,
act: instance._rflat,
cases: [
]
},
'object.walk': {
describe: '',
mode: tollo.mode.SYNC,
act: instance.walk,
cases: [
{
input: [{ a: { a1: 1, a2: 2 }, b: 3 }, 'a.a1'],
output: 1
},
{
input: [{ a: { a1: { a2: 2 } }, b: 3 }, 'a.a1.a2'],
output: 2
}
]
},
'object.getByFlatKey': {
describe: '',
mode: tollo.mode.SYNC,
act: instance.getByFlatKey,
cases: [
{
input: [{ a: { b: {c: 1} } }, 'a.b.c'],
output: 1
}
]
},
'object.setByFlatKey': {
describe: '',
mode: tester.mode.SYNC,
mode: tollo.mode.SYNC,
act: instance.setByFlatKey,
cases: [
{
input: [{}, 'a', 2],
output: { a: 2 }
},
{
input: [{}, 'a.b.c', 1],
output: { a: { b: {c: 1} } }
},
/*
{
// deep-equal in checkv fail to compare
disabled: true,
input: [{}, 'ann[0].b[1].cic', 1],
output: { ann: [{ b: [null, {cic: 1}] }] }
input: [{}, 'a', 2],
output: { a: 2 }
}
*/
],
assert: tester.assert.mutation
assert: tollo.assert.mutation
}
}

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

const tester = require('tollo')
const tollo = require('tollo')
const instance = require('../../src/random.js')

@@ -7,3 +7,3 @@

describe: '',
mode: tester.mode.SYNC,
mode: tollo.mode.SYNC,
act: instance.rnd,

@@ -34,3 +34,3 @@ cases: [

describe: '',
mode: tester.mode.SYNC,
mode: tollo.mode.SYNC,
act: instance.number,

@@ -57,3 +57,3 @@ cases: [

describe: '',
mode: tester.mode.SYNC,
mode: tollo.mode.SYNC,
act: instance.string,

@@ -63,7 +63,7 @@ cases: [

input: [8],
could: '"ajdsfchakwt"'
could: '\'ajdsfchakwt\''
},
{
input: [1, '1234567890'],
could: '"9"'
could: '\'9\''
},

@@ -97,3 +97,3 @@ {

describe: '',
mode: tester.mode.SYNC,
mode: tollo.mode.SYNC,
act: instance.hex,

@@ -103,3 +103,3 @@ cases: [

input: [8],
could: '"1bc956bf"'
could: '\'1bc956bf\''
},

@@ -135,3 +135,3 @@ {

describe: '',
mode: tester.mode.SYNC,
mode: tollo.mode.SYNC,
act: instance.hash,

@@ -141,3 +141,3 @@ cases: [

input: [],
could: '"1f8a690b7366a2323e2d5b045120da7e93896f471f8a690b731f8a690b739ab5"'
could: '\'1f8a690b7366a2323e2d5b045120da7e93896f471f8a690b731f8a690b739ab5\''
}

@@ -151,3 +151,3 @@ ],

describe: '',
mode: tester.mode.SYNC,
mode: tollo.mode.SYNC,
act: instance.element,

@@ -154,0 +154,0 @@ cases: [

@@ -1,32 +0,8 @@

const tester = require('tollo')
const tollo = require('tollo')
const instance = require('../../src/string.js')
module.exports = {
'string.replaceAll': {
describe: '',
mode: tester.mode.SYNC,
act: instance.replaceAll,
cases: [
{
input: ['repeat repeat repeat', 'repeat', 'don\'t repeat'],
output: 'don\'t repeat don\'t repeat don\'t repeat'
},
{
input: ['abcadaeafaga', 'a', ''],
output: 'bcdefg'
},
{
input: ['112233445544', '4', '9'],
output: '112233995599'
},
{
input: ['no replace all in js native code that replace all the replace', ' ', '_'],
output: 'no_replace_all_in_js_native_code_that_replace_all_the_replace'
}
],
assert: tester.assert.equal
},
'string.template': {
describe: '',
mode: tester.mode.SYNC,
mode: tollo.mode.SYNC,
act: instance.template,

@@ -54,8 +30,7 @@ cases: [

}
],
assert: tester.assert.equal
]
},
'string.trim': {
describe: '',
mode: tester.mode.SYNC,
mode: tollo.mode.SYNC,
act: instance.trim,

@@ -78,9 +53,39 @@ cases: [

output: 'cut these silly brackets please'
},
{
input: ['multiple words <li>Aliquam</li> to trim', ['multiple', 'words', 'to', 'trim', ' ']],
output: '<li>Aliquam</li>'
},
{
input: ['<p><ul><li>Aliquam.</li></ul></p>', ['<p>', '</p>']],
output: '<ul><li>Aliquam.</li></ul>'
}
],
assert: tester.assert.equal
]
},
'string.replaceAll': {
describe: '',
mode: tollo.mode.SYNC,
act: instance.replaceAll,
cases: [
{
input: ['abcadaeafaga', 'a', ''],
output: 'bcdefg'
},
{
input: ['112233445544', '4', '9'],
output: '112233995599'
},
{
input: ['repeat repeat repeat', 'repeat', 'don\'t repeat'],
output: 'don\'t repeat don\'t repeat don\'t repeat'
},
{
input: ['no replace all in js native code that replace all the replace', ' ', '_'],
output: 'no_replace_all_in_js_native_code_that_replace_all_the_replace'
}
]
},
'string.capitalize': {
describe: '',
mode: tester.mode.SYNC,
mode: tollo.mode.SYNC,
act: instance.capitalize,

@@ -100,8 +105,7 @@ cases: [

}
],
assert: tester.assert.equal
]
},
'string.prependMissing': {
describe: '',
mode: tester.mode.SYNC,
mode: tollo.mode.SYNC,
act: instance.prependMissing,

@@ -117,13 +121,11 @@ cases: [

}
],
assert: tester.assert.equal
]
},
'string.matchAll': {
describe: '',
mode: tester.mode.SYNC,
mode: tollo.mode.SYNC,
act: instance.matchAll,
cases: [
],
assert: tester.assert.equal
]
}
}

@@ -10,5 +10,4 @@ const tester = require('tollo')

cases: [
],
assert: tester.assert.equal
]
}
}

@@ -13,4 +13,3 @@ const tester = require('tollo')

}
],
assert: tester.assert.equal
]
},

@@ -25,4 +24,3 @@ 'chrono.reset': {

}
],
assert: tester.assert.equal
]
},

@@ -37,4 +35,3 @@ 'chrono.clear': {

}
],
assert: tester.assert.equal
]
},

@@ -50,4 +47,3 @@ 'chrono.get': {

}
],
assert: tester.assert.equal
]
},

@@ -59,5 +55,4 @@ 'time.gc': {

cases: [
],
assert: tester.assert.equal
]
}
}
const tester = require('tollo')
const tollo = require('tollo')
tester.start = async function () {
tollo.start = async function () {
// console.log('start')
}
tester.end = async function () {
tollo.end = async function () {
// console.log('end')
}
tester.bulk(require('./modules/object.js'))
tollo.bulk(require('./modules/array.js'))
tollo.bulk(require('./modules/fs.js'))
tollo.bulk(require('./modules/object.js'))
tollo.bulk(require('./modules/string.js'))
tollo.bulk(require('./modules/hash.js'))
tester.run()
tollo.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