UNPKG

313 BJavaScriptView Raw
1exports.serialize = function(x) {
2 if (typeof x === 'string') {
3 return x;
4 }
5 else {
6 return JSON.stringify(x || null);
7 }
8};
9
10exports.deserialize = function(x) {
11 if (typeof x === 'string') {
12 try {
13 return JSON.parse(x);
14 } catch (e) {
15 return null;
16 }
17 }
18 return x || null;
19};