an experiment in implementing microdata via JSON objects
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Failed to load latest commit information.




schemathing-js is an experiment in implementing a set of javascript objects that map to/from the microdata format as defined at

A example Thing

A +Thing+ object might have the following methods --

factory operations


params: an object (optional) E.g. A mongo object id. { _id: "MONGO_ID_STRING" }

Creates a new thing object. If an _id is with an object it will use that id (e.g. so you could instantiate a copy of a MongoDB object). If not it will create an _id property using a NewObjectId() function if defined.


params: object_id (optional) E.g. A mongo object id. { _id: "MONGO_ID_STRING" }

Creates a copy of itself as a new thing but with a new object_id.

comparison operations


params: an object (required)

Checks if an object has same properties (other object could have additional properties)


params: an object (required)

Both objects have every property in common


params: an object (required)

Check to see if properties in common are equal (==).


params: an object (required)

Check to see if common properties are strictly equal (===).


params: an object (required)

Check to see if properties in common are not equal (!=); returns true of false.


params: an object (required)

Check to see if properties in common are strictly not equal (!==); returns true or false.

transformation functions


params: an object (required)

Replace common properties from another object (except _id)


params: an object (required)

Update and add additional properties from another object (except _id, merge _isA list)


params: an object (required)

Overwrite and add additional properties passed into morph (except _id, merge _isA list)

rendering functions

schemething relies on mote-js for implementing handlebars templates and rendering html.


params: options (optional) an array of attribute strings (e.g. ['id="myid"', 'class="myclass"'])

Render the default template with mote into HTML adding necessary attributes to outer div.


params: none

Render as a JSON object.

A theoretical example using the module in NodeJS

var assert = require('assert'),
	schema = require('schemathing');

// Dummy Object id objects and functions
var ObjectIds = { _id: 0 },
	NewObjectId = function () {
		ObjectIds._id += 1;
		return ObjectIds._id;
	LastObjectId = function () {
		return ObjectIds._id;

// Example playing with things
var aThing, aClonedThing,
	aThingLikeObject = {
		description: "A plain old JavaScript object.",
		image: "",
		name: 'aThingLikeObject',
		url: ""

// Creating an empty thing
aThing = scheme.Thing.create({_id:1});
assert.strictEqual(aThing._id, 1, "aThing._id === 1");
// Should return false since aThing has nothing in common with aThingLikeObject
assert.ok(aThing.equal(aThinkLikeObject),"aThing == aThingLikeObject" );
// Merging aThingLikeObject
assert.ok(aThing.equal(aThingLikeObject),"aThing == aThingLikeObject");
assert.ok(! aThing.strictEqual(aThingLikeObject),"aThing === aThingLikeObject");
// Cloning, aClonedThing should have _id: 2
aClonedThing = aThing.clone();
assert.strictEqual(aClonedThing._id, 2, "aClonedThing should have an id: 2");
// Should be true because everything in common is equal
assert.ok(aThing.equal(aThingLikeObject),"aClonedThing == aThingLikeObject");
// Should be false because aThingLikeObject._id is missing
assert.ok(aThing.strictEqual(aThingLikeObject),"aClonedThing === aThingLikeObject");
// Should be true because all the fields, except _id are in common
assert.ok(aClonedThing.equal(aThing),"aClonedThing == aThing");
// Should be false since the _id is different
assert.ok(aClonedThing.strictEqual(aThing),"aClonedThing === aThing");

aEvent = schema.Event.create();
aEvent.merge(AThingLikeObject); = "A new Event.";
aEvent.duration = '2h';
aEvent.startDate = new Date();
aEvent.endDate = new Date();
console.log("aEvent.toJSON(): " + aEvent.toJSON());
console.log("aEvent.toHtml(): " + aEvent.toHtml());

Background notes

Random ideas

  • schemathing.js should work in NodeJS, MongoDB's shell and HTML5 friendly browsers
  • dirty.js would be an interesting environment to play with shemathing for in-memory only applications
  • the property types need to be validated against's description (e.g. Boolean, Date, Number, Text, URL)

Notes on coding style

  • exported functions begin with a capital letter and are camel case (e.g. Assemble())
  • exported objects begin with a capitil letter and are camel case (e.g. Thing)
  • functions starting with lowercase are intended to be object methods applied by a factory (e.g. var myt = Thing.create(); console.log(myt.toJSON());)