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 🙏

© 2026 – Pkg Stats / Ryan Hefner

datafixture.js

v0.1.3

Published

generate mock data objects

Downloads

2

Readme

#datafixture.js#

Generates random data based on a defined template model.

jsfiddle example implementing all of its features:

http://jsfiddle.net/acatl/fmvEj/

Jasmine tests results

http://jsfiddle.net/acatl/D2vmE/embedded/result/

Method: DataFixture.generate

DataFixture.generate(templateObject, numberOfResults);

templateObject is an object with at least one property.

numberOfResults is the number of results we want to be generated, if numberOfResults is == 0 it outputs an object. if > 0 it outputs an array of objects.

Examples

Generate an object with a randomly set numeric property

var template = {
	like: "0...100" /* generate a number between 0 an 100, with no decimals */
};
DataFixture.generate(template, 0);

// possible output
{
	like: 23
}

Generate an Array with a randomly set numeric property

var template = {
	like: "0...100" /* generate a number between 0 an 100, with no decimals */
};
DataFixture.generate(template, 20); /* second parameter indicates the number of elements */

// possible output
[
	{like: 23},
	{like: 3},
	{like: 2},
	{like: 22},
	{like: 10},
	...
]

Generate numbers with decimals

var template = {
	like: "0...100:2" /* generate a number between 0 an 100, with 2 decimals */
};
DataFixture.generate(template, 0);

// possible output
{
	like: 12.69
}

Generate a string from a defined set of values

var template = {
	names: ["Ian","Polo", "Oscar", "Fabien", "Rafael"] /* Create string with any of the values from the array */
};
DataFixture.generate(template, 0);

// possible output
{
	names: "Rafael"
}

Generate a string from a defined set of values with mixed types

var template = {
	names: ["Ian",2, 10.4, true, "Andros"] /* Create string with any of the values from the array */
};
DataFixture.generate(template, 0);

// possible output
{
	names: 10.4
}

One level template

var template = {
	score: "0...100:2" /* generate a number between 0 an 100, with 2 decimals */
	names: ["Paula", "Darek", "Ian", "Monica", "Andros", "Kenji"] /* Create string with any of the values from the array */
};
DataFixture.generate(template, 6);

// possible output
[
	{score: 45.67,	names: "Andros"},
	{score: 5.73,	names: "Ian"},
	{score: 34.45,	names: "Paula"},
	{score: 53.76,	names: "Darek"},
	{score: 99.28,	names: "Monica"},
	{score: 0.12,	names: "Kenji"}
]

Nested levels template

var template = {
	values: "0...100:2", 
	names: ["Ian",2, 10.4, true, "Andros"], 
	complex: {
		PO:"20000...30000",
		country: ["Mexico", "Canada", "US"]
	}
};
DataFixture.generate(template, 0);

// possible output
{
	names: 10.4,
	values: 13.78,
	complex: {
		PO: 27882,
		country: "Canada"
	}
}

Nested template with more than one result

var template = {
	values: "0...100:2", 
	names: ["Ian",2, 10.4, true, "Andros"], 
	complex: {
        // '#' is a reserved property name, indicates number of instances
		'#': '1...3', // this will generate from 1 to 3 array elements
		PO:"20000...30000",
		country: ["Mexico", "Canada", "US"]
	}
};
DataFixture.generate(template, 0);

// possible output
{ values: 97.62,
  names: 10.4,
  complex: 
   [ { PO: 22468, country: 'US' },
     { PO: 27431, country: 'Canada' },
     { PO: 20893, country: 'Canada' },
     { PO: 25644, country: 'Canada' } ] 
}

Values of properties can also be functions

var df = DataFixture.generate({
	coordinates:function(){
		return DataFixture.getRandom(0,30) + ":" + DataFixture.getRandom(0,15);
	}
},10);

// possible output
[ { coordinates: '15:7' },
  { coordinates: '14:11' },
  { coordinates: '19:15' },
  { coordinates: '15:9' },
  { coordinates: '17:2' },
  { coordinates: '25:3' },
  { coordinates: '4:1' },
  { coordinates: '12:9' },
  { coordinates: '15:2' },
  { coordinates: '7:8' } ]

Create Lorem Ipsum paragraphs with random lengths

var x = DataFixture.generate({
	// you may define the range of possible words to use
	// this case: from 1 to 3 words, if omitted it will by default "1...10"
	"lorem": "lorem:1...3"
}, 10);

//output
[ { lorem: 'Lorem' },
  { lorem: 'Lorem ipsum' },
  { lorem: 'Lorem ipsum' },
  { lorem: 'Lorem ipsum' },
  { lorem: 'Lorem ipsum dolor' },
  { lorem: 'Lorem ipsum' },
  { lorem: 'Lorem' },
  { lorem: 'Lorem ipsum dolor' },
  { lorem: 'Lorem' },
  { lorem: 'Lorem ipsum' } ]

Multiple values on a string

note: currently only support string, lorem, or numeric ranges

var x = DataFixture.generate({
    // use pipes | to separate each value
    "time": "1...24|:|0...59|:|0...59"
}, 10);

//output
[ { time: '15:53:36' },
  { time: '13:54:7' },
  { time: '4:37:46' }
]

enjoy!

All feedback is welcomed