lib-anonymization
TypeScript icon, indicating that this package has built-in type declarations

1.1.0 • Public • Published

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)) // print "João"   

Functions

Function generalizeCep: Removes the last three numbers.

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"

Function singleName: Simplifies names removing last name;

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"   

Function replaceName: Replaces a part in a name;

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"   

Function nameAggregation: Aggregates more info. in a name;

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"   

Function shuffleText: Shuffle a text information;

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"   

Function replaceCharacter: Replaces all characters;

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"

Function replaceRandomCharacter: Replaces characters in random positions;

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 "T*is i* c****denc**l inf**m**io* 0**3*0"

const phone = "999339434";
console.log(replaceRandomCharacter(namemessage2, 0.2)) // print "9993*94*4"

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'
    }
/**
 * 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: '************'
}
*/

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'
    }
/**
 * 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'
}

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'])
/**
 * 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'
}
*/   

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.

Readme

Keywords

Package Sidebar

Install

npm i lib-anonymization

Weekly Downloads

77

Version

1.1.0

License

MIT

Unpacked Size

39 kB

Total Files

10

Last publish

Collaborators

  • renanponick
  • ti-nginformatica