loopback-faker-mixin

0.0.3 • Public • Published

loopback-faker-mixin

Synopsis

A mixin for loopback using the faker library.

Code Example

In your model.json

{
    "name": "Customer",
    "base": "User"
    "properties": {
        "name": {
            "type": "string",
            faker: 'faker.method' || { method: 'faker.method', args: ['arg1']} see https://github.com/marak/Faker.js/
        }
    },
    "mixins": {
        "Faker": {
            "email": "internet.email",
            "password": "internet.password"
        }
    }
}
 

After the app has initialised you are able to access the static faker method via

let { Customer } = app.models
 
Customer.faker({
    name: 'New Name' // this will overwrite the faker fakeness if you want
})
.then(customer => {
// customer with faked data
})
 
Customer.bulkFaker({
    global: {
        name: 'Every One Gets this Name'
    },
    individuals: [
        {
            name: 'except this guy... this is his name'
        }
    ]
}, 10).then(customers => {
    let individual = customers[0]
    customers.length === 10
    individual.name === 'except this guy... this is his name'
})

Motivation

A simple way to create random data for testing and seeding

Installation

npm install faker loopback-faker-mixin

=============

Add the mixins property to your server/model-config.json:

{
  "_meta": {
    "sources": [
      "loopback/common/models",
      "loopback/server/models",
      "../common/models",
      "./models"
    ],
    "mixins": [
      "loopback/common/mixins",
      "<path-to-your>/node_modules/loopback-faker-mixin",
      "../common/mixins"
    ]
  }
}

API Reference

Faker github.

Contributors

henry
Henry Stevens

Readme

Keywords

Package Sidebar

Install

npm i loopback-faker-mixin

Weekly Downloads

0

Version

0.0.3

License

MIT

Last publish

Collaborators

  • nextfaze