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

structed-garbage

v0.9.7

Published

Garbage and test data generator with no dependencies that can generate random objects and arrays by defined structure

Downloads

6

Readme

structed-garbage

Garbage and test data generator with no dependencies that can generate random objects and arrays by defined structure.

Install

You can install this module by npm:

npm install structed-garbage

Usage

Firstly load module:

var garbage = require('structed-garbage');

Then you can use generator methods:

struct

Generates random data with defined structure.

Structure leafs must be defined as object: { generator: %generator-type%, params: %generator-argument% }. They will be replaced with results of random generators (they are described below).

This example generates object by defined structure:

garbage.struct({
    name: {generator: 'name'},
    birth: {generator: 'date'},
    staticValue: 'some text for example',
    staticValueMethod: {generator: 'value', params: {foo: 1, bar: 2, baz: 3}},
    likesCount: {generator: 'int', params: {min: 0, max: 10}},
    posts: [
        {
            title: {generator: 'collocation'},
            text: {generator: 'string'},
            image: {generator: 'imagePicsum', params: {width: 100, height: 100}},
            created: {generator: 'date'},
        },
        {
            title: {generator: 'collocation'},
            text: {generator: 'string'},
            image: {generator: 'imageLorempixel'},
            created: {generator: 'date'},
        },
    ],
    comments: {
        generator: 'array',
        params: {
            min: 0,
            max: 3,
            struct: {
                text: { generator: 'string' },
                date: { generator: 'date'}
            }
        }
    }
});

array

Returns random filled array. Params:

  • len - fixed length of the array
  • max - max length of the array
  • min - min length of the array
  • struct - structure of array element

This code generates array with 3 elements, that generated by different random generators (they are described below):

garbage.array({len: 3})

This example generates array with length from 0 to 5 with defined structure:

garbage.array({
    min: 0,
    max: 5,
    struct: {
        name: { generator: 'name' },
        phone: { generator: 'phone'},
        something: { generator: 'object' }
    }
});

// elements of this array will be something like this:
// {
//     name: 'Emmalynne Gabriele',
//     phone: '+45084705071',
//     something: { 
//         '+4QV*$51fIwDkG5lM': '[email protected]',
//         'Mz|uWppr8Oj}+s`ZK': 'http://lorempixel.com/200/300' 
//     } 
// }

object

Returns random filled object. Params:

  • len - fixed number of properties
  • max - max number of properties
  • min - min number of properties
  • struct - structure of element

This code generates object with 3 properties, that generated by different random generators (they are described below):

garbage.object({len: 3});

Object keys will be generated by string() method.

value

Just returns defined static value. May be useful in struct method.

garbage.value({foo: 1, bar: 2, baz: 3});

// expected: {foo: 1, bar: 2, baz: 3}

char

Returns single character.

garbage.char();

string

Returns random string. Params:

  • min - min size of string (default: 2)
  • max - max size of string (default: 20)
  • len - fixed length of the string
garbage.string({min: 10, max: 50});

int

Returns random integer. Params:

  • min - min value (default: 0)
  • max - max value (default: 500)
garbage.string({min: -100, max: 500});

bool

Returns random bool.

garbage.bool();

float

Returns random float from 0 to 1.

garbage.float();

key

Returns random key of the object or array defined as argument.

garbage.key({foo: 1, bar: 2, baz: 3});  // may be foo, bar or baz

garbage.key(['foo', 'bar', 'baz']);  // may be 0, 1 or 2

element

Returns random element of the object or array defined as argument.

garbage.element({foo: 1, bar: 2, baz: 3});  // may be 1, 2 or 3

garbage.element(['foo', 'bar', 'baz']);  // may be foo, bar or baz

collocation

Returns random string with collocation.

garbage.collocation();

// returns something like: "propitious filling station attendant"

name, firstName, lastName

Returns random string with first and/or last name.

garbage.name(); // returns something like: "Ariella Dal"
garbage.firstName(); // returns something like: "Rosalinda"
garbage.lastName(); // returns something like: "Ripley"

email

Returns random string with email.

garbage.email();

// returns something like: "[email protected]"

phone

Returns random string with something like phone number. Params:

  • len - length of the phone string without + at the start (default: 10)
garbage.phone();

// returns something like: "+05566393145"

site

Returns random string with site domain.

garbage.site();

// returns something like: "framemail.cf"

error

Returns random error object. Params:

  • min - min length in words of the text (default: 2)
  • max - max length in words of the text (default: 5)
garbage.error({min: 1, max: 7});

date

Returns random date object. Params:

  • min - min timestamp (default: 0)
  • max - max timestamp (default: Date.now())
garbage.date();

imagePicsum

Returns random image url from picsum.photos. Params:

  • heigth - heigth of the image (default: 200)
  • width - width of the image (default: 300)
garbage.imagePicsum({width: 100, height: 150});

imageLorempixel

Returns random image url from lorempixel.com. Params:

  • heigth - heigth of the image (default: 200)
  • width - width of the image (default: 300)
garbage.imageLorempixel({width: 100, height: 150});

text

Returns random text (lorem ipsum). Params:

  • min - min length in words of the text (default: 1)
  • max - max length in words of the text (default: end of lorem ipsum text)
  • len - fixed length of the text in words
garbage.text({len: 10});