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

grunt-ipsum

v0.1.0

Published

Generate fake data, lorem ipsum, and placeholder images as JSON.

Downloads

6

Readme

grunt-ipsum Build Status Code Climate

Generate lots of fake data.

Getting Started

This plugin requires Grunt ~0.4.0

If you haven't used Grunt before, be sure to check out the Getting Started guide, as it explains how to create a Gruntfile as well as install and use Grunt plugins. Once you're familiar with that process, you may install this plugin with this command:

npm install grunt-ipsum --save-dev

Once the plugin has been installed, it may be enabled inside your Gruntfile with this line of JavaScript:

grunt.loadNpmTasks('grunt-ipsum');

Ipsum task

Run this task with the grunt ipsum command.

Task targets, files and options may be specified according to the grunt Configuring tasks guide.

Options

dest String

Path to save output file.

grunt.config('ipsum.mytask', {
	dest : 'path/to/file.json'
});

template Object|Array

The schema of fake data to generate.

For all available keys, see the docs below.

grunt.config('ipsum.mytask', {
	template : {
		name : {
			first : '{%= ipsum.firstName %}',
			last : '{%= ipsum.lastName %}',
		},
		street : '{%= ipsum.streetName %}',
		city : '{%= ipsum.city %}',
		state : '{%= ipsum.usState %}',
	}
});
// Output
{
	"name": {
		"first": "Janie",
		"last": "Mertz"
	},
	"street": "Ardith Brook",
	"city": "Hertafurt",
	"state": "Rhode Island"
}

Each value is compiled with _.template using the {% and %} delimiters. Both the grunt template and underscore.string helpers are available in this context.

grunt.config('ipsum.mytask', {
	template : {
		date : '{%= grunt.template.date(847602000000, "yyyy-mm-dd") %}',
		slug : '{%= _.slugify(ipsum.name) %}'
	}
});
// Output
{
	"date": "1996-11-09",
	"slug": "hobart-torp"
}

The current object is available via the self keyword. Note that this will only work after previous keys are set.

grunt.config('ipsum.mytask', {
	template : {
		name : '{%= ipsum.name %}',
		slug : '{%= _.slugify(self.name) %}',
		notyetdefined : '{%= self.after %}',
		after : 'needs to be before notyetdefined'
	}
});
// Output
{
	"name": "Stephen Abshire",
	"slug": "stephen-abshire",
	"notyetdefined": "",
	"after": "needs to be before notyetdefined"
}

repeat Number|Array

The number of times to repeat the template.

grunt.config('ipsum.mytask', {
	template : {
		name : '{%= ipsum.name %}'
	},
	repeat : 5
});
// Outputs
[
	{
		"name": "Lori Hegmann"
	},
	{
		"name": "Vernie Deckow"
	},
	{
		"name": "Karlee Schowalter"
	},
	{
		"name": "Mya Hahn"
	},
	{
		"name": "Colin Strosin"
	}
]

If the value is an array, the template will be repeated a random number of times between the two values.

grunt.config('ipsum.mytask', {
	template : {
		name : '{%= ipsum.name %}'
	},
	repeat : [1, 20]
});
// Outputs 1 to 20 results
[
	{
		"name": "Lori Hegmann"
	},
	// ...
	{
		"name": "Colin Strosin"
	}
]

repetitions Object

The number of times to repeat nested items.

grunt.config('ipsum.mytask', {
	template : {
		name : '{%= ipsum.name %}',
		children : {
			name : '{%= ipsum.name %}'
		}
	},
	repetitions : {
		'children' : 3
	}
});
// Outputs
{
	"name": "Rosanna Predovic",
	"children": [
		{
			"name": "Mr. Karlie Jast"
		},
		{
			"name": "Sabina Hoppe"
		},
		{
			"name": "Jordon Friesen"
		}
	]
}

This also works for deep nested paths.

grunt.config('ipsum.mytask', {
	template : {
		name : '{%= ipsum.name %}',
		children : {
			child_name : '{%= ipsum.name %}',
			friends : {
				friend_name : '{%= ipsum.name %}'
			}
		}
	},
	repetitions : {
		'children' : 2,
		'children.friends' : 3
	}
});
// Outputs
{
	"name": "Johnnie Kutch",
	"children": [
		{
			"child_name": "Ms. Charlene Jacobi",
			"friends": [
				{
					"friend_name": "Martin Hilpert"
				},
				{
					"friend_name": "Price Murray"
				},
				{
					"friend_name": "Jermain Mosciski"
				}
			]
		},
		{
			"child_name": "Barrett Connelly",
			"friends": [
				{
					"friend_name": "Mrs. Ethel Cremin"
				},
				{
					"friend_name": "Weldon Muller"
				},
				{
					"friend_name": "Aurelia Parisian"
				}
			]
		}
	]

As with the repeat option, if the value is an array, a random number will be chosen between the two values.

grunt.config('ipsum.mytask', {
	template : {
		name : '{%= ipsum.name %}',
		children : {
			name : '{%= ipsum.name %}'
		}
	},
	repetitions : {
		'children' : [1, 10]
	}
});
// Outputs
{
	"name": "Rosanna Predovic",
	"children": [ // 1 to 10 children
		{
			"name": "Mr. Karlie Jast"
		},
		// ...
		{
			"name": "Jordon Friesen"
		}
	]
}

Template keys and examples

Much of the data here is generated by Marak/Faker.js.

Users

Companies

Addresses

Images

Each of the image options can accept two parameters, width and height.

grunt.config('ipsum.mytask', {
	template : {
		thumb : '{%= ipsum.placeKitten(400, 300) %}'
	}
});
// Outputs
{
	"thumb": "http://placekitten.com/400/300"
}

If an array is used, a number will be chosen within that range.

grunt.config('ipsum.mytask', {
	template : {
		thumb : '{%= ipsum.placeKitten([10, 40], [500, 600]) %}'
	}
});
// Outputs
{
	"thumb": "http://placekitten.com/23/574"
}

The range defaults to [100, 500].

grunt.config('ipsum.mytask', {
	template : {
		thumb : '{%= ipsum.placeKitten %}'
	}
});
// Outputs
{
	"thumb": "http://placekitten.com/246/437"
}