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

data-obfuscator

v1.0.2

Published

Obfuscates JSON data.

Downloads

10

Readme

Obfuscator

Code Style: Google

Obfuscator is a simple tool that replaces JSON data with random values but preserves the data structure, types, and relations.

This tool becomes handy if you have a problem with a dataset that you can't share because it contains sensitive information. Obfuscator replaces all values in this dataset with random values (not with hash values), but it will keep the structure and JSON types intact.

For example, you have the following employees.json file:

[
  {
    "id": 193,
    "department_id": 10,
    "name": "Joe Sixpack",
    "email": "[email protected]",
    "phone": "+1-234-567-890",
    "city": "New York",
    "socialSecurityNumber": "555-55-5555",
    "active": true,
    "salary": 10000
  },
  {
    "id": 220,
    "department_id": 12,
    "name": "Jane Plain",
    "email": "[email protected]",
    "city": "New York",
    "phone": "+2-345-678-901",
    "socialSecurityNumber": "777-77-7777",
    "active": false,
    "salary": 150000
  }
]

And departments.json file in the same directory:

[
  {
    "id": 10,
    "name": "HR"
  },
  {
    "id": 12,
    "name": "Sales"
  }
]

If you haven't installed Obfuscator yet, run this command:

npm install -g data-obfuscator

And then, just cd to your directory with the JSON files run obfuscate. Obfuscator will create a file per every JSON file in the directory. So, for our example, it will make employees.obfuscated.json:

[
  {
    "id": 961,
    "department_id": 87,
    "name": "J5A CIWZLao",
    "email": "[email protected]",
    "phone": "+7-514-949-061",
    "city": "X9A zUS4",
    "socialSecurityNumber": "972-82-8282",
    "active": true,
    "salary": 58635
  },
  {
    "id": 571,
    "department_id": 5,
    "name": "RIz1 X9ve0",
    "email": "[email protected]",
    "city": "X9A zUS4",
    "phone": "+5-330-447-822",
    "socialSecurityNumber": "137-42-7934",
    "active": false,
    "salary": 243046
  }
]

departments.obfuscated.json:

[
  {
    "id": 87,
    "name": "OL"
  },
  {
    "id": 5,
    "name": "JmzX0"
  }
]

And clues.json:

[
  {
    "before": 10,
    "_after": 87
  },
  {
    "before": "HR",
    "_after": "OL"
  },
  {
    "before": 12,
    "_after": 5
  },
  {
    "before": "Sales",
    "_after": "JmzX0"
  },
  {
    "before": 193,
    "_after": 961
  },
  {
    "before": "Joe Sixpack",
    "_after": "J5A CIWZLao"
  },
  {
    "before": "[email protected]",
    "_after": "[email protected]"
  },
  {
    "before": "+1-234-567-890",
    "_after": "+7-514-949-061"
  },
  {
    "before": "New York",
    "_after": "X9A zUS4"
  },
  {
    "before": "555-55-5555",
    "_after": "972-82-8282"
  },
  {
    "before": 10000,
    "_after": 58635
  },
  {
    "before": 220,
    "_after": 571
  },
  {
    "before": "Jane Plain",
    "_after": "RIz1 X9ve0"
  },
  {
    "before": "[email protected]",
    "_after": "[email protected]"
  },
  {
    "before": "+2-345-678-901",
    "_after": "+5-330-447-822"
  },
  {
    "before": "777-77-7777",
    "_after": "137-42-7934"
  },
  {
    "before": 150000,
    "_after": 243046
  }
]

The clues.json links the original values and the newly generated random values. So you can now share the two obfuscated files with your colleague and keep clues.json if you need to map the randomly generated values back to the original ones.

However, you still need to be careful with the data: the default implementation of Obfuscator preserves string lengths, spaces, dots, "at signs" (@), and a couple more symbols to keep emails, GUIDs, and text look more natural. It also doesn't change null and boolean values.