Lib anonymization
If you need anonymize data, can use this library.
Installation
// with npm
npm install lib-anonymization
// with yarn
yarn add lib-anonymization
Usage
Here is a quick example to get you started, it's all you need:
import { singleName } from 'lib-anonymization'
const name = "João Costa Da Silva";
console.log(singleName(name))
Functions
Function generalizeCep: Removes the last three numbers.
import { generalizeCep } from 'lib-anonymization'
const cep1 = '89237130'
const cep2 = '89237-130'
console.log(generalizeCep(cep1))
console.log(generalizeCep(cep2))
Function singleName: Simplifies names removing last name;
import { singleName } from 'lib-anonymization'
const name = "João Costa Da Silva";
console.log(singleName(name))
Function replaceName: Replaces a part in a name;
import { replaceName } from 'lib-anonymization'
const name = "João Costa Da Silva";
console.log(replaceName(name))
Function nameAggregation: Aggregates more info. in a name;
import { nameAggregation } from 'lib-anonymization'
const name = "João Costa Da Silva";
console.log(nameAggregation(name))
Function shuffleText: Shuffle a text information;
import { shuffleText } from 'lib-anonymization'
const name = "João Costa Da Silva";
console.log(shuffleText(name))
Function replaceCharacter: Replaces all characters;
import { replaceCharacter } from 'lib-anonymization'
const message = "This is confidencial information 040320";
console.log(replaceCharacter(message))
const message2 = "This is confidencial information 040320";
console.log(replaceCharacter(message2 'x'))
const message3 = "This is confidencial information 040320";
console.log(replaceCharacter(message3 'x', false))
Function replaceRandomCharacter: Replaces characters in random positions;
import { replaceRandomCharacter } from 'lib-anonymization'
const message = "This is confidencial information 040320";
console.log(replaceRandomCharacter(namemessage))
const phone = "999339434";
console.log(replaceRandomCharacter(namemessage2, 0.2))
Function simpleDataSynthetic<T>: Replace a real object to synthetic object;
import { simpleDataSynthetic } from 'lib-anonymization'
const input = {
name: 'João Costa Da Silva',
socialName: 'Imperatriz Água Limpa',
cpf: 'Imperatriz Água Limpa'
}
console.log(simpleDataSynthetic(input), ['name'], 'Jão')
console.log(simpleDataSynthetic(input), ['socialName'], null)
console.log(simpleDataSynthetic(input), ['name','cpf'], '************')
Function advancedDataSynthetic<T>: Replace a real object to synthetic object;
import { advancedDataSynthetic } from 'lib-anonymization'
const input = {
name: 'João Costa Da Silva',
socialName: 'Imperatriz Água Limpa',
cpf: 'Imperatriz Água Limpa'
}
console.log(advancedDataSynthetic(input), ['name', 'cpf'], ['jão', '**')
console.log(advancedDataSynthetic(input), ['name', 'cpf'], ['**'])
Function anonymizeObject: Make the data object anonymous, replaces all strings with *.
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'])
console.log(anonymizeObject(input, notReplace, '0', false))
Contributing
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.
License
This project is licensed under the terms of the MIT license.
Maintained
Created and maintained by NG Informática.