Comparing version
@@ -1,8 +0,8 @@ | ||
// Generated by CoffeeScript 1.6.2 | ||
// Generated by CoffeeScript 1.9.1 | ||
(function() { | ||
var JSOG, isArray, nextId; | ||
var JSOG, JSOG_OBJECT_ID, hasCustomJsonificaiton, isArray, nextId; | ||
JSOG = {}; | ||
nextId = 1; | ||
nextId = 0; | ||
@@ -13,18 +13,21 @@ isArray = Array.isArray || function(obj) { | ||
hasCustomJsonificaiton = function(obj) { | ||
return obj.toJSON != null; | ||
}; | ||
JSOG_OBJECT_ID = '__jsogObjectId'; | ||
JSOG.encode = function(original) { | ||
var doEncode, idOf, sofar; | ||
sofar = {}; | ||
idOf = function(obj) { | ||
if (!obj.__jsogObjectId) { | ||
obj.__jsogObjectId = "" + (nextId++); | ||
if (!obj[JSOG_OBJECT_ID]) { | ||
obj[JSOG_OBJECT_ID] = "" + (nextId++); | ||
} | ||
return obj.__jsogObjectId; | ||
return obj[JSOG_OBJECT_ID]; | ||
}; | ||
doEncode = function(original) { | ||
var encodeArray, encodeObject; | ||
encodeObject = function(original) { | ||
var id, key, result, value; | ||
id = idOf(original); | ||
@@ -41,3 +44,3 @@ if (sofar[id]) { | ||
value = original[key]; | ||
if (key !== '__jsogObjectId') { | ||
if (key !== JSOG_OBJECT_ID) { | ||
result[key] = doEncode(value); | ||
@@ -50,12 +53,10 @@ } | ||
var val; | ||
return (function() { | ||
var _i, _len, _results; | ||
_results = []; | ||
for (_i = 0, _len = original.length; _i < _len; _i++) { | ||
val = original[_i]; | ||
_results.push(doEncode(val)); | ||
var i, len, results; | ||
results = []; | ||
for (i = 0, len = original.length; i < len; i++) { | ||
val = original[i]; | ||
results.push(doEncode(val)); | ||
} | ||
return _results; | ||
return results; | ||
})(); | ||
@@ -65,2 +66,4 @@ }; | ||
return original; | ||
} else if (hasCustomJsonificaiton(original)) { | ||
return original; | ||
} else if (isArray(original)) { | ||
@@ -79,10 +82,7 @@ return encodeArray(original); | ||
var doDecode, found; | ||
found = {}; | ||
doDecode = function(encoded) { | ||
var decodeArray, decodeObject; | ||
decodeObject = function(encoded) { | ||
var id, key, ref, result, value; | ||
ref = encoded['@ref']; | ||
@@ -113,12 +113,10 @@ if (ref != null) { | ||
var value; | ||
return (function() { | ||
var _i, _len, _results; | ||
_results = []; | ||
for (_i = 0, _len = encoded.length; _i < _len; _i++) { | ||
value = encoded[_i]; | ||
_results.push(doDecode(value)); | ||
var i, len, results; | ||
results = []; | ||
for (i = 0, len = encoded.length; i < len; i++) { | ||
value = encoded[i]; | ||
results.push(doDecode(value)); | ||
} | ||
return _results; | ||
return results; | ||
})(); | ||
@@ -125,0 +123,0 @@ }; |
{ | ||
"name": "jsog", | ||
"version": "1.0.6", | ||
"main": "lib/JSOG", | ||
"devDependencies": { | ||
"coffee-script": "1.7.x", | ||
"mocha": "1.9.x" | ||
}, | ||
"scripts": { | ||
"build": "coffee --compile --lint --output lib/ src/*.coffee", | ||
"prepublish": "coffee --compile --lint --output lib/ src/*.coffee", | ||
"test": "./node_modules/.bin/mocha" | ||
}, | ||
"repository": { | ||
"type": "git", | ||
"url": "https://github.com/jsog/jsog" | ||
}, | ||
"bugs": { | ||
"url": "https://github.com/jsog/jsog/issues" | ||
}, | ||
"licenses": [ | ||
{ | ||
"type": "MIT", | ||
"url": "http://opensource.org/licenses/MIT" | ||
} | ||
] | ||
"name": "jsog", | ||
"version": "1.0.7", | ||
"main": "lib/JSOG", | ||
"devDependencies": { | ||
"coffee-script": "^1.9.1", | ||
"mocha": "*", | ||
"moment": "^2.9.0" | ||
}, | ||
"scripts": { | ||
"compile": "coffee --compile --output lib/ src/*.coffee && coffee --compile --output test/ src-test/*.coffee", | ||
"build": "npm run-script compile", | ||
"prepublish": "npm run-script compile", | ||
"test": "npm run-script compile && ./node_modules/.bin/mocha" | ||
}, | ||
"repository": { | ||
"type": "git", | ||
"url": "https://github.com/jsog/jsog" | ||
}, | ||
"bugs": { | ||
"url": "https://github.com/jsog/jsog/issues" | ||
}, | ||
"licenses": [ | ||
{ | ||
"type": "MIT", | ||
"url": "http://opensource.org/licenses/MIT" | ||
} | ||
] | ||
} |
@@ -1,4 +0,4 @@ | ||
// Generated by CoffeeScript 1.6.3 | ||
// Generated by CoffeeScript 1.9.1 | ||
(function() { | ||
var JSOG, assert; | ||
var JSOG, assert, moment; | ||
@@ -9,2 +9,4 @@ assert = require('assert'); | ||
moment = require('moment'); | ||
describe('leaving original object alone', function() { | ||
@@ -99,2 +101,13 @@ var foo; | ||
describe('custom json serialization', function() { | ||
return it('should leave objects with toJSON methods alone', function() { | ||
var encoded, foo; | ||
foo = { | ||
foo: moment() | ||
}; | ||
encoded = JSOG.encode(foo); | ||
return assert(encoded.foo === foo.foo); | ||
}); | ||
}); | ||
}).call(this); |
Sorry, the diff of this file is not supported yet
64374
280.44%21
75%277
23.11%3
50%