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

ice-json-generator

v1.0.0

Published

A json generator

Downloads

3

Readme

madoka Build Status

madoka is a tool to generate json data.There is provided an online editor to edit json template.editor

中文文档

Install

npm install madoka

Run Test

// install mocha first
sudo npm install mocha -g

// install dependence
npm install

// run test
npm test

Usage

var path = require('path'),
  madoka = require('modoka');


var template = [
  '{{ repeat(5,7) }}',
  {
    _id: '{{ objectId() }}',
    index: '{{ index() }}',
    guid: '{{ guid() }}',
    isActive: '{{ bool() }}',
    selfIntroduction: function(faker) {
      return 'My name is ' + this.name + '. Generate before name is parsed';
    },
    balance: '{{floating(1000, 4000, 2, "$0,0.00")}}',
    picture: '{{ image.image() }}',
    age: '{{ integer(20, 40) }}',
    eyeColor: '{{ random("blue", "brown", "green") }}',
    name: '{{ firstName() }} {{ lastName() }}',
    compay: '{{ company().toUpperCase() }}',
    phone: '{{ phone() }}',
    address: '{{ state() }}, {{ city() }}, {{ street() }}, {{ faker.address.zipCode() }}',
    registered: '{{date(new Date(2014, 0, 1), new Date(), "YYYY-MM-dd hh:mm:ss Z")}}',
    tags: [
      '{{ repeat(7) }}',
      '{{ lorem(1, "words") }}'
    ],
    greeting: function(faker) {
      return 'Hello, ' + this.name + ' You have ' + faker.integer(10, 100) + ' unread message';
    }
  }
];

console.time('build');


for(var i = 1; i < 4; i++) {
  madoka.save(template, path.join(__dirname, 'build/users/' + i + '.json'));
}

console.timeEnd('build');

Api

madoka.generate(template)

Generate json data.

  • template: data template
var template = '{{ firstName() }}';
console.log( madoka.generate(template) );   

madoka.save(template, path)

Generate json data and save to specified path.

  • template: data template
  • path: path to save file

madoka.faker

Generate fake data.

faker.faker

Instance of faker.js , you can use all the methods faker.js provided.

faker.random(arg1, arg2, arg3, ...)

returns random item from passed arguments list.

faker.integer(min, max, format)

Random integer in specified range. Can be negative.

faker.floating(min, max, fixed, format)

Random float in specified range.

faker.bool()

Random boolean value.

faker.guid()

Random globally unique identifier.

faker.objectId()

MongoDB's globally unique identifier for objects.

faker.date(min, max, format)

Random date in specified range.

  • min: Minimum date in the range. Default is new Date(1970, 0, 1).
  • max: Maximum date in the range. Default is new Date().
  • format: Date format. For more info visit http://github.com/hogart/datef

faker.lorem(count, units)

Random Lorem Ipsum text.

  • count: Number of generated units. Default is 1.
  • units: Units type. Can be words, sentences, or paragraphs. Default is sentences.

faker.firstName(gender)

Random person name of both genders if no gender is specified.

  • gender: male | female

faker.surname() | faker.lastName()

Return a last name.

faker.company()

faker.email()

faker.country()

faker.state()

faker.city()

faker.street()

faker.phone(format)

Random phone number.

  • format: Format string which contains # letters. Default is "###########".

faker.image

faker.js image object.

  • image()
  • imageUrl(width, height, category)
  • avatar()
  • abstract(width, height)
  • animals(width, height)
  • business(width, height)
  • cats(width, height)
  • city(width, height)
  • food(width, height)
  • nightlife(width, height)
  • fashion(width, height)
  • people(width, height)
  • nature(width, height)
  • sports(width, height)
  • technics(width, height)
  • transport(width, height)

faker.imagePl(width, height, options)

Returns a placeholder image link. visit http://dummyimage.com.

  • width: Image width, default is 640.
  • height: Image height, default is 480.
  • options: Image options.
// default options
{
       width: 640,
       height: 480,
       
       // array or string, background color.
       bgColor: ['CCC', 'FF9C5B', 'FAD089', 'FF9C5B', 'ED303C', '3B8183'], 
       
        // array or string,text color
       fgColor: ['333', 'FFF'],
       
       format: 'png',
       text: ''
}