Node Roundup: 0.6.15, node-inherit, Synchronize.js, jaded

11 Apr 2012 | By Alex Young | Tags node modules jade templating thumbnails images async fibers
You can send in your Node projects for review through our contact form or @dailyjs.

Node 0.6.15

Node 0.6.15 is out. It includes npm 1.1.16, and some platform-specific bug fixes for Windows and Mac OS.

Thumbbot

Thumbbot (GitHub: vdemedes / thumbbot, License: MIT, npm: thumbbot) by Vadim Demedes is a thumbnail generator API built with PhantomJS, ImageMagick, and ffmpeg.

The Thumbbot class is instantiated with a source and output file:

bot = new Thumbbot 'video.mp4', 'video_thumb.png'
bot.set width: 200, height: 150
bot.set position: '00:05:04'
bot.snap (err) ->
    # done

The author has included Mocha tests, and various output formats are supported (png, jpg, gif).

node-inherit

node-inherit (License: MIT, npm: inherit) by Dmitry Filatov adds some sugar to help with class-like declarations, constructors, super calls, and static methods.

An inherited class looks like this:

var B = inherit(A, {
    getProperty: function() {
      return this.property + ' of instanceB';
    },

    getType: function() {
      return this.__base() + 'B';
    }
  },

  staticMethod: function() {
    return this.__base() + ' of staticB';
  }
});

This example assumes a class called A – notice how the getType method can access A’s getType using this.__base. The full example can be viewed in the project’s readme.

Dmitry has included some Nodeunit tests that also demonstrate the main features of the library.

Synchronize.js

Synchronize.js (GitHub: alexeypetrushin / synchronize, License: MIT, npm: synchronize) by Alexey Petrushin is another library that’s built on fibers to attempt to “flatten” all of those pesky callbacks people like to talk about on Hacker News.

Existing methods can be wrapped with the sync method provided by the library:

var sync = require('synchronize')
  , fs = require('fs');

fs.readFile_ = sync(fs.readFile);

sync.fiber(function() {
  var data = fs.readFile_(__filename, 'utf8');
  console.log(data);

  try {
    data = fs.readFile_('invalid', 'utf8');
  } catch (err) {
    console.log(err);
  }
});

Asynchronous methods can be used in a synchronous fashion within the sync.fiber callback. Wrapped functions will behave as if return and throw were called synchronously. The author has written Mocha tests, but the library itself is fairly small so it’s not too hard to figure out how it uses fibers to wrap functions: synchronize.js.

jaded

jaded (License: MIT, npm: jaded) from Fractal is an alternate command-line interface for Jade that includes AMD support:

  Usage: jaded [options]

  Options:

    -h, --help            output usage information
    -V, --version         output the version number
    -i --input [folder]   Specify input folder
    -o --output [folder]  Specify output folder
    -d --development      Beautify output and insert line numbers
    -a --amd              Wrap output in AMD closure

blog comments powered by Disqus