DailyJS

DailyJS

The JavaScript blog.


Tagdependencies
Featured

dependencies node modules authentication windows oauth

Node Roundup: 0.11.0, Dependo, Mashape OAuth, node-windows

Posted on .

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

0.11.0, 0.10.2

Node 0.11.0 has been released, which is the latest unstable branch of Node. Node 0.10.12 was also released, which includes some fixes for the stream module, an update for the internal uv library, and various other fixes for cryptographic modules and child_process.

Dependo

Dependo

Dependo (GitHub: auchenberg / dependo, License: MIT, npm: dependo) by Kenneth Auchenberg is a visualisation tool for generating force directed graphs of JavaScript dependencies. It can interpret CommonJS or AMD dependencies, and uses MaDGe to generate the raw dependency graph. D3.js is used for drawing the results.

Mashape OAuth

Mashape OAuth (GitHub: Mashape / mashape-oauth, License: MIT, npm: mashape-oauth) by Nijiko Yonskai is a set of modules for OAuth and OAuth2. It has been designed to work with lots of variations of OAuth implementations, and includes some lengthy Mocha unit tests.

The authors have also written a document called The OAuth Bible that explains the main concepts behind each supported OAuth variation, which is useful because the OAuth terminology isn't exactly easy to get to grips with.

node-windows

node-windows (GitHub: coreybutler / node-windows, License: MIT/BSD, npm: node-windows) by Corey Butler is a module designed to help write long-running Windows services with Node. It supports event logging and process management without requiring Visual Studio or the .NET Framework.

Using native node modules on Windows can suck. Most native modules are not distributed in a binary format. Instead, these modules rely on npm to build the project, utilizing node-gyp. This means developers need to have Visual Studio (and potentially other software) installed on the system, just to install a native module. This is portable, but painful... mostly because Visual Studio itself is over 2GB.

node-windows does not use native modules. There are some binary/exe utilities, but everything needed to run more complex tasks is packaged and distributed in a readily usable format. So, no need for Visual Studio... at least not for this module.

Featured

webkit server dependencies loading games

PhantomJS, load.js, Phantom Limb, OpenOdyssey

Posted on .

PhantomJS

PhantomJS by Ariya Hidayat is a WebKit-based JavaScript tool for exploiting the power of WebKit. Let's
say you want to generate a PNG from an SVG file:

if (phantom.state.length === 0) {
  if (phantom.args.length !== 2) {
    console.log('Usage: rasterize.js URL filename');
    phantom.exit();
  } else {
    var address = phantom.args[0];
    phantom.state = 'rasterize';
    phantom.viewportSize = { width: 600, height: 600 };
    phantom.open(address);
  }
} else {
  var output = phantom.args[1];
  phantom.sleep(200);
  phantom.render(output);
  phantom.exit();
}

This will produce a PNG when run through phantomjs on the
command line:

phantomjs rasterize.js http://ariya.github.com/svg/tiger.svg tiger.png

This example is from the PhantomJS
QuickStart
.

What really interests me about this project is generating nice PDFs from
HTML. WebKit has been ported to quite a few platforms, and PhantomJS
should run on Linux, Windows, and Mac OS X, so it could be a great tool
to have on your server.

load.js

load.js by Chris O'Hara is a small lazy-loading and dependency management library:

load('jquery.js').then('jquery-ui.js', 'jquery-ui-theme.js')
  .then('myscript.js')
  .thenRun(function () {
    alert('Loaded.');
  });

load('underscore.js');

I like the chained API, which just so happens to be created with
chain.js by the same author.

Phantom Limb

Phantom Limb by Brian Carstensen makes desktop browsers to simulate touchscreen device events:

A mousedown fires a touchstart. A mousemove fires a touchmove if the mouse is down, and a mouseup fires a touchend. These custom events are also assigned a touches array containing a reference to the event, just like a real touch event in a mobile browser.

Brian pointed out that this makes debugging mobile apps easier, because
you're not limited to Mobile Safari's limited debugging tools. There's
also a bookmarklet for activating Phantom Limb, which means you could
use it on any page.

WebGL Model Viewer

Christopher Chedeau sent us a link to
jDataView, a library for reading binary files in browsers. His blog post, Javascript - jDataView: Read
Binary
File

includes some background on the project and a great demo: a World of
Warcraft Model
Viewer
.
You'll need a WebGL-enabled browser to view this demo.

Dealing with binary data is inherent to games development, so it's worth
taking a look at jDataView if you're working in that area.

OpenOdyssey

OpenOdyssey by Michal Budzynski for the Mozilla GameOn
Competition
is a simple browser-based
game that uses the Mibbu game framework. The basic
gameplay mechanics are fairly solid, so it'll be interesting to see what
Mibbu is like when Michal releases it.

Featured

dependencies loading

Script Loading and Dependencies

Posted on .

I've created a few projects that are self-contained HTML/JavaScript
files -- small utilities that are easy to share or stash on a USB stick.
When writing this type of project I like to use a script loader like
Google's AJAX Libraries so I don't need to bundle separate files. Another use case is for very
complex projects: Google's API allows you to easily switch between
different library versions which is great for testing against a new
version of a big library like jQuery.

Dominoes

If you have a place to host code you might still want to use a script
loader. I've recently been looking at
javascript-dominoes which includes script loading, aliasing and dependencies. The dependency
engine in particular allows you to express rules that permit scripts to
be loaded concurrently, which could improve the load times of your
pages.

The following examples are from the hands
on

documentation on the javascript-dominoes site.

Script Loading

Basic usage is like this:

dominoes("http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js" , function() {
    // jQuery dependant code goes here
} );

If this is called twice dominoes will automatically detect that the
script has already been loaded.

Substitution

Properties can be defined to shorten configuration:

dominoes.property("mySiteJSPath" , "http://mySite.org/u/kio/67/long/is/long/js");
dominoes("${mySiteJSPath}/script1.js" , function1);

Dependencies

If you have a script that does not depend on jQuery, you can tell
dominoes to concurrently load the scripts:

dominoes("${jQueryURL} ./js/myScript/js" , myFunction);

Dependencies can be expressed using operators:

action1 action2 action1 & action2 are independant
action1 > action2 action2 depends on the completion of action1
action1 >| action2 action2 depends on the completion of action1 and on the DOM being ready for manipulation
{ sub-rule } sub-rule (the completion of this action is determined by the completion of the whole sub-rule)
{{ "{{" }} optional-sub-rule }} optional sub-rule (same as a normal sub-rule but the completion of this action is not needed down the line, i.e. fire & forget)