DeLorean, Cash: Call, Collect, Assign

19 Aug 2014 | By Alex Young | Comments | Tags libraries ui flux


DeLorean.js (GitHub: f / delorean, License: MIT, Bower: delorean, npm: delorean.js) by Fatih Kadir Akın is a Flux implementation. It can be used with React.js and Flight.js, and the author mentioned that he’s working on Backbone.js integration as well.

I’ve previously written about Fluxxor, which is another library based on Flux. If you’ve used MVC libraries before, then you can think of DeLorean.js and Fluxxor like alternatives for the models and controllers. Flux provides tools for creating stores, dispatchers, and action creators.

Stores are a bit like models, but you don’t create instances of them. Instead they manage state for a domain within the application. This actually has positive implications for testing. This quote is from the React overview:

Stores accept updates and reconcile them as appropriate, rather than depending on something external to update its data in a consistent way. Nothing outside the store has any insight into how it manages the data for its domain, helping to keep a clear separation of concerns. This also makes stores more testable than models, especially since stores have no direct setter methods like setAsRead(), but instead have only an input point for the payload, which is delivered through the dispatcher and originates with actions.

Dispatchers manage data flows, responding to actions as they are created during the lifetime of a program. Action creators are similar to controllers in MVC – in DeLorean’s documentation they do things like get JSON from a server, then pass the data to a dispatcher.

Action creators are then used by the view layer, so if you’re using React you could invoke action creators from views and bind them to template fragments.

This might all sound highly abstract, but you might find it useful if you’re finding it hard to manage large client-side projects. The model layer in MVC libraries often feels ORM-inspired, which in my experience doesn’t always work well when combined with business logic.

Cash Updates

Rob Robbins sent in a note to say Cash has been updated to include new methods for allowing the invocation of native functionality:

Call, Collect and Assign

In order to keep code creep at a minimum, We are introducing these three methods that allow the invocation of native functionality on the elements in the q. What do I mean? Let’s take the Attribute methods for an example. We could write separate methods for the getting, setting, and removal of attributes:

