Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

model-golem

Package Overview
Dependencies
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

model-golem

A model factory JS library to generate data mocks

  • 1.0.3
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
0
decreased by-100%
Maintainers
1
Weekly downloads
 
Created
Source

model-golem

A model factory JS library to generate data mocks


Installing

npm install --save-dev model-golem

Using

Load the Factory:

// NodeJS / CommonJS Modules
var Factory = require('model-golem');

// ES2015 Modules
import Factory from 'model-golem';

Define a model:

var Person = {
  id: function() {

    // this.sequence is autoincremented on every creation step, starts from 0
    return this.sequence;
  },

  // Define the attributes giving their default values
  name: '',
  charisma: 42,

  // Reuse attributes
  username: function() {
    return this.item.name.toLowerCase().replace(/ /g, '');
  }
};

Instantiate the Factory with your model:

var peopleFactory = new Factory(Person);

Create your mocks!

var person = peopleFactory({
  name: 'Leo Balter',
});

/*
  person === {
    id: 0,
    name: 'Leo Balter',
    charisma: 42,
    username: 'leobalter'
  }
*/

Create your mocks from arrays!

var people = peopleFactory([
  {
    name: 'Green Avocados',

    // replace default values!
    charisma: 0
  },
  {
    name: 'Spicy Mustard',
    id: 100,
    charisma: 37,
    username: 'mryellow'
  }
]);

/*
  people === [
    {
      id: 2,
      name: 'Green Avocados',
      charisma: 0,
      username: 'greenavocados'
    },
    {
      id: 100,
      name: 'Spicy Mustard',
      charisma: 37,
      username: 'mryellow'
    }
  ]
*/

Get the stored data!

var stored = peopleFactory.store;

/*
  stored === [
    {
      id: 1,
      name: 'Leo Balter',
      charisma: 42,
      username: 'leobalter'
    },
    {
      id: 2,
      name: 'Green Avocados',
      charisma: 0,
      username: 'greenavocados'
    },
    {
      id: 100,
      name: 'Spicy Mustard',
      charisma: 37,
      username: 'mryellow'
    }
  ]
*/

MIT Licensed

Keywords

FAQs

Package last updated on 11 Dec 2015

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc