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

generate-json-2

v0.1.1

Published

- [JSON Data Generator](#json-data-generator) - [1 - Generate based on datashape only](#1---generate-based-on-datashape-only) - [2 - Generate based on datashape and keys reducers](#2---generate-based-on-datashape-and-keys-reducers) - [3 - Use the cl

Downloads

1

Readme

JSON Data Generator

1 - Generate based on datashape only

const dataShape = {
    "{env}": {
      users: {
        "{userID}": {
          comment_count: "number",
          username: "string",
          is_verified: "boolean",
          created_at: "timestamp"
        }
      },
      posts: {
        "{postID}": {
          post_title: "string",
          post_data: (faker, key) => {
            // return faker.random.words(5)
            return key.split("/").join("-") + ":post_data";
          },
          author_id: "{userID}",
          created_at: "timestamp"
        }
      },
      comments: {
        "{postID}": {
          "{commentID}": {
            value: "👍",
            userID: "{userID}"
          }
        }
      }
    }
  };

const { generateJSON } = require("json-data-generator");

const { keys, values, tree } = generateJSON(schema);
console.log({ keys, values, tree });

// Will Output :
Object {
  "keys": Array [
    "G_K_dsy6q.users.G_K_sll5g.comment_count",
    "G_K_dsy6q.users.G_K_sll5g.username",
    "G_K_dsy6q.users.G_K_sll5g.is_verified",
    "G_K_dsy6q.users.G_K_sll5g.created_at",
    "G_K_dsy6q.posts.G_K_5pn02.post_title",
    "G_K_dsy6q.posts.G_K_5pn02.post_data",
    "G_K_dsy6q.posts.G_K_5pn02.author_id",
    "G_K_dsy6q.posts.G_K_5pn02.created_at",
    "G_K_dsy6q.comments.G_K_5pn02.G_K_6mami.value",
    "G_K_dsy6q.comments.G_K_5pn02.G_K_6mami.userID",
  ],
  "tree": Object {
    "G_K_dsy6q": Object {
      "comments": Object {
        "G_K_5pn02": Object {
          "G_K_6mami": Object {
            "userID": "G_K_sll5g",
            "value": "👍",
          },
        },
      },
      "posts": Object {
        "G_K_5pn02": Object {
          "author_id": "G_K_sll5g",
          "created_at": 24761311291,
          "post_data": "G_K_dsy6q.posts.G_K_5pn02.post_data:post_data",
          "post_title": "Coordinator Multi-channelled",
        },
      },
      "users": Object {
        "G_K_sll5g": Object {
          "comment_count": 29122,
          "created_at": 9213076313,
          "is_verified": false,
          "username": "Namibia enable",
        },
      },
    },
  },
  "values": Array [
    29122,
    "Namibia enable",
    false,
    9213076313,
    "Coordinator Multi-channelled",
    "G_K_dsy6q.posts.G_K_5pn02.post_data:post_data",
    "G_K_sll5g",
    24761311291,
    "👍",
    "G_K_sll5g",
  ],
}

2 - Generate based on datashape and keys reducers

const keyReducers = {
  "{env}": (fakerjs: typeof faker) => {
    return fakerjs.random.arrayElement(["prod", "staging"]);
  },
  "{userID}": (fakerjs: typeof faker) => {
    return fakerjs.random.alphaNumeric(5);
  },
  "{postID}": (fakerjs: typeof faker) => {
    return fakerjs.random.alphaNumeric(5);
  }
}

const { generateJSON } = require("json-data-generator");
const { keys, values, tree } = generateJSON(schema, keyReducers);
console.log({ keys, values, tree });

// Will Output :

Object {
  "keys": Array [
    "prod.users.sy6qs.comment_count",
    "prod.users.sy6qs.username",
    "prod.users.sy6qs.is_verified",
    "prod.users.sy6qs.created_at",
    "prod.posts.gvcl5.post_title",
    "prod.posts.gvcl5.post_data",
    "prod.posts.gvcl5.author_id",
    "prod.posts.gvcl5.created_at",
    "prod.comments.gvcl5.G_K_706z6.value",
    "prod.comments.gvcl5.G_K_706z6.userID",
  ],
  "tree": Object {
    "prod": Object {
      "comments": Object {
        "gvcl5": Object {
          "G_K_706z6": Object {
            "userID": "sy6qs",
            "value": "👍",
          },
        },
      },
      "posts": Object {
        "gvcl5": Object {
          "author_id": "sy6qs",
          "created_at": 14382625758,
          "post_data": "prod.posts.gvcl5.post_data:post_data",
          "post_title": "enable Gorgeous Frozen Pants",
        },
      },
      "users": Object {
        "sy6qs": Object {
          "comment_count": 52475,
          "created_at": 19295395373,
          "is_verified": true,
          "username": "Grocery Home",
        },
      },
    },
  },
  "values": Array [
    52475,
    "Grocery Home",
    true,
    19295395373,
    "enable Gorgeous Frozen Pants",
    "prod.posts.gvcl5.post_data:post_data",
    "sy6qs",
    14382625758,
    "👍",
    "sy6qs",
  ],
}

3 - Use the cli

Create a js file that exports schema, (and optionally keyReducers and count)

const keyReducers = {
  "{env}": fakerjs => {
    return fakerjs.random.arrayElement(["prod", "staging"]);
  },
  "{userID}": fakerjs => {
    return fakerjs.random.alphaNumeric(5);
  },
  "{postID}": fakerjs => {
    return fakerjs.random.alphaNumeric(5);
  }
};

const schema = {
  "{env}": {
    users: {
      "{userID}": {
        comment_count: "number",
        username: "string",
        is_verified: "boolean",
        created_at: "timestamp"
      }
    },
    posts: {
      "{postID}": {
        post_title: "string",
        post_data: (faker, key) => {
          // return faker.random.words(5)
          return key.split("/").join("-") + ":post_data";
        },
        author_id: "{userID}",
        created_at: "timestamp"
      }
    },
    comments: {
      "{postID}": {
        "{commentID}": {
          value: "👍",
          userID: "{userID}"
        }
      }
    }
  }
};

const count = 5;
module.exports = {
  schema,
  keyReducers,
  count
};

Then run :

  generate-json path/to/schema.js path/to/output-directory/

This will create 3 files in path/to/output-directory/ :

  • tree.json
  • keys.json
  • values.json