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-randomizer

v2.0.1

Published

Pseudo-random recursive data generator to create placeholder content in data-driven functional proofs-of-concept or design prototypes

Downloads

17

Readme

data-randomizer

Installation

npm install --save data-randomizer

Usage

const SEED = 'My example Seed asdf 1234';

let Randomizer = require('data-randomizer');

let random = Randomizer.create(SEED);

let randomId = random.integer(10000, 20000);

let randomName = random.phrase(3);

let mockProduct = {
    id: randomId(),
    name: randomName()
};

Description

This module lets you create random data with arbitrary constraints.

It is pseudo-random, so it requires an arbitrary seed value to get started. Any string will do. The purpose of the seed is to maintain consistency from one run to the next. If you don't like the data being generated, then change the seed.

It is recursive, meaning that compound data structures will be treated as one iteration of the random sequence. The purpose of the recursion is to maintain consistency among multiple items, regardless of how deep the data goes. For example, if you generate an "atomic" value such as a number after a "compound" value such as an object, even if you add key-value pairs to the object, the subsequent number will not change. This is helpful when you want to keep as much of your existing structure as possible for a given seed.

Methods

(static) create(seed: String) -> DataRandomizer

Instantiates a randomizer.

let random = Randomizer.create('abc');

number(min: Number, max: Number, step?: Number) -> Function

Creates function that returns numbers between min (inclusive) and max (exclusive) at step intervals (default 0).

let randomHeight = random.number(25, 300)

let randomPrice = random.number(0.01, 999.99, 0.01)

integer(min: Number, max: Number) -> Function

Creates function that returns random integer between min (inclusive) and max (inclusive).

boolean(split?: Number) -> Function

Creates function that returns random boolean with split probability of being true (default 0.5).

phrase(wordCount: Number|Function) -> Function

Creates function that generates string with given number of words.

sentence() -> Function

Creates function that generates random string.

paragraph() -> Function

Creates function that generates random paragraph.

date(min: Date, max: Date) -> Function

Creates function that generates random Date in given range.

choice(list: Array) -> Function

Creates function that returns random item from list.

alternative(list: Array<Function>) -> Function

Creates function that randomly selects from the list of functions to invoke. This is useful to specify a union of multiple random type constraints.

array(count: Number|Function, randomItem: Function) -> Function

Creates function that generates array of random items. The count can be a constant number or a function that generates a random number.

object(template: Object) -> Function

Creates function that generates object with structure corresponding to template.

permutation(count: Number|Function, list: Array) -> Function

Creates function that generates array of items from list of length given by count (or the length of list, whichever is less). Each item in the resulting array will be distinct.

transform

All random values can be arbitrarily transformed. For example:

const randomAnswer = random.boolean().transform(b => b ? 'yes' : 'no');