The JavaScript blog.


libraries events books conferences strings

StringFormatter, Hapi.js in Action, FullStack 2015

Posted on .


Simon Blackwell sent me StringFormatter (GitHub: anywhichway/stringformatter, License: MIT), a string formatting library that aims to go beyond the new ECMAScript string templates. It's a bit like sprintf formatting, but includes some more complex features:

  • Numerical type formatting
  • Date formatting
  • CSS styles
  • Conditional formatting
  • Caching

It can handle expressions like currency as well, which is ideal for web applications when you want to display multiple currency formats. You can use StringFormatter.register to register a formatting for a type. For example, if you had a date formatter object you could associate it with Date like this: StringFormatter.register(Date, dateFormatter, 'Date').

The usual way to format a string is with StringFormatter.format, but you can use StringFormatter.polyfill() to add string formatting to the String object. Format strings are represented with JavaScript-inspired syntax:

  "The time is now {Date: {format:'hh:mm'}} and I have {number: {fixed: 2, currency: '$'}}.",
  new Date('2015-03-13T10:01:27.284Z'),

All format options accept an additional style string, which causes the output to be wrapped in span elements with inline styles.

Ideally this library should be used with a templating system to really cut down on format invocation boilerplate. Simon has included an example for the Ractive template engine.

Hapi.js in Action

Hapi in Action

Hapi.js in Action by Matt Harrison is a book that's dedicated to web development with Hapi.js. It has been released as an early access edition, and pricing starts at $35.99 for the eBook. The planned content includes authentication, building modular applications with plugins, testing, production, proxies, and creating streaming services.

Hapi.js in Action teaches you how to build modern Node-driven applications using Hapi.js. Packed with examples, this book takes you from your first simple server through the skills you'll need to build a complete application. In it, you'll learn how to build websites and APIs, implement caching, authentication, validation, error handling, and a lot more. You'll also explore vital techniques for production applications, such as testing, monitoring, error handling, deployment, and documentation.

The first chapter is available for free, and early access supporters can get chapters two and three as well.

FullStack 2015

FullStack 2015 is an event that's all about JavaScript, Node, and the Internet of Things, that will be held in London on 25th to 27th June. Tickets start at £375 for early bird tickets.

There's currently a FullStack call for papers, so if you're interested in speaking at the conference you've got a week to apply.


testing databases node modules strings ORM

Node Roundup: Buster.JS, Word, Persist

Posted on .

You can send in your Node projects for review through our contact form or @dailyjs.


A reader sent in Buster.JS (GitHub: busterjs, npm: buster, License: BSD) by Christian Johansen and August Lilleaas, which is a new test framework for Node and browsers. It's made up of a large set of modules that support everything from CommonJS assertions to JsTestDriver. The entire suite of modules can be viewed in the Buster.JS module documentation.

Asynchronous testing is supported through a callback function, similar to other frameworks, and promises. Any object with a then method is considered a promise:

function someAsyncTestFunction() {  
  var promise = {
    then: function (callback) {
      this.callbacks = this.callbacks || [];

  setTimeout(function () {
    var callbacks = promise.callbacks || [];

    for (var i = 0, l = callbacks.length; i < l; ++i) {
  }, 100);

  return promise;

Buster.JS supports setup and teardown methods, which can be nested inside groups of tests. Setup and teardown methods can also be asynchronous.

Tests can be written with TDD or BDD syntax, and several reporters are included, including a XML (which should work with test automation tools).

Buster.JS overview includes highlights and examples for the major features of the framework.


Word (License: MIT, npm: word) by Veselin Todorov is a string library. It has methods for stripping slashes, stripping quotes, random strings, auto HTML links, and a lot more. It plays nicely with Express, so if you want to use these as helper methods then just call app.helpers({ word: word });


Persist (npm: persist, License: MIT) by Joe Ferner and Jeff Kunkle is a new ORM framework that supports SQLite, MySQL, PostgreSQL, and Oracle. Models and their relationships are defined using a chainable API. This example is from the project's documentation:

var persist = require('persist')  
  , type = persist.type;

// define some model objects
var Phone = persist.define('Phone', {  
  'number': type.STRING

var Person = persist.define('Person', {  
  'name': type.STRING

  driver: 'sqlite3',
  filename: 'test.db',
  trace: true
}, function(err, connection) {
  Person.using(connection).all(function(err, people) {
    // people contains all the people

As you can see, the Phone and Person models are defined in a fashion reminiscent of popular Node ODMs like Mongoose. The hasMany method sets up a relationship between the two models, and this also supports a through option for more complex join models.

The connection.chain(chainables, callback) method is one of Persist's interesting features: it can take an array of chainable queries in sequence. This solves a common Node control flow issue without having to use a control flow library (or lots of nested callbacks).