Skip to content

Commit

Permalink
Merge branch 'master' of github.com:bjornstar/tomes into develop
Browse files Browse the repository at this point in the history
  • Loading branch information
Bjorn Stromberg committed Oct 22, 2013
2 parents a29c009 + bb824dc commit 04257c0
Show file tree
Hide file tree
Showing 9 changed files with 114 additions and 4 deletions.
7 changes: 6 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
[![Build Status](https://travis-ci.org/Wizcorp/node-tomes.png)](https://travis-ci.org/Wizcorp/node-tomes)

Tomes
=========
=====

*Evented Storage Agnostic Data API*

![Tomes Logo](https://raw.github.com/bjornstar/tomes/master/logo/tomes-logo-small.png)

Problem: You've got data and you want to do something whenever it changes.

Access and modify your data through the Tomes API and you'll get change events.
Expand Down Expand Up @@ -53,6 +55,9 @@ Returns data's type as a string. Tomes only has types that exist in JSON which a
###Tome.isTome( *data* )
Returns a boolean indicating whether data is a Tome or not.

###Tome.unTome( *tome* )
Returns a regular JavaScript version of your Tome.

##TomeTypes
- ArrayTome
- BooleanTome
Expand Down
2 changes: 1 addition & 1 deletion component.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "tomes",
"repo": "bjornstar/tomes",
"description": "Evented Storage Agnostic Data API",
"version": "0.0.13",
"version": "0.0.15",
"keywords": [ "data", "events" ],
"dependencies": {
"component/emitter": "*"
Expand Down
Binary file added logo/tomes-logo-big.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added logo/tomes-logo-less-big.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added logo/tomes-logo-medium.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added logo/tomes-logo-small.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "tomes",
"description": "Evented Storage Agnostic Data API",
"version": "0.0.13",
"version": "0.0.15",
"author": "Wizcorp, Inc. <info@wizcorp.jp>",
"maintainers": [
{ "name": "Bjorn Stromberg", "email": "bstromberg@wizcorp.jp" }
Expand All @@ -11,7 +11,8 @@
},
"main": "tomes.js",
"devDependencies": {
"nodeunit": "*"
"nodeunit": "*",
"rumplestiltskin": "*"
},
"license": {
"type": "MIT",
Expand Down
68 changes: 68 additions & 0 deletions test/modules/untome.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
var trueName = require('rumplestiltskin').trueName;
var Tome = require('../../tomes').Tome;

exports.unTomeNumber = function (test) {
test.expect(1);

var a = 1;
var b = Tome.conjure(a);

test.strictEqual(trueName(a), trueName(Tome.unTome(b)));

test.done();
};

exports.unTomeString = function (test) {
test.expect(1);

var a = 'the unTome.';
var b = Tome.conjure(a);

test.strictEqual(trueName(a), trueName(Tome.unTome(b)));

test.done();
};

exports.unTomeNull = function (test) {
test.expect(1);

var a = null;
var b = Tome.conjure(a);

test.strictEqual(trueName(a), trueName(Tome.unTome(b)));

test.done();
};

exports.unTomeBoolean = function (test) {
test.expect(1);

var a = false;
var b = Tome.conjure(a);

test.strictEqual(trueName(a), trueName(Tome.unTome(b)));

test.done();
};

exports.unTomeArray = function (test) {
test.expect(1);

var a = [ 0, 1, 2, 'hi', null, undefined, { a: 'nope' } ];
var b = Tome.conjure(a);

test.strictEqual(trueName(a), trueName(Tome.unTome(b)));

test.done();
};

exports.unTomeComplex = function (test) {
test.expect(1);

var a = { a: { b: true, c: undefined, d: null, e: [ 0, 1, 'hi', 'cat' ], f: { g: false } } };
var b = Tome.conjure(a);

test.strictEqual(trueName(a), trueName(Tome.unTome(b)));

test.done();
};
36 changes: 36 additions & 0 deletions tomes.js
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,42 @@ Tome.buildChain = function (tome) {
return chain.reverse();
};

Tome.unTome = function (tome) {
var out, keys;

var tomeType = Tome.typeOf(tome);

switch (tomeType) {
case 'object':
out = {};
keys = Object.keys(tome);
break;
case 'array':
out = new Array(tome.length);
keys = Object.keys(tome);
break;
case 'undefined':
out = undefined;
break;
case 'null':
out = null;
break;
default:
out = tome.valueOf();
break;
}

if (!keys) {
return out;
}

for (var i = 0; i < keys.length; i += 1) {
var key = keys[i];
out[key] = Tome.unTome(tome[key]);
}
return out;
};

function markDirty(tome, dirtyAt, was) {
if (tome.__dirty__ === dirtyAt) {
return;
Expand Down

0 comments on commit 04257c0

Please sign in to comment.