const{waitForCondition}=require('sat-utils')waitForCondition.setDefaultOpts({timeout: 2500,// default waiting time is 2500 msinterval: 250,// default re-check condition interval time is 250 msmessage: 'Failed',// default error message is "Failed"waiterError: TypeError,// default error is TypeError});test()asyncfunctiontest(){awaitwaitForCondition(async()=>{constresult=awaitsomeAsyncLogic()returnresult;})}test1()asyncfunctiontest1(){awaitwaitForCondition(async()=>{constresult=awaitsomeAsyncLogic()returnresult;},{analyseResult: (result)=>result.status===200;
timeout: 25000,interval: 250,message: (time)=>thrownewError(`My custom error throw function with time ${time}`)})}
getRandomArrayItem
const{ getRandomArrayItem }=require('sat-utils');constfirstItem=getRandomArrayItem([1,2,3,4]);// 2const[first,second]=getRandomArrayItem([1,2,3,4],2);// [3, 1]getRandomArrayItem([1,2,3,4],10);// => RangeError('getRandomArrayItem(): more elements taken ...getRandomArrayItem([]);// => RangeError('getRandomArrayItem(): given array is empty')getRandomArrayItem(null);// => TypeError 'getRandomArrayItem(): first argument should be an')
const{ shuffleArr }=require('sat-utils');constarr1=shuffleArr([2,3,1]);// [1,3,2]shuffleArr({});// TypeError 'shuffleArr(): first argument should be an array ...'
shuffleArrMutable
const{ shuffleArrMutable }=require('sat-utils');constarr=[1,2,3,4,5];shuffleArrMutable(arr);console.log(arr);// [ 5, 2, 4, 1, 3 ]shuffleArrMutable({});// TypeError 'shuffleArr(): first argument should be an array ...'
const{ execNumberExpression }=require('sat-utils');constisTruly=execNumberExpression('>10',11);// trueconstisTruly1=execNumberExpression('>10 and <12',11);// trueconstisTruly2=execNumberExpression('>10 and <13 and !== 12',11);// trueconstisTruly3=execNumberExpression('<9',11);// falseconstisTruly4=execNumberExpression('!==11',11);// false
compareToPattern
const{ compareToPattern }=require('sat-utils');//{constdata={a: {text: 'first'},b: {c: {d: {text: 'second'}}},};constpattern={b: {c: {d: {text: /.*/}}},};const{ result, message }=compareToPattern(data,pattern);// result is true, message is ''}{constdata={a: {text: 'first'},b: {c: {d: {text: 'second'}}},};constpattern={b: {c: {d: {text: 'second'}}},};const{ result, message }=compareToPattern(data,pattern);// result is true, message is ''}{constdata={a: {text: 'first'},b: {c: {d: {text: 'first'}}},};constpattern={b: {c: {d: {text: 'second'}}},};const{ result, message }=compareToPattern(data,pattern);// result is false, message is 'b->c->d->text->Message: expected: second, actual: first'}{constdata={a: {text: 'first'},b: {c: [{d: [{text: 'first'}]}]},};constpattern={b: {c: {d: {text: 'second'}}},};const{ result, message }=compareToPattern(data,pattern);// result is false, message is 'b->c->d[0]->text[0]->Message: expected: second, actual: first'}{constdata={a: {text: 'first'},b: {c: [{d: [{text: 'first'}]}]},};constpattern={b: {c: {length: 3,d: {text: 'second'}}},};const{ result, message }=compareToPattern(data,pattern);// result is false, message is 'false b->c->Message: expected length: 3, actual lenght: 1'}{constdata={a: {text: 'first'},b: {c: [{d: [{text: 'first 1'},{text: 'first 2'},{text: 'first 3'}]}]},};constpattern={b: {c: {d: {text: 'first'}}},};const{ result, message }=compareToPattern(data,pattern,{stringIncludes: true,});// result is true, message is ''}{constdata={a: {text: 'first'},b: {c: [{d: [{text: 'first 1'},{text: 'first 2'},{text: 'first 3'}]}]},};constpattern={b: {c: {d: {text: 'first 2'}}},};const{ result, message }=compareToPattern(data,pattern,{everyArrayItem: false,});// result is true, message is ''}{constdata={a: {text: 'first'},};constpattern={a: {text: compareToPattern.patternToLowercase('FIRST')},};const{ result, message }=compareToPattern(data,pattern);// result is true, message is ''}{constdata={a: {text: 'FIRST'},};constpattern={a: {text: compareToPattern.dataToUppercase('first')},};const{ result, message }=compareToPattern(data,pattern);// result is true, message is ''}{constdata={a: {text: 'FIRST'},};constpattern={a: {text: compareToPattern.patternToUppercase('first')},};const{ result, message }=compareToPattern(data,pattern);// result is true, message is ''}
getDirFilesList
const{ getDirFilesList }=require('sat-utils');constfiles=getDirFilesList('./node_modules');// all absolute file pathes in node_module folder