lib to anonymize informations
npm install lib-anonymizationIf you need anonymize data, can use this library.
---
``sh
// with npm
npm install lib-anonymization
// with yarn
yarn add lib-anonymization
`
Here is a quick example to get you started, it's all you need:
`ts`
import { singleName } from 'lib-anonymization'
const name = "João Costa Da Silva";
console.log(singleName(name)) // print "João"
`ts`
import { generalizeCep } from 'lib-anonymization'
const cep1 = '89237130'
const cep2 = '89237-130'
/**
* Generalize CEP removes the last three numbers
* @param cep The compleat CEP as a string
*/
console.log(generalizeCep(cep1)) // print "89237000"
console.log(generalizeCep(cep2)) // print "89237-000"
`ts`
import { singleName } from 'lib-anonymization'
const name = "João Costa Da Silva";
/**
* Simplifies names removing last name
* @param name Name to simplify
*/
console.log(singleName(name)) // print "João"
`ts`
import { replaceName } from 'lib-anonymization'
const name = "João Costa Da Silva";
/**
* Replaces a part in a name
* @param name Name to replace
* @param percent Percentage over the probability of replacing a names quantity. Default is 0.5.
*/
console.log(replaceName(name)) // print "João Macedo Da Silva"
`ts`
import { nameAggregation } from 'lib-anonymization'
const name = "João Costa Da Silva";
/**
* Aggregates more info. in a name
* @param name Name to aggregate
*/
console.log(nameAggregation(name)) // print "João Costa Barros Da Silva"
`ts`
import { shuffleText } from 'lib-anonymization'
const name = "João Costa Da Silva";
/**
* Shuffle a text information
* @param text Texto to shuffle
*/
console.log(shuffleText(name)) // print "Da João Costa Silva"
`ts
import { replaceCharacter } from 'lib-anonymization'
const message = "This is confidencial information 040320";
/**
* Replaces all characters
* @param text Text to replace with other char
* @param char Character to use to replace
* @param space Default true, replace all. If false, it does not replace spaces
*/
console.log(replaceCharacter(message)) // print "*"
const message2 = "This is confidencial information 040320";
console.log(replaceCharacter(message2 'x')) // print "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
const message3 = "This is confidencial information 040320";
console.log(replaceCharacter(message3 'x', false)) // print "xxxx xx xxxxxxxxxxxx xxxxxxxxxxx xxxxxx"
`
`ts
import { replaceRandomCharacter } from 'lib-anonymization'
const message = "This is confidencial information 040320";
/**
* Replaces characters in random positions
@param text Text to replace with
@param percent Percentage over the probability of replacing the character with . Default is 0.75.
*/
console.log(replaceRandomCharacter(namemessage)) // print "Tis i c*dencl infmio 0*30"
const phone = "999339434";
console.log(replaceRandomCharacter(namemessage2, 0.2)) // print "9993944"
`
`ts`
import { simpleDataSynthetic } from 'lib-anonymization'
const input = {
name: 'João Costa Da Silva',
socialName: 'Imperatriz Água Limpa',
cpf: 'Imperatriz Água Limpa'
}
/**
* Replace a real object to synthetic object
* @param obj Object to replace
* @param keysReplace Array of keys to replace on object
* @param valueReplace Static value to replace on all keys
*/
console.log(simpleDataSynthetic(input), ['name'], 'Jão')/* print
{
name: 'Jão',
socialName: 'Imperatriz Água Limpa',
cpf: 'Imperatriz Água Limpa'
}
*/
console.log(simpleDataSynthetic(input), ['socialName'], null)/* print
{
name: 'João Costa Da Silva',
socialName: null,
cpf: 'Imperatriz Água Limpa'
}
*/
console.log(simpleDataSynthetic(input), ['name','cpf'], '*')/ print
{
name: '**',
socialName: 'Imperatriz Água Limpa',
cpf: '**'
}
*/
`ts`
import { advancedDataSynthetic } from 'lib-anonymization'
const input = {
name: 'João Costa Da Silva',
socialName: 'Imperatriz Água Limpa',
cpf: 'Imperatriz Água Limpa'
}
/**
* Replace a real object to synthetic object on the respective keys
* @param obj Object to replace
* @param keysReplace Array of keys to replace on object
* @param valuesReplace Array of values to replace on the respective keys
*/
console.log(advancedDataSynthetic(input), ['name', 'cpf'], ['jão', '*')/ print
{ name: 'jão', socialName: 'Imperatriz Água Limpa', cpf: '**' }
*/
console.log(advancedDataSynthetic(input), ['name', 'cpf'], ['*'])/ print
{
name: '**',
socialName: null,
cpf: 'Imperatriz Água Limpa'
}
`ts``
import { anonymizeObject } from 'lib-anonymization'
const input = {
name: 'João Costa Da Silva',
socialName: 'Imperatriz Água Limpa',
cpf: 123,
boolean: true,
senha: 'aaa'
}
const notReplace = new Set(['name'])
/**
Make the data object anonymous, replaces all strings with
* @param obj Object to replace
* @param notReplace Set of keys to NOT replace on object
* @param char Character to use to replace
* @param space Default true, replace all. If false, it does not replace spaces
*/
console.log(anonymizeObject(input, notReplace, '0', false)) /* print
{
name: 'João Costa Da Silva',
socialName: '0000000000 0000 00000',
cpf: 123,
boolean: true,
senha: '000'
}
*/
---
Bug reports, feature requests and other contributions are more than welcome!
Whenever possible, please make a pull request with the implementation instead of just requesting it.
---
This project is licensed under the terms of the MIT license.
---
Created and maintained by NG Informática.