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

anonymizer

v0.2.2

Published

An easy way to anonymize your json. This utility can remove all field names from javascript objects.

Downloads

9

Readme

anonymizer

Build Status

Let's say you have to put a dataset on your website for your own use, but don't really want to share it to everyone. If you upload the raw, nice dataset with all the field names, people can just take it for their own use easily. You want to make it a bit harder for them to interpret the data without shooting yourself in the foot.

This anonymizer was built for that purpose:

  • Given a schema, it can easily strip out all the field names.
  • It works with nested schema, e.g., Array of Objects, Array of Objects that contains Array, and so on.
  • It can also take all categorical values and map them into integers, which are more compact and help you anonymize the data.

The library is also very lightweight (raw 3KB, minified 1KB) and supports CommonJS, AMD (RequireJS) as well as browser use.

1. Installation

Install with npm:

npm install --save anonymizer

or bower

bower install --save anonymizer

2. Usage

var anonymizer = new Anonymizer();

2.1 Basic

anonymizer.encode(data, schema)

anonymizer.encode(
  {a: 1, b: true, c: 'test'},
  {a: 'Number', b: 'Boolean', c: 'String'}
);
=> [1, true, 'test']

anonymizer.encode(
  [{a: 1, b: true, c: 'test'}, {a: 2, b: false, c: 'test2'}],
  [{a: 'Number', b: 'Boolean', c: 'String'}]
);
=> [ [1, true, 'test'], [2, false, 'test2'] ]

anonymizer.decode(data, schema)

anonymizer.decode(
  [1, true, 'test'],
  {a: 'Number', b: 'Boolean', c: 'String'}
);
=> {a: 1, b: true, c: 'test'}

anonymizer.decode(
  [ [1, true, 'test'], [2, false, 'test2'] ],
  [{a: 'Number', b: 'Boolean', c: 'String'}]
);
=> [{a: 1, b: true, c: 'test'}, {a: 2, b: false, c: 'test2'}]

2.2 Categorical values

Anonymizer can map categorical values to/from integers.

anonymizer.encode('test', 'Category');
=> 1

anonymizer.encode(['test', 'test2', 'test'], ['Category']);
=> [1, 2, 1]

anonymizer.getCategories();
=> ['test', 'test2']

// Create a new anonymizer and pass known categories
var anonymizer2 = new Anonymizer(anonymizer.getCategories());

anonymizer2.decode(1);
=> 'test'

anonymizer2.decode([1, 2, 1]);
=> ['test', 'test2', 'test']

3. Schema definition

Primitive values Use string

2
=> schema = 'Number'
'test value'
=> 'String'
true
=> schema = 'Boolean'

Categorical values Use string "Categorical"

'category1'
=> schema = 'Categorical'

Object Use curly braces and contain all the keys that you want to export. The value for each key is the type for that field.

{a: 1, b:'test', c: true}
=> schema = {a: 'Number', b: 'String', c: 'Boolean'}

Array Use square brackets and contains the type of an element. This library assume that all children of an array are of the same type, so you will define the schema for the child only once.

[1, 2, 3]
=> schema = ['Number']
['test1', 'test2']
=> schema = ['String']
['category1', 'category2']
=> schema = ['Category']

Nesting You can combine the syntax above to define any schema for you data.

Array of objects

[
  {a: 1, b: true, c: 'test'},
  {a: 2, b: false, c: 'test2'}
]
=> schema = [{a: 'Number', b: 'Boolean', c: 'String'}]

Array of arrays

[
  [1, 2, 3],
  ['a', 'b', 'c']
]
=> schema = [['Number'], ['String']]

Object that contains an array

{
  a: [1, 2, 3],
  b: ['a','b','c'],
  c: 'test'
}
=> schema = {a: ['Number'], b: ['String'], c: 'String'}

4. Testing

From the repo root:

npm install
npm test