1.1.0 • Published 2 years ago

lib-anonymization v1.1.0

Weekly downloads
-
License
MIT
Repository
-
Last release
2 years ago

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\: 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\: 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.

1.1.0

2 years ago

1.0.15

2 years ago

1.0.9

4 years ago

1.0.8

4 years ago

1.0.7

4 years ago

1.0.11

4 years ago

1.0.10

4 years ago

1.0.14

4 years ago

1.0.13

4 years ago

1.0.12

4 years ago

1.0.6

4 years ago

1.0.5

4 years ago

1.0.4

4 years ago

1.0.3

4 years ago

1.0.2

4 years ago

1.0.1

4 years ago