summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTrygve Laugstøl <trygvis@inamo.no>2012-07-17 01:46:14 +0200
committerTrygve Laugstøl <trygvis@inamo.no>2012-07-17 01:46:14 +0200
commitc9a39168e2dae9e7b301773047838649fda98d2a (patch)
tree5e824d17f86b2b712d945414b6908ad3465e8a1e
parent3f310615b388d428c68bbf3b773505c868e90db6 (diff)
downloadcollection_json.js-c9a39168e2dae9e7b301773047838649fda98d2a.tar.gz
collection_json.js-c9a39168e2dae9e7b301773047838649fda98d2a.tar.bz2
collection_json.js-c9a39168e2dae9e7b301773047838649fda98d2a.tar.xz
collection_json.js-c9a39168e2dae9e7b301773047838649fda98d2a.zip
o Ensuring all items has data too.HEADmaster
-rw-r--r--index.js3
-rw-r--r--package.json20
2 files changed, 20 insertions, 3 deletions
diff --git a/index.js b/index.js
index 07078cc..4ff993e 100644
--- a/index.js
+++ b/index.js
@@ -18,6 +18,7 @@ function fixTemplate(t) {
function fromObject(root) {
// console.log('in ', root);
+ root = _.isObject(root) ? root : {collection: {}};
root.isCollection = function() {
return typeof this.collection == 'object';
}
@@ -29,7 +30,6 @@ function fromObject(root) {
fixTemplate(root.template);
}
else {
- root = _.isObject(root) ? root : {collection: {}};
if(!_.isObject(root.collection)) {
root.collection = {};
}
@@ -38,6 +38,7 @@ function fromObject(root) {
c.version = _.isString(c.version) ? c.version : "1.0";
c.items = _.isArray(c.items) ? c.items : [];
_.each(c.items, function(item) {
+ item.data = _.isArray(item.data) ? item.data : [];
item.links = _.isArray(item.links) ? item.links : [];
item.toObject = toObject;
});
diff --git a/package.json b/package.json
index c4cccba..5db759f 100644
--- a/package.json
+++ b/package.json
@@ -2,11 +2,27 @@
"name": "collection_json",
"version": "0.0.1",
"description": "application/vnd.collection+json Utility library",
- "author": "Trygve Laugstøl <trygvis@inamo.no>",
+ "author": {
+ "name": "Trygve Laugstøl",
+ "email": "trygvis@inamo.no"
+ },
"dependencies": {
"underscore": "~1.3.3"
},
"devDependencies": {
"mocha": "1.0.3"
- }
+ },
+ "_id": "collection_json@0.0.1",
+ "optionalDependencies": {},
+ "engines": {
+ "node": "*"
+ },
+ "_engineSupported": true,
+ "_npmVersion": "1.1.24",
+ "_nodeVersion": "v0.6.19",
+ "_defaultsLoaded": true,
+ "dist": {
+ "shasum": "da0f9fcde4c882b1046ed6a828d4fe2967287495"
+ },
+ "_from": "collection+json@git+http://trygvis.dyndns.org/~trygvis/git/2012/06/collection+json.js.git"
}