node package manager
Share your code. npm Orgs help your team discover, share, and reuse code. Create a free org »


nail - simple modular classes

Nail is a simple but flexble tool for creating coffe/java script classes.

Nail uses the powefull nail-core API to handlethe propertiesmethods and iheritance with seperate replacable modules.

Class definitions in nail are well strcutured and tool friendly.

This Document

To ensure that the examle code is up to date it is run as a test- This requires underscore, should and an instrumented version of nail. In your productive code nail = require 'nail' should be enough.

nail    = require '../coverage/instrument/lib/module.js'
should  = require 'should'
_       = require 'underscore'


The nail concept:

  • class definitions are objects
  • every key in the definition is a class
  • every aspect of a class has a seperate block

Nail uses the API defined by nail-core and modules from nail-common.


Creating a class

The following code defines the class Person and adds it to exports and the namespace 'my-module'. exports, 'my-module', Person:
    firstName:  null
    lastName:   null
    getFormatedName: -> return "#{@lastName}, #{@firstName}"

Now our package exports the constructor for Person.

describe 'Person', ->
  it 'is a function', -> 
    (_.isFunction exports.Person)

creating an instance

Properties are injected into the new Instance.

dalia = new exports.Person
  firstName: 'Dalia'
  lastName:  'Scarlet'
it 'injects properties', ->
  dalia.firstName.should.equal 'Dalia'
  dalia.lastName.should.equal  'Scarlet'
it 'creates methods', ->
  dalia.getFormatedName().should.equal 'Scarlet, Dalia'

using namespaces

Using namespaces will give evry class a unique name. This name can be used to when using resources.

For a demonstrtion we will use a very simple generic factory function.

it "can be loaded from json", ->
  sampleJSON ="""
                "type": "my-module.Person",
                  "firstName": "Nick",
                  "lastName":  "Pudel"   
  loadObject = (data) -> new nail.lib[data.type]

  nick  = loadObject(JSON.parse sampleJSON)
  nick.firstName.should.equal 'Nick'
  nick.lastName.should.equal 'Pudel'
  nick.getFormatedName().should.equal "Pudel, Nick" 


Install with npm:

npm install nail

Clone with GIT:

git clone


Head here → docs