March 2nd, 2010 – by Kris Zyp
CommonJS Utils is a collection of general purpose CommonJS-compliant modules. These modules can be used on Narwhal, Node, and other CommonJS platforms. The modules include:
- json-schema.js – This is a JSON Schema validator module. It can be used to validate data structures using JSON schema definitions. For example:
var validate = require("json-schema").validate;
var data = {name: "Test"};
var schema = {
properties: {
name: {type: "string"},
age: {type: "number"}
}
};
var validation = validate(data, schema);
validation.valid -> false
validation.errors -> indicates that age was not provided
data.age = 30;
var validation = validate(data, schema);
validation.valid -> true
This module also supports using standard native constructors as type definitions. The schema above could be written
more briefly:
var schema = {
properties: {
name: String,
age: Number
}
};
Continue reading
Tags: and Persevere 2.0, CommonJS, CommonJS Utils, pintura, Server-Side JavaScript
Posted in CommonJS | 4 Comments
January 19th, 2010 – by Kris Zyp
CommonJS (formerly known as ServerJS) has become the essential hub around the development of server side JavaScript (SSJS). SSJS for years has suffered from fragmentation, but the CommonJS project has provided the momentum to bring different frameworks together and start building interoperable modules. SSJS is ripe with potential; JavaScript has been soaring in popularity and the ECMAScript 5 specification was recently accepted. JavaScript has proven itself as the language of the web’s client-side (even ActionScript is a derivative of JavaScript). The opportunity to use the same language on both client and server is certainly most realistic and viable with JavaScript as it avoids the need for translation.
CommonJS
CommonJS has focused on developing critical APIs for building reusable modules, particularly for server-side JavaScript environment. The server-side is generally based around database interaction, file I/O, HTTP serving, and the generation of data formats and HTML, whereas the client-side is based around DOM manipulation and the browser object model. There are certainly APIs that can be used on both sides, and JavaScript on the client and server invites the reuse of APIs where possible. The WebWorker, Indexed Database, and XHR APIs are promising to be enormously beneficial on the server side, and with excellent client server consistency. But still the server side requires special attention, and CommonJS is bringing the needed standards and conventions.
Continue reading
Tags: CommonJS, Persevere 2.0, pintura, Server-Side JavaScript
Posted in CommonJS, JavaScript, Persevere, thoughts | 20 Comments