Skip to content

Commit

Permalink
Merge pull request #20 from bjornstar/master
Browse files Browse the repository at this point in the history
v0.0.14: You can now unTome a Tome.
  • Loading branch information
Ron Korving committed Mar 22, 2013
2 parents c76d622 + e63eb8c commit 2f1daa4
Show file tree
Hide file tree
Showing 5 changed files with 111 additions and 3 deletions.
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,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.14",
"keywords": [ "data", "events" ],
"dependencies": {
"component/emitter": "*"
Expand Down
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.14",
"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 2f1daa4

Please sign in to comment.