Comparing version 1.0.3 to 1.0.4
{ | ||
"name": "js-awe", | ||
"version": "1.0.3", | ||
"version": "1.0.4", | ||
"description": "", | ||
"type": "module", | ||
"main":"src/index.js", | ||
"types":"types/index.d.ts", | ||
"main": "src/index.js", | ||
"types": "types/index.d.ts", | ||
"scripts": { | ||
@@ -22,3 +22,3 @@ "test": "npm run testUT", | ||
"loglevel": "^1.8.0", | ||
"node-fetch": "^3.2.9", | ||
"node-fetch": "^3.2.10", | ||
"ramda": "^0.28.0", | ||
@@ -25,0 +25,0 @@ "stream": "^0.0.2", |
# js-awe | ||
javascript utilities and extensions | ||
## Generating types | ||
The library offer typescript types in ./types/ for the consumer. Currently only the main functions are typed in detail. | ||
To generate types: | ||
tsc -p tsconfig.json | ||
This will output types in ./genTypes then we will need to copy the new type definitions into ./types/ . This is to keep the documentation that was already manually generated. | ||
## publishing lib to npm | ||
Change the version of the library in package.json version field. npm forces that each version published to have a unique version value. | ||
npm publish |
@@ -7,3 +7,22 @@ | ||
const lengthSanitizer = (_, value) => '*length=' + value.length + '*' | ||
const lengthSanitizer = (_, value) => { | ||
if(typeof value !== 'string' || value.length < 1) return value | ||
const lengthString = 'length=' + value.length | ||
if(value.length >= lengthString.length) { | ||
const numberOfRightAsteriscs = Math.floor((value.length - lengthString.length) / 2) | ||
return lengthString | ||
.padEnd( | ||
lengthString.length + numberOfRightAsteriscs, '*' | ||
) | ||
.padStart(value.length, '*') | ||
} | ||
return ''.padEnd(value.length,'*') | ||
} | ||
const bearerSanitizer = (_, bearerToken) => bearerToken.substring(0, 7) + lengthSanitizer(undefined, bearerToken.substring(7)) | ||
@@ -10,0 +29,0 @@ |
import { strict as assert } from 'assert' | ||
import { sanitize } from '../src/sanitizer.js' | ||
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', () => { | ||
@@ -10,3 +61,3 @@ | ||
{ | ||
truken: 'bearer 123456' | ||
truken: 'bearer 123456789012' | ||
} | ||
@@ -18,3 +69,3 @@ } | ||
{ | ||
truken: 'bearer *length=6*' | ||
truken: 'bearer **length=12*' | ||
} | ||
@@ -38,3 +89,3 @@ } | ||
{ | ||
truken: 'bearer *length=6*' | ||
truken: 'bearer ******' | ||
} | ||
@@ -58,3 +109,3 @@ } | ||
{ | ||
authorization: 'bearer *length=6*' | ||
authorization: 'bearer ******' | ||
} | ||
@@ -78,3 +129,3 @@ } | ||
{ | ||
authorization: '*length=6*' | ||
authorization: '******' | ||
} | ||
@@ -91,3 +142,3 @@ } | ||
{ | ||
authorization: '1234567' | ||
authorization: '123456789' | ||
} | ||
@@ -99,3 +150,3 @@ } | ||
{ | ||
authorization: '*length=7*' | ||
authorization: '*length=9' | ||
} | ||
@@ -119,3 +170,3 @@ } | ||
{ | ||
body: '*length=6*' | ||
body: '******' | ||
} | ||
@@ -147,3 +198,3 @@ } | ||
other: { | ||
token: '*length=19*', | ||
token: '*****length=19*****', | ||
other: { | ||
@@ -154,3 +205,3 @@ fin: 'Bearer *length=11*', | ||
}, | ||
body: '*length=6*' | ||
body: '******' | ||
} | ||
@@ -163,2 +214,36 @@ } | ||
it('Sanitize calling with my own sanitizer definition and a pre-created sanitizer group', () => { | ||
const input = { | ||
body: | ||
{ | ||
name: 'Jose Marin', | ||
address: '25 Melrose place', | ||
addressId: 2, | ||
customer: 'F54615234', | ||
date: '2022-08-19' | ||
} | ||
} | ||
const mySanitizer = [ | ||
{ field: 'address', replacer: lengthSanitizer }, | ||
{ field: 'name', replacer: lengthSanitizer } | ||
] | ||
const inputListOfSanitizers = [mySanitizer, 'pushNotification'] | ||
const expected = { | ||
body: | ||
{ | ||
name: '*length=10', | ||
address: '****length=16***', | ||
addressId: 2, | ||
customer: 'Flength=8', | ||
date: '2022-08-19' | ||
} | ||
} | ||
const result = sanitize(input, inputListOfSanitizers) | ||
assert.deepStrictEqual(result, expected) | ||
}) | ||
}) |
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
20
153292
46
4577
Updatednode-fetch@^3.2.10