cash.setAttribute = function(foo, bar) {
  // set attribute 'foo' to 'bar' on each element in the q 

cash.removeAttribute = function(foo) {
  // remove attribute 'foo' from each element in the q 

cash.getAttribute = function(foo) {
  // collect and return attribute 'foo' from each element in the q 

Instead we can have a single method capable invoking any of these (or any native method for that matter):

$(foo).call('setAttribute', 'data-foo', 'bar'); // returns cash
$(foo).call('removeAttribute', 'data-foo');
$(foo).collect('getAttribute', 'data-foo'); // retruns an array

The reason I wrote about Cash previously was because I know a lot of people are looking for alternatives to jQuery for smaller DOM/event-wrapper libraries, and this new API should help people use existing standards rather than reinventing things browsers are good at.

PerfBar, ngAtp

18 Aug 2014 | By Alex Young | Comments | Tags libraries ui angularjs performance benchmarks



PerfBar (GitHub: lafikl / perfBar, License: MIT) by Khalid Lafi is a script that adds various benchmarks to a page. To use it, add perfBar.js and then configure some metrics:

  budget: {
    'loadTime': {
      max: 200
    'redirectCount': {
      max: 1
    'globalJS': {
      min: 2,
      max: 5

You can use perfBar.enable and perfBar.disable to toggle metrics. The documentation has PerfBar included on the page so you can see what it looks like, and each of the available metrics is documented.

Some of the available metrics are the total number of DOM elements, the time for the DOM content to load, request duration, and backend/frontend processing time.


ngAtp (GitHub: yiransheng / ngAtp, License: MIT, Bower: ng-atp) by Yiran Sheng is an autocompletion library for AngularJS. The basic usage is to specify the ng-atp and ng-atp-config directives. The config option uses a Bloodhound config object, which comes from Twitter’s typeahead.js suggestion engine.

In ngAtp, Bloodhound is included as an Angular service, with Angular’s $http library instead of jQuery.ajax. It reuses Bloodhound, so you get features like prefetching, intelligent caching, fast lookups, and backfilling, but with an Angular-friendly API.

Js13kGames, Angular Plasmid

15 Aug 2014 | By Alex Young | Comments | Tags games competitions graphics biology angularjs testing


Andrzej Mazur wrote in to say that the Js13kGames competition has started. All entries must be in by the 13th of September. It’s a competition to build HTML5 games in 13 kilobytes, and that includes all assets. If you want sounds and complex graphics then it might be advantageous to procedurally generate certain things.

All your code and game assets should be smaller than or equal to 13 kilobytes (that’s exactly 13,312 bytes, because of 13 x 1024) when zipped. Your package should contain index.html file and when unzipped should work in the browser.

The competition has a theme, so entries should somehow encapsulate the elements:

The main theme of the competition in 2014 is The Elements: Earth, Water, Air and Fire. It is optional, so you can use it, use part of it (one Element), or drop it. Remember that there will be bonus points for implementing the theme in your game.

Andrzej wrote a tutorial for tuts+ about minifying games, and he created the game Triskaidekaphobia to promote the competition.

Angular Plasmid

Angular Plasmid

Angular Plasmid (GitHub: vixis / angularplasmid, License: MIT) by Rehan Chawdry is an AngularJS library for biological plasmid visualisation:

Rather than coding client-side JavaScript or other server-side programming languages, AngularPlasmid provides easy-to-use HTML markup, making plasmid generation as easy as creating a web page. In fact, you don’t really neeed to know anything about AngularJS or JavaScript to use the components, as one of the download options bundles everything together for you.

The basic tutorial explains how to create a visualisation using markup rather than having to write JavaScript, so it should appeal to biologists who want to create rich HTML documents that aren’t programmers. In fact, Angular seems like a good choice for this type of visualisation in that you can use it declaratively.

Amygdala: A JavaScript REST Client

14 Aug 2014 | By Alex Young | Comments | Tags rest libraries browser

Over the last few years I’ve worked almost exclusively by designing server-side APIs totally separately to the UI. Client-side code is just another client, structured with something like Backbone or Angular. This works well when you develop applications that have multiple front-ends (public site, admin area), or you’ve got desktop and mobile clients.

Marco Louro sent in Amygdala (GitHub: lincolnloop / amygdala, License: BSD, npm: amygdala), a JavaScript REST library designed specifically for this type of work. It’s inspired by Hoodie, but optimised for custom API backends instead of a specific API or database.

Amygdala was born out of the desire to reduce the complexity involved with managing multiple JavaScript modules (controllers or models/collections) that do essentially the same thing, fetch and sync data.

It works by using a constructor function that accepts configuration and resource paths. Data is cached to localStorage, and updates to data after subsequent modifications results in events that you can subscribe to:

store.on('discussions:change', function() {
  // re-render our view

When you set up the RESTful API, you can specify things like HTTP headers and foreign key relationships:

var store = new Amygdala({
  'config': {
    'apiUrl': 'http://localhost:8000',
    'idAttribute': 'url',
    'headers': {
      'X-CSRFToken': getCookie('csrftoken')
    'localStorage': true
  'schema': {
    'users': {
      'url': '/api/v2/user/'
    'teams': {
      'url': '/api/v2/team/',
      'orderBy': 'name',
      'oneToMany': {
        'members': 'members'
    'members': {
      'foreignKey': {
        'user': 'users'

When I use a library that focuses on data binding, like Knockout, server communication always feels hard to get right. Amygdala looks like a great library to pair with Knockout – it’ll help make server calls cleaner and also add locally cached data without much extra effort.

Node Roundup: npmE, Snapshot.js, dm.js

13 Aug 2014 | By Alex Young | Comments | Tags node modules libraries npm dependency-injection


There’s an open beta for npmE, the npm Enterprise programme. This allows you to sign in to a private, hosted repository, which can be used to distribute private modules. They’re prefixed with your company name, like this:

npm install @myco/somepackage

Then you can load them with the prefix as follows:


There’s a new post on the npm blog about the roadmap for npmE:

We plan on building a web-UI for controlling various aspects of an npmE installation: adding and removing packages from the whitelist, configuring authentication/authorization strategies, managing organizations and teams.


Snapshot.js (GitHub: Wildhoney/Snapshot.js, License: MIT, Demo) by Adam Timberlake is a WebSocket-based Node application for sorting, paginating, and filtering data served using WebSockets.

It uses Express and the crossfilter module, which is a multidimensional filtering library:

Crossfilter is a JavaScript library for exploring large multivariate datasets in the browser. Crossfilter supports extremely fast interaction with coordinated views, even with datasets containing a million or more records; we built it to power analytics for Square Register, allowing merchants to slice and dice their payment history fluidly.


dm.js (GitHub: gobwas / dm.js, License: MIT, npm: dm) by Sergey Kamardin is a module for dependency injection. It’s service based, so you’d have to build applications using that pattern to take advantage of it.

The dm module itself implements the “service locator” pattern. That means it knows how to find a given service and configure it. It supports asynchronous adapters, so you could use it with jQuery.Deferred, Q.js, and promises with Harmony. It can load modules with either AMD or CommonJS, so it’ll work with Node modules.

This might sound like a huge amount of effort if you’re not used to dependency injection, but if you come from a Java/C#/C++ background then you might find it easier to design Node applications this way.

Build Configuration with Angus

12 Aug 2014 | By Alex Young | Comments | Tags build grunt


Build tools are great, but they’re usually optimised for working on single projects. If you’re a freelancer or work for an agency, then you probably work on multiple projects for several clients each day. Angus (GitHub: nickjanssen / angus, License: MIT) by Nick Janssen aims to help improve exactly that type of workflow by sharing a build configuration across all of your applications.

Angus solves these problems by turning the build process into something generic and reusable. It allows you to specify libraries on a per-app basis, while still sharing the same build steps.

Inside Angus, every app is simply a directory inside the apps/a folder with its own repository. The apps/ folder gets ignored by the Angus repository. Each app you make with Angus shares the same global Gruntfile, but can define all the libraries they need on a per-app level.

Each application can still have its own dependencies. Bower is used for client-side dependencies, but rather than using bower.json files Angus invokes Bower with the necessary package names and version strings.

Nick posted an article to David Walsh’s blog about Angus: Building Web Apps Faster Using Angus. It details the installation and configuration process and also shows how to use Angus with Git.

Backbone Directives

11 Aug 2014 | By Alex Young | Comments | Tags backbone angularjs libraries

Tal Bereznitskey writes:

This is an open source project to enrich Backbone.js with AngularJS style directives.

I used to hear people talk about the new hotness and I didn’t really want to let go of Backbone. I took quick looks from time to time and found some stuff I didn’t like in AngularJS.

The DOM was filled with things like “ng-click” which reminded me of the spaghetti age of HTML and JavaScript.

When I first started using Angular I also found custom attributes (directives) concerning. However, after using them I realised that they can really help make code more declarative and concise. Tal came to the same conclusion, and created Backbone Directives (GitHub: berzniz / backbone.directives, License: MIT) to bring the same pattern to Backbone projects.

It includes things like bb-bind which implements data-binding with expression support, and bb-class for changing an element’s class.

Expressions use the same code as Angular’s expression parser, which attempts to safely execute JavaScript by using a sandbox that prevents access to certain properties (like .constructor).

// Sandboxing Angular Expressions
// ------------------------------
// Angular expressions are generally considered safe because these expressions only have direct
// access to $scope and locals. However, one can obtain the ability to execute arbitrary JS code by
// obtaining a reference to native JS functions such as the Function constructor.

Not all data binding libraries support expressions as well as this, so Tal has opted to fork Angular’s approach so you can get the same functionality in your Backbone applications.

Tal wrote a post about the project, with his thoughts on Angular, Backbone, and how to use Backbone Directives.

Face Tracking, tcomb

08 Aug 2014 | By Alex Young | Comments | Tags graphics webcam

JavaScript Face Tracking

Konrad Dzwinel sent in a JavaScript Face Tracking Demo that demonstrates how to use getUserMedia with tracking.js to track your face and add an image based on the position. It also uses gif.js to generate GIFs, and Imgur’s API to upload the images.

Konrad made a video about the project with more details about each of the libraries and how you can use them.


tcomb (GitHub: gcanti / tcomb, License: MIT, npm: tcomb) by Giulio Canti is a library for making types and combinators. You can use it for validating input or perhaps even lightweight models.

It supports JavaScript primitive type checking, structs, unions, tuples, and subtypes. This is an example of a struct:

var Product = struct({
  name: Str,                  // a REQUIRED string
  description: maybe(Str),    // an OPTIONAL string (can be `null`)
  homepage: Url,              // a SUBTYPE of string representing an URL
  shippings: list(Shipping),  // a LIST of shipping methods
  category: Category,         // a string in [Audio, Video] (ENUM)
  price: union(Num, Price),   // price expressed in dollars OR in another currency (UNION)
  dim: tuple([Num, Num])      // width x height (TUPLE)

The project is tested with Mocha, and the readme and homepage have lots of examples.


07 Aug 2014 | By Alex Young | Comments | Tags processing graphics


I’m a big fan of Processing, and I’ve made lots of my own weird and wonderful graphical sketches over the years. p5.js (GitHub: lmccart/p5.js, License: GPL) by Lauren McCarthy is an entirely new library that’s inspired by Processing. It doesn’t currently have an integrated IDE, but the authors are working on it. The documentation shows how to use Sublime Text for p5.js development.

Sketches made with p5.js have setup and draw functions. There are globally available methods that provide handy drawing commands:

function setup() {
  createCanvas(640, 480);

function draw() {
  if (mouseIsPressed) {
  } else {
  ellipse(mouseX, mouseY, 80, 80);

If you’ve ever seen Processing before then this should be familiar. In fact, there’s a Processing transition article for people with Processing experience.

There are some p5 libraries, like p5.dom for HTML5 manipulation and p5.sound for audio.

The advantage of p5.js over Processing.js is your scripts can use native JavaScript. However, because it uses global methods and special variables (like ellipse() and mouseIsPressed) then it feels more like a domain specific language than a reusable JavaScript library that’s safe to drop into an existing project.

For people that love JavaScript and Processing it’s definitely worth trying out, and I hope people will create more libraries for it. Also, if you’re trying to learn Processing or p5.js then check out The Nature of Code!

Node Roundup: V8 Vulnerability, git-promise, awesome-nodejs

06 Aug 2014 | By Alex Young | Comments | Tags node modules security git

V8 Memory Corruption

The versions of V8 included with Node 0.8 and 0.10 were found to have a memory corruption vulnerability. The issue was discovered by a security specialist, and then a core Node contributor worked with the V8 team to fix the problem. More details can be found in the V8 Memory Corruption and Stack Overflow post on the Node blog.

That means Node 0.8.28 and Node 0.10.30 have been released which both include a fix. 0.10.30 also has some changes to several core modules, including buffer, streams, and child process.


git-promise (GitHub: piuccio / git-promise, License: MIT, npm: git-promise) by Fabio Crisci is a promise-based wrapper for Git:

var git = require('git-promise');

git('rev-parse --abbrev-ref HEAD').then(function(branch) {
  console.log(branch); // This is your current branch

The readme has more advanced examples, like finding the commit where master diverged from your current branch. Fabio has included some tests written with nodeunit.


Sindre Sorhus sent in awesome-nodejs, a curated list of Node modules and resources. It’s a handy list to check if you’re looking for a module and are overwhelmed by choice, or not sure where to start on a topic.

There’s also an awesome list of awesome lists, which leads to awesome-javascript, and then back again.

Touch Emulator, Input by Font Bureau

05 Aug 2014 | By Alex Young | Comments | Tags libraries ui mobile fonts

Touch Emulator

When working with iOS applications, the gesture shortcuts in the simulator quickly become second nature. Sometimes I use the iOS Simulator for web development purely to check responsive designs, mainly because it starts up more quickly than the Android emulator. Touch Emulator (GitHub: hammerjs / touchemulator, License: MIT) from Hammer.js is a way to emulate multi-touch events on the desktop, based on the W3C specifications.

Once it’s installed you can listen for events in the standard way:

document.body.addEventListener('touchstart', log, false);
document.body.addEventListener('touchmove', log, false);
document.body.addEventListener('touchend', log, false);

The demo is what reminded me of the iOS Simulator – you can press shift to fake a second touch point, which allows pinch to zoom to work.

Input by Font Bureau


I recently had a spate of font experimentation in Visual Studio. I’m typically a terminal/Vim user, so I’m not used to the way Windows handles font rendering. Since then I’ve been tweaking my fonts everywhere, although I keep ending up back on Menlo or Meslo.

André Mora sent in Font Bureau’s Input typeface:

Input is a flexible system of fonts designed specifically for code by David Jonathan Ross. It offers both monospaced and proportional fonts, all with a large range of widths, weights, and styles for richer code formatting.

There’s an interesting page with more details about Input, called Questioning Monotheism:

Monospaced fonts aren’t great for setting normal text, but they have become the de facto standard for setting code. Since all characters are constrained to the same fixed width, the page becomes a grid of characters, and the mechanics of typesetting are drastically simplified. However, this comes at an aesthetic cost: wide characters are forced to squeeze; narrow characters are forced to stretch. Uppercase letters look skinny next to lowercase, and bold characters don’t have enough room to get very bold.

It goes on to present several arguments about how to position text for code:

By mixing typographic variation with the power of syntax highlighting, by composing text that transcends a fixed-width grid, and by choosing and combining multiple font styles, we can end all up with code and data that is ultimately easier to read and write.

You can download Input for private use, or license it for commercial publications (including websites).

t3, Blast.js

04 Aug 2014 | By Alex Young | Comments | Tags libraries ui graphics gl text-parsing


t3 (GitHub: maurizzzio / t3, License: MIT, Bower: t3) by Mauricio Poppe is a boilerplate for creating three.js projects. It’s inspired by Jerome Etienne’s three.js boilerplate, and supports:

  • Modules following the UMD pattern
  • Integration with dat.gui
  • Micro scene handler
  • Micro camera manager
  • Keyboard manager
  • Themes

If you’re looking for a framework to get started making a WebGL game or demo, then this might be a good way to quickly make something fun.



Blast.js (GitHub: julianshapiro / blast, License: MIT) by Julian Shapiro is a typographic manipulation library. It “blasts apart” text using delimiters, which can include character, word, sentence, and element. You could use it to animate text, or style it in some way

The documentation has visualisation for each delimiter, so you can easily see what each does. I can see it being useful in situations where you want to create carefully positioned magazine-like layouts, or reflow effects for responsive designs.

ng-polymer-elements, Easy CSS Animations

01 Aug 2014 | By Alex Young | Comments | Tags libraries graphics animation angularjs polymer


ng-polymer-elements (GitHub: GabiAxel / ng-polymer-elements, License: MIT) by Gabriel Axel is a library for mapping between AngularJS models and Polymer data-bindings.

It comes with support for various components, including core-input, paper-input, paper-checkbox, and paper-toast. As an example, binding the Angular scope’s myText property to Polymer’s paper-input looks like this:

<paper-input ng-model="myText"></paper-input>

You can extend the supported components by adding mappings to window.NG_POLYMER_ELEMENTS_EXTENDED_MAPPINGS. There’s an example of this in the readme.

Easy CSS Animations

Erica Salvaneschi wrote Easy CSS Animations, which demonstrates how to animate illustration-based web designs with CSS. The animations are subtle but interesting – I like the ones that persist after the initial page load.

CSS animations are an excellent way to make web pages look cool with relatively little effort. We used animations in our recent Windows Beta release page to bring our designer’s creative doodles to life. Since then we’ve released Papers 3 for Windows and created more pages with subtle animations.

We’ve extracted the CSS for you and shared it in this GitHub repository: mekentosj/blog-windows-animations.

She’s included some tips about using Retina.js, and basic drawing with CSS borders.

Natural Language Parsing with Retext

31 Jul 2014 | By Alex Young | Comments | Tags parsing text

Retext (GitHub: wooorm / retext, License: MIT, npm: retext) by Titus Wormer is an extensible module for analysing and manipulating natural language text. It’s built on two other modules by the same author. One is TextOM, which provides an object system for manipulating text, and the other is ParseLatin.

Given some text, ParseLatin returns syntax trees:

parseLatin.parse('A simple sentence.');
 * ˅ Object
 *    ˃ children: Array[1]
 *      type: "RootNode"
 *    ˃ __proto__: Object

These trees can then be processed as required. You can iterate over nodes or search them for values, it’s a bit like a DOM for plain text (or syntax/grammar).

The Retext module has lots of plugins. One example is an implementation of the Metaphone algorithmretext-double-metaphone. There’s also a short-code emoji parser, so you can actually build tightly focused text-processing modules with Retext. Another similar plugin is a typographic parsing library, which converts ASCII to HTML entities.

One cool use of Retext would be natural language date parsing, which is something that in my experience always ends up in a horrible mess of regular expressions. The author is still looking for a “retext-date” implementation, so it would be interesting to see what that looks like in Retext.

Node Roundup: Building Node.js Together, node-libnmap, httpolyglot

30 Jul 2014 | By Alex Young | Comments | Tags node modules libraries network security http

Building Node.js Together

TJ Fontaine wrote about Node from a release management perspective on the official Node blog, in Building Node.js Together. It covers documentation, code quality, and the growing team of core contributors and contributors that are employed full-time to work on Node:

For instance, Chris Dickinson was recently hired to work full time on Node.js, and has expressed interest in working on the current and future state of streams. But it’s not who employs Chris that makes him an ideal candidate, but it will be the quality of his contributions, and his understanding of the ethos of Node.js. That’s how we find members of the team.


The evilscan module uses JavaScript to enumerate over TCP ports. node-libnmap (GitHub: jas- / node-libnmap, License: MIT, npm: node-libnmap) by Jason Gerfen is an alternative that uses the nmap binary.

It will return results as JavaScript objects, so you should be able to process the output fairly easily. A basic scan looks like this:

var libnmap = require('libnmap');

var opts = {
  range: ['localhost', '', '']

libnmap.nmap('scan', opts, function(err, report){
  if (err) throw err


httpolyglot (GitHub: mscdex / httpolyglot, License: MIT, npm: httpolyglot) by Brian White allows you to start a server that accepts both HTTP and HTTPS connections on the same port.

It works by sniffing the first byte of the stream to see if TLS is required:

var firstByte = data[0];
if (firstByte < 32 || firstByte >= 127) {
  // tls/ssl
} else

BitcoinJS 1.0

29 Jul 2014 | By Alex Young | Comments | Tags bitcoin libraries

BitcoinJS 1.0 (GitHub: bitcoinjs / bitcoinjs-lib, License: MIT, npm: bitcoinjs-lib) has been released. This is a library for working with Bitcoins. For example, Bitcoin.ECKey.makeRandom can be used to generate a new address, and you can create transactions with new Bitcoin.Transaction().

The API is clean and easy to learn, and it comes with a test suite. It depends on crypto-js and some modules for working with base 58 encoding. Typed arrays are used to ensure it has solid performance.

BitcoinJS is a popular module, and is used by some popular Bitcoin-related services, including Hive Wallet,, and BitAddress.

It comes with support for browsers, so you can use it in client-side code as well as Node.

The 1.0 release signifies a milestone that the author has been working on since 2011. For more details, see the 1.0 announcement.

Blockies, Angular Debaser

28 Jul 2014 | By Alex Young | Comments | Tags libraries ui graphics angularjs testing


Blockies (GitHub: download13 / blockies, License: WTFPL) by Erin Dachtler is a small library that generates avatars based on a random seed and colour.

var icon = blockies.create({
  seed: 'randstring',
  color: '#dfe',
  size: 15,
  scale: 3

The arguments are all optional, and the output is a canvas element that you can insert into a container. The resulting images look a bit like the default GitHub avatars.

Angular Debaser

Angular Debaser (GitHub: decipherinc / angular-debaser, License: MIT) by Christopher Hiller is a library designed to cut down the amount of boilerplate required to test AngularJS projects.

When a module depends on a lot of services, then it can require a lot of stubs to test. To get around that, Debaser provides a more succinct syntax:

  .object('Settings', {
    location_id: 1

It uses angular-mocks, which is “ngMock” from the main AngularJS project.

TypeScript Log, Supplemental

25 Jul 2014 | By Alex Young | Comments | Tags typescript languages microsoft libraries

This week on DailyJS every post is about TypeScript! This article is a roundup of interesting TypeScript libraries.

This is the end of TypeScript week on DailyJS. I’ve been going through my email archives looking for TypeScript-related things that people have sent in. Here is a selection! As always, please share anything TypeScript (or JavaScript) related with me by going to


VCL.JS (GitHub: vclteam / VCL.JS, License: Apache 2.0) is a component-based web framework. The built-in components are based on Bootstrap, so the UI code should be quite easy to work with if you’ve used Bootstrap before.

It has deep Visual Studio integration, so Microsoft developers should be able to get started quickly. It even supports data binding and AMD for client-side code.


I’m intrigued by EndGate, a game framework for HTML5 games written in TypeScript. It has APIs for input, graphics, animations (tweening), and collision detection.

There’s a tutorial that explains how to use collisions and tweens. It seems to focus on map-based 2D games, which usually work well in browsers anyway.


One of the big things in C# 5.0 was the async modifier and await operator. These keywords allow C# code to be asynchronous, without callbacks or delegate methods.

The asyncawait module for Node is inspired by this API. You can await asynchronous methods, so you get to use non-blocking APIs with synchronous convenience:

var foo = async (function() {
    var resultA = await (firstAsyncCall());
    var resultB = await (secondAsyncCallUsing(resultA));
    var resultC = await (thirdAsyncCallUsing(resultB));
    return doSomethingWith(resultC);

This module is based on two great projects: node-fibers and bluebird, but it’s written with TypeScript:

TypeScript: asyncawait is written in TypeScript (look in the src folder), and includes a type declaration file. TypeScript makes JavaScript development faster, less error-prone, more scaleable, and generally more pleasant.

TypeScript's Compiler

24 Jul 2014 | By Alex Young | Comments | Tags typescript languages microsoft

This week on DailyJS every post is about TypeScript! This article is all about TypeScript's compiler.

This week a new TypeScript compiler was announced, along with the move of the project to GitHub.

Our work to date on the new compiler has been very promising. At its current level of completeness, the new compiler is able to compile existing real-world TypeScript code 5x faster than the currently shipping compiler. These results are still early. Once the compiler has reached parity, we’ll be able to report out a more complete picture of the performance improvements.

You might be wondering how the TypeScript compiler works. The source can be found at GitHub: Microsoft/TypeScript, and is written in TypeScript. It’s structured using features and idioms commonly used in TypeScript, like services and generics.

There’s a parser, scanner, and the infrastructure needed to work with command-line options and files. The parser generates nodes that are used by an “emitter” that produces the desired output. You’ll see a lot of switch statements matching on enums that relate to language constructs.

Comparison with Other Compilers

The CoffeeScript parser is generated from a Jison file – so unlike TypeScript it has an additional context free grammar file. There are attempts at writing Jison-based TypeScript compilers, which are interesting to look at. LiveScript is also based on Jison.

ClojureScript’s compiler transforms ClojureScript into JavaScript. Originally ClojureScript was written in Clojure, and I’m not sure if it’s self-hosted yet. There was a fork that is self-hosted, however.


One issue with JavaScript compilers is the fact you have to recompile files to JavaScript whenever you make a change. Fortunately, tsc has a --watch option, so you can write tsc -w file.ts to watch for changes on file.ts. This can easily be used with a module like nodemon to automatically restart the Node process (if you’re using Node) as well.

There are also Grunt and Gulp plugins for TypeScript:


It’s interesting that there seems to be three main approaches to transpiling JavaScript:

  • Parser based on a context-free grammar
  • Self-hosted hand-written parser
  • External language

If someone had showed me TypeScript I would have assumed it was written with a CLR-based language, so it’s cool that it’s self-hosted and able to easily run without Microsoft’s development tools.

TypeFramework: A TypeScript Web Framework

23 Jul 2014 | By Alex Young | Comments | Tags typescript languages microsoft

This week on DailyJS every post is about TypeScript! This post is about TypeFramework, a possibly Rails inspired web framwork aimed at TypeScript developers.

One of the aims of TypeScript is to help you write large applications. In Node, the popular idiom is “small modules” – programs are composed from small packages with APIs based on patterns found in Node’s core modules. That means EventEmitter, streams, callbacks with the error-first signature, and modules that return a single function.

This can work well, but people still seem to struggle to maintain larger web applications. Surely a TypeScript MVC framework offers insights on how to structure larger projects?

TypeFramework (GitHub: zekelevu / typeframework, License: MIT, npm: typeframework) by Zeke Kievel is built on Express. It has controllers, models, views, routing, and configuration. The models are based on the Waterline ORM, and they look like this:

class User extends TF.Model {
  name: string;
  email: string;
  age?: number;


The chainable API is quite nice:

  .where({ name: 'John' })
  .done((err, users: User[]) => { /* callback */ });

Everything looks very much like a lightweight Rails. It will probably help C# developers who want to write things that run on Node, or Rails developers who are transitioning to Node.

What I’d really like to see is a more MVVM-style framework with interfaces for code contracts, services, and ReactiveUI-style APIs. I’d prefer skinny models so I can avoid putting business logic in them and use my own persistance layer. I think TypeScript is perfectly suited to this, but I haven’t yet found such a framework.