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 🙏

© 2026 – Pkg Stats / Ryan Hefner

maquila

v0.1.3

Published

Factory lib for building JavaScript or creating records.

Readme

Maquila

factory_girl inspired library for building JavaScript objects or creating records, useful for setting up test data.

Installation

web: $ bower install maquila

node: $ npm install maquila

Usage

Factory Definitions

You can define a new factory with optional constructor function and default attributes, functions will be evaluated:

  Maquila.define('post', Post).defaults({
    title : function() {
      return "Post " + this.sequence();
    },
    createdAt : function() { return new Date(); },
    content   : function(attrs) { return "Content for " + attrs['title'] },
    author    : "Macario Ortega",
    published : false
  });

Building Objects

Instantiate an object optionally passing attributes to override:

  var post = Maquila.build('post', { author: "Daffy Duck" });

It will return a Post instance with this attributes.

  new Post({
    title: 'Post 1',
    createdAt: Tue Apr 09 2013 20:56:24 GMT-0500 (CDT),
    content: "Content for Post 1",
    author: 'Daffy Duck',
    published: false
  })

Same as:

var post = Maquila.factory('post').build({ author: "Daffy Duck" });

Or return a plain JavaScript computed attributes object:

  var postAttributes = Maquila.attributes('post', { author: "Daffy Duck" });

Strategies

Besides attributes, and build, Maquila defines the create strategy, that calls create on the constructor passing the computed attributes.

  var persistedPost = Maquila.create('post', { author: "Daffy Duck" });

New strategies can be defined or existing ones overriden.

  Maquila.strategy('create', function(Constructor, attrs){
    obj = new Constructor(attrs)
    obj.save
    return obj
  });

  Maquila.strategy('persist', function(Constructor, attrs){
    return Constructor.persist(atts);
  });

  var persistedPost = Maquila.persist('post', { author: "Daffy Duck" });

Strategies can be define or overriden globaly or on a factory basis.

  Maquila.factory('post').strategy('publish', function(Post, attrs){
    return Post.publish(atts);
  });

  var publishedPost = Maquila.publish('post', { author: "Daffy Duck" });

Sequences

You can reset the sequence counter for a given factory:

  > Maquila.build('post').title;
  // => "Post 1"
  > Maquila.build('post').title;
  // => "Post 2"
  > Maquila.factory('post').resetSequence();
  // => Factory
  > Maquila.build('post').title;
  // => "Post 1"

Or for all factories:

Maquila.resetSequences();

Collections

You can build an array of instances or attributes, optionally overriding defaults.

var posts = Maquila.factory('post').arrayOf(3).build({
  author: function() { Maquila.factory('author').build() }
};

var persistedPosts = Maquila.factory('post').arrayOf(3).create();

var attributes = Maquila.factory('post').arrayOf(3).attributes();

Collections will implement strategies defined globally or by factory.

var persistedPosts = Maquila.factory('post').arrayOf(3).persist();

var publishedPosts = Maquila.factory('post').arrayOf(3).publish();

Extending Factories

You can define a factory based on a previous factory definition, overriding some defaults.

  Maquila.define('published-post').extend('post').defaults({
    published: true
  });
  
  > Maquila.build('published-post').published;
  // => true

Extended factories will share a sequence counter, but you can set a new one passing an optional start number.

  Maquila.factory('published-post').setNewCounter(2);