typely
Lightweight (meaning relatively fast) type-checking in CoffeeScript.
Last updated 12 years ago by dyoder .
MIT · Repository · Original npm · Tarball · package.json
$ npm install typely 
SYNC missed versions from official npm registry.

typely

A lightweight (read: relatively fast) type-checking library in CoffeeScript.

{overload} = require "typely"

class Multiplier 

  total: 1

  multiply: overload (match) ->
    match "array", (array) -> @multiply element for element in array
    match "number", (number) -> @total *= number

multiplier = new Multiplier

multiplier.multiply 2
multiplier.multiply [ 3, 4, 5 ]

console.log multiplier.total

Typely is limited to checking for types, [as per Douglas Crockford's typeOf function][0]. That is: null, undefined, boolean, number, string, date, regexp, array, object, and function. This limitation allows it to run relatively fast, by simply using as an index a string based on the types of the given arguments and seeing whether it returns a function.

Installation

npm install typely

Current Tags

  • 0.0.0                                ...           latest (12 years ago)

1 Versions

  • 0.0.0                                ...           12 years ago
Maintainers (1)
Downloads
Total 0
Today 0
This Week 0
This Month 0
Last Day 0
Last Week 0
Last Month 0
Dependencies (1)
Dev Dependencies (0)
None
Dependents (0)
None

© 2010 - cnpmjs.org x YWFE | Home | YWFE