npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

lib-anonymization

v1.1.0

Published

lib to anonymize informations

Downloads

461

Readme

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.