Home > emery

emery

Emery is a project mainly written in JavaScript, based on the MIT license.

Node.js extended

= Emery

NodeJS "à la" Ruby

== Install

== class and module

=== Create a class

var class = require('emery/class').class;

exports.MyClass = MaClass = class( ParentClass, { // Constructor initialize: function() { ... },

// Instance method
methodA: function() { ... },

// Class method
self$methodB: function() { ... },

...

} ); MaClass.include(MyModule);

MaClass.methodB();

var myInstance = new MaClass(); myInstance.methodA();

=== Create a module

var module = require('emery/module').module;

exports.MyModule = MyModule = module({ method1: function() { ... },

// ...

});

MyModule.method1();

== Enumerable

The Enumerable mixin provides collection classes with several traversal and searching methods, and with the ability to sort. The class must provide a method each, which yields successive members of the collection. If Enumerable#max, min, or sort is used, the objects in the collection must also implement a meaningful <=> operator, as these methods rely on an ordering between members of the collection.

=== Usage

var Enumerable = require('emery/enumerable').Enumerable

=== Methods

  • Enumerable#all
  • Enumerable#any
  • Enumerable#count
  • Enumerable#cycle
  • Enumerable#drop
  • Enumerable#drop_while
  • Enumerable#each_slice
  • Enumerable#each_cons
  • Enumerable#each_with_index
  • Enumerable#each_with_object
  • Enumerable#find
  • Enumerable#find_all
  • Enumerable#find_index
  • Enumerable#grep
  • Enumerable#group_by
  • Enumerable#include
  • Enumerable#inject
  • Enumerable#max
  • Enumerable#max_by
  • Enumerable#min
  • Enumerable#min_by
  • Enumerable#minman
  • Enumerable#minmax_by
  • Enumerable#none
  • Enumerable#one
  • Enumerable#reject
  • Enumerable#select
  • Enumerable#sort
  • Enumerable#sort_by
  • Enumerable#take
  • Enumerable#take_while

== EString

=== Usage

var EString = require('emery/string').EString;

=== Methods

== ENumber

=== Usage

var ENumber = require('emery/number').ENumber;

=== Methods

== EArray

EArrays are ordered, integer-indexed collections of any object. EArray indexing starts at 0, as in C or Java. A negative index is assumed to be relative to the end of the array—that is, an index of -1 indicates the last element of the array, -2 is the next to last element in the array, and so on.

=== Usage

var EArray = require('emery/array').EArray;

=== Included module

Enumerable

=== Methods

  • EArray#each
  • EArray#map
  • EArray#collect
  • EArray#map$
  • EArray#collect$
  • EArray#push
  • EArray#unshift
  • EArray#concat
  • EArray#at
  • EArray#pop
  • EArray#shift
  • EArray#slice
  • EArray#slice$
  • EArray#pretty_print
  • EArray#to_s
  • EArray#inspect
  • EArray#index
  • EArray#delete
  • EArray#delete_at
  • EArray#delete_if
  • EArray#each_index
  • EArray#empty
  • EArray#eql
  • EArray#fetch
  • EArray#fill
  • EArray#first
  • EArray#take
  • EArray#replace
  • EArray#insert
  • EArray#join
  • EArray#last
  • EArray#reject$
  • EArray#reverse_each
  • EArray#reverse
  • EArray#reverse$
  • EArray#shuffle
  • EArray#shuffle$
  • EArray#take_while
  • EArray#uniq
  • EArray#uniq$
  • EArray#values_at
  • EArray#clear
  • EArray#compact
  • EArray#compact$
  • EArray#to_json
  • EArray#get
  • EArray#set

== EHash

=== Usage

var EHash = require('emery/hash').EHash;

=== Included module

Enumerable

=== Methods

  • EHash#replace
  • EHash#each
  • EHash#each_pair
  • EHash#each_key
  • EHash#each_value
  • EHash#clear
  • EHash#empty
  • EHash#values
  • EHash#has_value
  • EHash#value
  • EHash#keys
  • EHash#has_key
  • EHash#member
  • EHash#key
  • EHash#map
  • EHash#invert
  • EHash#to_js
  • EHash#clone
  • EHash#merge
  • EHash#merge$
  • EHash#update
  • EHash#delete
  • EHash#delete_if
  • EHash#fetch
  • EHash#pretty_print
  • EHash#to_s
  • EHash#inspect
  • EHash#set
  • EHash#store
  • EHash#get

== ERange

=== Usage

var ERange = require('emery/range').ERange;

=== Included module

Enumerable

=== Methods

  • ERange#begin
  • ERange#cover
  • ERange#each
  • ERange#end
  • ERange#eql
  • ERange#exclude_end
  • ERange#first
  • ERange#hash
  • ERange#last
  • ERange#member
  • ERange#inspect
  • ERange#pretty_print
  • ERange#to_s
  • ERange#to_js
  • ERange#to_a
  • ERange#step

== Exceptions

=== Error classes list

  • ArgumentError
  • IndexError
  • KeyError
  • NameError
  • NotImplementedError
  • ERangeError
  • RegexpError
  • RuntimeError
  • StandardError
  • SyntaxError
  • TypeError
  • ZeroDivisionError

=== Raise an exception

throw( new Exception("message") )

Example :

var ZeroDivisionError = require('emery/exception').ZeroDivisionError;

function myFunction( value ) { var ret = 100/value;

if( ret == Infinity ) throw( new ZeroDivisionError("Zero division not allowed in myFunction!") );

return( 100/value );

}

try { v = myFunction( 0 ); } catch(e) { console.log(e); //=> #<ZeroDivisionError: Zero division not allowed in myFunction!> }

== Note on Patches/Pull Requests

  • Fork the project.
  • Make your feature addition or bug fix.
  • Add tests for it. This is important so I don't break it in a future version unintentionally.
  • Commit, do not mess with jakefile, version, or history. (if you want to have your own version, that is fine but bump version in a commit by itself I can ignore when I pull)
  • Send me a pull request. Bonus points for topic branches.

== Inspiration

This lib was truly inspired by the awsome JS.Class (http://jsclass.jcoglan.com/) and php.js (http://phpjs.org)

== Copyright

Copyright (c) 2010 Gregoire Lejeune. See LICENSE for details.