1 | exports.serialize = function(x) {
|
2 | if (typeof x === 'string') {
|
3 | return x;
|
4 | }
|
5 | else {
|
6 | return JSON.stringify(x || null);
|
7 | }
|
8 | };
|
9 |
|
10 | exports.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 | };
|