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

random-world-cli

v1.0.6

Published

Command line tools to generate bulk files containing mocked data from the random-world library.

Downloads

11

Readme

Random World CLI.

CLI tools for generating real-looking random data using the random-world NPM library.

Quickly generate large flat files of "real looking" data (CSV, SQL insert scripts, unstructured text files) using the random-world library. Files can be generated on disk, or the output piped via stdout to any other programs.

Installing:

npm install -g random-world-cli

This will install the library to your $PATH so you can generate files from any directory.

Random World

All documentation for the methods exposed by the random-world library can be found on its GitHub page.

Basics:

Arguments that create random-goodness are passed to the program using namespace.method syntax e.g.

random-world-cli names.title, names.fullname, places.city -r 5

This will output 5 rows (-r 5) consisting of a person's title (names.title), their full name (names.fullname) and a city (places.city):

Miss, Adella Avery, Madaba
Mr, Freddie Karr, Liberia
Miss, Kaylene Odell, Delmar
Ms, Laronda Tate, Longyearbyen
Mrs, Esta Hutto, Monte Carlo

Passing arguments to random-world methods

Most RW methods accept arguments - these are passed into the library using the CLI interface by wrapping the args in square braces. The entire namespace/method must be wrapped in single quotes when providing arguments.

random-world-cli 'numbers.integer[max: 2000]', 'places.city[country: France]' -r 5

This will output 5 rows comprising of a random number with a limit of 2000, and a city limited to France:

1639, Maurecourt
1147, Saint-Germain-de-la-Grange
1913, Rosieres-aux-Salines
889, Rainneville
97, Morlaix

CLI Options

| Option | Short Option | Description | Options | | ------------- |:-------------:| -----:| ---------:| | ̵̵format | -f | Output formats | stdout⎮csv⎮sql⎮text | | ̵̵rows | -r | Number of rows to output | - | | ̵̵output | -o | File to write to | - | | ̵̵headers | -h | Headers for CSV files | Split with commas | | ̵̵columns | -c | Columns for SQL outputs | Split with commas | | ̵̵table | -t | Table name for inserting into when using SQL option | - |

None RW values

Any arguments passed into the library that cannot be resolved as a random-world method will be output to the stream as-is. For example:

random-world-cli numbers.integer, 'some random value', places.city -r 5

Outputs a random number (numbers.integer), the unresolvable string some random value, and a random city name places.city.

2225531, some random value, Cerknica
6225652, some random value, Bamako
8112931, some random value, Marigot
4795959, some random value, Skala
5756085, some random value, Saipan

Escaping/Value Wrapping

The program will attempt to escape values according to the output type and the type of the value. For example, a SQL output will wrap strings in quotes and leave ints/longs as the native value.

Types - CSV

The most common use-case for this program was to generate CSVs. The -f --format flag must be set to csv. Optionally, the -h --headers flag can be provided that will append the column headers (names) to the start of the CSV. Headers must be wrapped in single quotes and split by commas.

When the --headers flag is provided, the number of arguments provided must match the headers count.

Types - SQL

Bulk insert statements can also be generated for importing dummy data into SQL tables. When the -f --format flag is set to sql, the -t --table and -c --columns parameters must be provided. The columns provided must have the same count as the number of arguments the program will generate, otherwise an error will be raised.

random-world-cli names.fullname, 'numbers.integer[max: 100]', places.street, places.city -r 5 -f sql --columns "name, age, address, city" --table tbl_People

INSERT INTO tbl_People (name, age, street, city) VALUES ("Jerold Schwartz", 99, "69 Eat Avenue", "Port-aux-Francais");
INSERT INTO tbl_People (name, age, street, city) VALUES ("Leeann Padgett", 38, "147 Doctor Quay", "Piaski");
INSERT INTO tbl_People (name, age, street, city) VALUES ("Lorie Vest", 22, "133 Fine Mews", "Cotonou");
INSERT INTO tbl_People (name, age, street, city) VALUES ("Stephania Evans", 27, "123 With Crescent", "Koper");
INSERT INTO tbl_People (name, age, street, city) VALUES ("Tawna Ho", 2, "60 Slow Mews", "Gaborone");

Types - stdout

If the -o --output flag is not set, the data will be piped straight to stdout. This is useful for testing before writing files, or using to pipe to another program. For example. this output of 1000 names can be easily passed to grep.

random-world-cli names.fullname -r 10000 | grep Dave

Leon **Dave**nport
**Dave** Mccain
**Dave** **Dave**nport
**Dave** Kovach