Skip to content

Commit

Permalink
Merge pull request #6 from lihe1314/master
Browse files Browse the repository at this point in the history
Update main.js
  • Loading branch information
rgcl committed Jul 8, 2014
2 parents cc338a5 + 9b8e514 commit 3742489
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions main.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
var TOKEN_FALSE = -2;
var TOKEN_NULL = -3;
var TOKEN_EMPTY_STRING = -4;
var TOKEN_UNDEFINED = -5;

var pack = function(json, options) {

Expand Down Expand Up @@ -50,6 +51,14 @@
index : TOKEN_NULL
};
}

//add undefined
if (typeof item === 'undefined') {
return {
type : 'undefined',
index : TOKEN_UNDEFINED
};
}

// Case 1: The item is Array Object
if ( item instanceof Array) {
Expand Down Expand Up @@ -224,6 +233,10 @@
return TOKEN_NULL;
}

if (type === 'undefined') {
return TOKEN_UNDEFINED;
}

if (type === 'empty') {
return TOKEN_EMPTY_STRING;
}
Expand Down Expand Up @@ -346,6 +359,9 @@
case TOKEN_NULL:
node.push(null);
break;
case TOKEN_UNDEFINED:
node.push(undefined);
break;
case TOKEN_EMPTY_STRING:
node.push('');
break;
Expand Down Expand Up @@ -393,6 +409,9 @@
case TOKEN_NULL:
node[key] = null;
break;
case TOKEN_UNDEFINED:
node[key] = undefined;
break;
case TOKEN_EMPTY_STRING:
node[key] = '';
break;
Expand Down Expand Up @@ -431,6 +450,11 @@
if (value === null)
return TOKEN_NULL;

//add undefined
if (typeof value === 'undefined')
return TOKEN_UNDEFINED;


if (value === '') {
return TOKEN_EMPTY_STRING;
}
Expand Down

0 comments on commit 3742489

Please sign in to comment.