Comparing version 1.0.6 to 1.0.7
{ | ||
"name": "js-awe", | ||
"version": "1.0.6", | ||
"version": "1.0.7", | ||
"description": "", | ||
@@ -5,0 +5,0 @@ "type": "module", |
@@ -80,3 +80,14 @@ import { resolve } from 'fluture' | ||
} | ||
function areRelativeFrom(ancestorInCommon) | ||
{ | ||
if(ancestorInCommon === undefined || ancestorInCommon.length === 0) return false | ||
return familyMember1 => familyMember2 => | ||
_.isEqual(ancestorInCommon, familyMember1?.slice(0, ancestorInCommon.length)) && | ||
_.isEqual(ancestorInCommon, familyMember2?.slice(0, ancestorInCommon.length)) | ||
} | ||
areRelativeFrom([0,0])([0,0,0,0])([0,0]) //? | ||
const stackSiblingsReducer = | ||
@@ -107,25 +118,50 @@ (acum, el, index) => { | ||
let accruingParallel = false | ||
let funsToParallelize = [] | ||
let stackItemsToParallelize = [] | ||
return (acum, el, index, stack) => { | ||
const elParent = el.path.slice(0,-1) | ||
const nextElParent = stack[index+1]?.path?.slice(0,-1) | ||
const elGrandparent = elParent?.slice(0,-1) | ||
const nextToEl = stack[index+1]?.path | ||
const nextToElParent = nextToEl?.slice(0,-1) | ||
const nextToElGrandparent = nextToElParent?.slice(0,-1) | ||
const previousToEl = stack[index-1]?.path | ||
const previousToElGrandparent = previousToEl?.slice(0,-2) | ||
let isElToAccrue = | ||
_.isEqual(elParent?.slice(0,-1), nextElParent?.slice(0, -1)) && | ||
R.last(elParent) + 1 === R.last(nextElParent) && | ||
el.path.length >= 3 && | ||
_.isEqual(elGrandparent, nextToElGrandparent) && | ||
// el is the only child of parent | ||
_.isEqual(getDescendants(stack)(elParent), [el]) | ||
_.isEqual(getDescendants(stack)(elParent), [el]) && | ||
// If previous was not accrued we dont want this to be desdendent of the current grandParent unless previous | ||
// is a brother of the parent (function header of subsequent parellel functions). | ||
( | ||
accruingParallel || | ||
isAncestorOf(previousToEl)(elGrandparent) === false || | ||
( isAncestorOf(previousToEl)(elGrandparent) === true && previousToEl.length < el.path.length ) | ||
) | ||
if(isElToAccrue) | ||
if(isElToAccrue === true) | ||
{ | ||
accruingParallel = true | ||
funsToParallelize.push(el.value) | ||
stackItemsToParallelize.push(el) | ||
} | ||
if(isElToAccrue === false && accruingParallel === true) { | ||
funsToParallelize.push(el.value) | ||
// In cases we stopped because next element even though have the grandParent as ancestor but is more | ||
// nested than our current parallelization, then we need to cancel accruing and restore all elements to acum. | ||
if( isAncestorOf(nextToEl)(elGrandparent) && nextToEl?.length > el.path.length ) | ||
{ | ||
acum.push(...stackItemsToParallelize) | ||
acum.push(el) | ||
accruingParallel = false | ||
stackItemsToParallelize = [] | ||
return acum | ||
} | ||
// Rest of cases we need to follow with parallelization including current element. | ||
stackItemsToParallelize.push(el) | ||
acum.push( | ||
{ | ||
value: runFunctionsSyncOrParallel(numberOfThreads)(funsToParallelize), | ||
value: runFunctionsSyncOrParallel(numberOfThreads)(R.pluck('value',stackItemsToParallelize)), | ||
path: el.path.slice(0,-1) | ||
@@ -144,3 +180,3 @@ } | ||
accruingParallel = false | ||
funsToParallelize = [] | ||
stackItemsToParallelize = [] | ||
} | ||
@@ -147,0 +183,0 @@ |
@@ -222,2 +222,119 @@ import { strict as assert } from 'assert' | ||
it('Plan without promise and complex nesting', () => { | ||
const result= plan( | ||
[ | ||
[ | ||
[ | ||
x => x + 1 | ||
], | ||
x => x + 1 | ||
], | ||
[ | ||
x => x + 1 | ||
], | ||
[ | ||
x => x + 1 | ||
] | ||
] | ||
)(1) | ||
assert.deepStrictEqual( | ||
result, | ||
[3,2,2] | ||
) | ||
}) | ||
it('Plan without promise and complex nesting', () => { | ||
const result= plan( | ||
[ | ||
[ | ||
[ | ||
[ | ||
[ | ||
x => x + 1 | ||
] | ||
] | ||
], | ||
[ | ||
x => x + 1 | ||
] | ||
], | ||
([x1,x2]) => x1 + x2, | ||
[ | ||
x => x + 1 | ||
], | ||
[ | ||
x => x + 1 | ||
] | ||
] | ||
)(1) | ||
assert.deepStrictEqual( | ||
result, | ||
[5,5] | ||
) | ||
}) | ||
it('Plan without promise and complex nesting', () => { | ||
const result= plan( | ||
[ | ||
[ | ||
[ | ||
[ | ||
[ | ||
x => x + 1 | ||
] | ||
] | ||
], | ||
[ | ||
x => x + 1 | ||
] | ||
], | ||
[ | ||
x => x + 1 | ||
], | ||
[ | ||
x => x + 1 | ||
], | ||
[ | ||
x => x + 1 | ||
] | ||
] | ||
)(1) | ||
assert.deepStrictEqual( | ||
result, | ||
[[2,2],2,2,2] | ||
) | ||
}) | ||
it('Plan without promise and complex nesting', () => { | ||
const result= plan( | ||
[ | ||
[ | ||
x => x + 1 | ||
], | ||
[ | ||
x => x + 1 | ||
], | ||
[ | ||
x => x + 1 | ||
], | ||
[ | ||
[x => x + 1] | ||
], | ||
[ | ||
x => x + 1 | ||
] | ||
] | ||
)(1) | ||
assert.deepStrictEqual( | ||
result, | ||
[2,2,2,2,2] | ||
) | ||
}) | ||
}) |
import { strict as assert } from 'assert' | ||
import { sanitize, lengthSanitizer } from '../src/sanitizer.js' | ||
describe('lenghtSanitizer', () => { | ||
it('Long string sanitizer with more padding on the left. size string > 8', () => { | ||
assert.deepStrictEqual( | ||
lengthSanitizer(undefined, | ||
'more padding on left'), | ||
'******length=20*****' | ||
) | ||
}) | ||
it('Long string sanitizer with equal padding on both sides. size string > 8', () => { | ||
assert.deepStrictEqual( | ||
lengthSanitizer(undefined, | ||
'same size padding'), | ||
'****length=17****' | ||
) | ||
}) | ||
it('long sanitizer without padding. size string 8', () => { | ||
assert.deepStrictEqual( | ||
lengthSanitizer(undefined, | ||
'this car'), | ||
'length=8' | ||
) | ||
}) | ||
it('short string sanitizer. size string 7', () => { | ||
assert.deepStrictEqual( | ||
lengthSanitizer(undefined, | ||
'address'), | ||
'*******' | ||
) | ||
}) | ||
it('zero size string', () => { | ||
assert.deepStrictEqual( | ||
lengthSanitizer(undefined, | ||
''), | ||
'' | ||
) | ||
}) | ||
it('input is not a string', () => { | ||
assert.deepStrictEqual( | ||
lengthSanitizer(undefined, | ||
['member1', 'member2']), | ||
['member1', 'member2'] | ||
) | ||
}) | ||
}) | ||
describe('Sanitize an Object', () => { | ||
@@ -238,2 +187,53 @@ | ||
}) | ||
}) | ||
describe('lenghtSanitizer', () => { | ||
it('Long string sanitizer with more padding on the left. size string > 8', () => { | ||
assert.deepStrictEqual( | ||
lengthSanitizer(undefined, | ||
'more padding on left'), | ||
'******length=20*****' | ||
) | ||
}) | ||
it('Long string sanitizer with equal padding on both sides. size string > 8', () => { | ||
assert.deepStrictEqual( | ||
lengthSanitizer(undefined, | ||
'same size padding'), | ||
'****length=17****' | ||
) | ||
}) | ||
it('long sanitizer without padding. size string 8', () => { | ||
assert.deepStrictEqual( | ||
lengthSanitizer(undefined, | ||
'this car'), | ||
'length=8' | ||
) | ||
}) | ||
it('short string sanitizer. size string 7', () => { | ||
assert.deepStrictEqual( | ||
lengthSanitizer(undefined, | ||
'address'), | ||
'*******' | ||
) | ||
}) | ||
it('zero size string', () => { | ||
assert.deepStrictEqual( | ||
lengthSanitizer(undefined, | ||
''), | ||
'' | ||
) | ||
}) | ||
it('input is not a string', () => { | ||
assert.deepStrictEqual( | ||
lengthSanitizer(undefined, | ||
['member1', 'member2']), | ||
['member1', 'member2'] | ||
) | ||
}) | ||
}) |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
159069
4796