json-buffer
Advanced tools
Comparing version 1.0.0 to 2.0.0
16
index.js
@@ -9,6 +9,6 @@ var Buffer = require('buffer').Buffer | ||
if(o && Buffer.isBuffer(o)) | ||
o = o.toString('base64') | ||
return JSON.stringify(':base64:' + o.toString('base64')) | ||
if(o && o.toJSON) | ||
o = o.toJSON() | ||
o = o.toJSON() | ||
@@ -33,3 +33,5 @@ if(o && 'object' === typeof o) { | ||
return s | ||
} else | ||
} else if ('string' === typeof o) { | ||
return JSON.stringify(/^:/.test(o) ? ':' + o : o) | ||
} else | ||
return JSON.stringify(o) | ||
@@ -40,6 +42,10 @@ } | ||
return JSON.parse(s, function (key, value) { | ||
if('string' === typeof value && /==$/.test(value)) | ||
return new Buffer(value, 'base64') | ||
if('string' === typeof value) { | ||
if(/^:base64:/.test(value)) | ||
return new Buffer(value.substring(8), 'base64') | ||
else | ||
return /^:/.test(value) ? value.substring(1) : value | ||
} | ||
return value | ||
}) | ||
} |
{ | ||
"name": "json-buffer", | ||
"description": "", | ||
"version": "1.0.0", | ||
"version": "2.0.0", | ||
"homepage": "https://github.com/dominictarr/json-buffer", | ||
@@ -6,0 +6,0 @@ "repository": { |
@@ -20,2 +20,12 @@ | ||
boolean2: false | ||
}, | ||
foo: new Buffer('foo'), | ||
foo2: new Buffer('foo2'), | ||
escape: { | ||
buffer: new Buffer('x'), | ||
string: _JSON.stringify(new Buffer('x')) | ||
}, | ||
escape2: { | ||
buffer: new Buffer('x'), | ||
string: ':base64:'+ new Buffer('x').toString('base64') | ||
} | ||
@@ -28,5 +38,5 @@ } | ||
var s = _JSON.stringify(value) | ||
console.log(s) | ||
var _value = _JSON.parse(s) | ||
t.deepEqual(toJSON(_value), toJSON(value)) | ||
console.log(k, value) | ||
t.end() | ||
@@ -33,0 +43,0 @@ }) |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
4139
78