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

@benjamin-vanryseghem/mongoose-dummy

v1.0.9

Published

Mongoose dummy data generator

Downloads

8

Readme

mongoose-dummy 1.0.4

mongoose-dummy is an automatic dummy object generator for mongoose using only the schema definition built for Node.js.

Installation

  • Latest release:

    npm install mongoose-dummy

Usage

dummy(model, opts)

Generates dummy object from model

  • model: Mongoose schema object
  • opts: Generation options, where the options are in the following format:
        {
          ignore: Array,
          autoDetect: Boolean,
          applyFilter: Boolean,
          returnDate: Boolean,
          resolveRef: Function,
          maxDepth: Number,
          custom: {
             email: [String, Array, Object],
             phone: [String, Array, Object],
             password: [String, Array, Object]
          }
        }

| Option | Type | Usage | | :------: | ------ | ------ | | ignore | Array | It can contains string paths or RegExp of fields to ignore during generation | | autoDetect | Boolean | Attempt to detect e-mail, phone, or password and generate corresponding random data, defaults to true | | applyFilter | Boolean | Apply lowercase, uppercase, and trim filters on generated object if defined in the path | | returnDate | Boolean | Weather to return dates as Date or String | | resolveRef | Function | Function taking a schema ref as arguments, and returning the absolute path to its schema file | | maxDepth | Number | Maximum depth for recursive ref resolution. Default to 10. | | custom | Object | Special generator for specified fields | | custom.email | String, Array, or Object | String (field to generate a random e-mails), Array of Strings (fields to generate a random e-mail), or Object {field: String or Array of String, value: Function (custom generator function)} | custom.phone | String, Array, or Object | String (field to generate a random phones), Array of Strings (fields to generate a random phone), or Object {field: String or Array of String, value: Function (custom generator function)} | custom.password | String, Array, or Object | String (field to generate a random passwords), Array of Strings (fields to generate a random password), or Object {field: String or Array of String, value: Function (custom generator function)} | force | Object | paths to set it to certain values |

dummy.getPaths(model)

Helper function to extract all paths definition from model.

Usage Example

const mongoose = require('mongoose');
const dummy = require('mongoose-dummy');
const ignoredFields = ['_id','created_at', '__v', /detail.*_info/];
let genderValues = ['Male', 'Female']
let schemaDefinition = new mongoose.Schema({
    name: {
        type: String,
        required: true,
        lowercase: true,
        trim: true
    },
    email: {
        type: String,
    },
    birth_date: {
        type: Date
    },
    gender: {
        type: String,
        enum: genderValues
    },
    data: {
        type: Object,
        default: null
    },
    results: [
        {
            score: Number,
            course: Number
        }
    ],
    is_student: {
        type: Boolean
    },
    parent: {
        type: mongoose.Schema.Types.ObjectId
    },
    detail: {
        main_info: String,
        some_info: String,
        none_match: String
    },
    created_at: {
        type: Date,
        default: Date.now
    }
});
let model = mongoose.model('Student', schemaDefinition);
let randomObject = dummy(model, {
    ignore: ignoredFields,
    returnDate: true
})
console.log(randomObject);

/* Result:
{
    "name": "lyda.renner84",
    "data": {
        "de_AT": {
            "name": "Josianne Bins",
            "email": "[email protected]",
            "phone": "198.514.9229 x60299",
            "posts": [{
                "words": "maxime quia sit",
                "sentence": "Fuga vel in architecto ut modi sequi aliquam debitis.",
                "sentences": "Reprehenderit ratione consequuntu.."
            }, {
                "words": "dignissimos qui qui",
                "sentence": "Eveniet est unde quis sit et ab.",
                "sentences": "Sit eos quaerat aut quisquam unde..",
                "paragraph": "Quasi et numquam cumque neque rerum aliquam ullam.."
            }],
            "address": {
                "geo": {
                    "lat": "25.9144",
                    "lng": "6.0991"
                },
                "city": "Amaraville",
                "state": "Indiana",
                "streetA": "O'Conner Prairie",
                "streetB": "5722 Shane Grove",
                "streetC": "8040 Hane Roads Suite 402",
                "streetD": "Apt. 816",
                "country": "Kenya",
                "zipcode": "74052"
            },
            "website": "garnett.net",
            "company": {
                "bs": "cross-platform facilitate deliverables",
                "name": "Morissette LLC",
                "catchPhrase": "Self-enabling intangible methodology"
            },
            "username": "Emanuel.Botsford37",
            "accountHistory": [{
                "amount": "473.69",
                "date": "2012-02-01T22:00:00.000Z",
                "business": "Lang, Hudson and Heller",
                "name": "Savings Account 3906",
                "type": "invoice",
                "account": "60253551"
            }, {
                "amount": "824.69",
                "date": "2012-02-01T22:00:00.000Z",
                "business": "Rice - Price",
                "name": "Credit Card Account 8924",
                "type": "withdrawal",
                "account": "62599733"
            }]
        }
        }
    },
    "email": "[email protected]",
    "gender": "Male",
    "parent": "59d0ff689b95b02fec446c55",
    "results": [{
        "score": 61,
        "course": 51
    }, {
        "score": 38,
        "course": 63
    }],
    "birth_date": "2017-09-30T14:57:01.279Z",
    "is_student": true,
    "detail": {
        "none_match": "Wade_Robel"
    }
}*/

Testing

To run the test cases use npm test

License

Licensed under MIT

Author

Feel free to Contact us and improve the code.