Skip to content

Commit

Permalink
Convert ArrayBuffer
Browse files Browse the repository at this point in the history
Close #260
  • Loading branch information
maxcnunes committed Jan 28, 2017
1 parent 12c7825 commit ba2550e
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions src/renderer/utils/convert.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,17 +20,40 @@ export function valueToString(value) {
if (value === null) {
return 'NULL';
}

if (typeof value === 'boolean') {
return value.toString();
}

if (!value) {
return String(value);
}

if (value.toISOString) {
return value.toISOString();
}

if (typeof value === 'object') {
if (isArrayBuffer(value)) {
return arrayBufferToString(value);
}

return JSON.stringify(value);
}

return String(value);
}

function arrayBufferToString(buf) {
if (buf.length === 1) {
// Probably is a bit column
return String(buf[0]);
}
return buf.toString('utf-8');
}

// reference:
// http://stackoverflow.com/a/21799845/1050818
function isArrayBuffer(value) {
return value && value.buffer instanceof ArrayBuffer && value.byteLength !== undefined;
}

0 comments on commit ba2550e

Please sign in to comment.