Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Support buffer representation on node 6
- Loading branch information
1 parent
1490bc5
commit 77add28
Showing
3 changed files
with
37 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -85,7 +85,7 @@ | |
* | ||
* @return {String} | ||
*/ | ||
var getGlobalVariable = function (value, indent, stringify) { | ||
var toGlobalVariable = function (value, indent, stringify) { | ||
return 'Function(' + stringify('return this;') + ')()'; | ||
}; | ||
|
||
|
@@ -99,7 +99,12 @@ | |
// Map array values to their stringified values with correct indentation. | ||
var values = array.map(function (value) { | ||
var str = stringify(value); | ||
return indent + (str && str.split('\n').join('\n' + indent)); | ||
|
||
if (value === undefined) { | ||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
blakeembrey
Author
Owner
|
||
return String(str) | ||
} | ||
|
||
return indent + str.split('\n').join('\n' + indent); | ||
}).join(indent ? ',\n' : ','); | ||
|
||
// Wrap the array in newlines if we have indentation set. | ||
|
@@ -140,22 +145,39 @@ | |
|
||
return '{' + values + '}'; | ||
}, | ||
'[object Date]': function (date, indent, stringify) { | ||
'[object Date]': function (date) { | ||
return 'new Date(' + date.getTime() + ')'; | ||
}, | ||
'[object String]': function (string, indent, stringify) { | ||
'[object String]': function (string) { | ||
return 'new String(' + stringify(string.toString()) + ')'; | ||
}, | ||
'[object Number]': function (number, indent, stringify) { | ||
'[object Number]': function (number) { | ||
return 'new Number(' + number + ')'; | ||
}, | ||
'[object Boolean]': function (boolean, indent, stringify) { | ||
'[object Boolean]': function (boolean) { | ||
return 'new Boolean(' + boolean + ')'; | ||
}, | ||
'[object Uint8Array]': function (array, indent) { | ||
if (typeof Buffer === 'function' && Buffer.isBuffer(array)) { | ||
return 'new Buffer(' + stringify(array.toString()) + ')'; | ||
} | ||
|
||
if (indent) { | ||
var str = ''; | ||
|
||
for (var i = 0; i < array.length; i++) { | ||
str += indent + array[i] + ',\n' | ||
} | ||
|
||
return 'new Uint8Array([\n' + str + '\n])' | ||
} | ||
|
||
return 'new Uint8Array([' + array.join(indent ? ',\n' : ',') + '])' | ||
}, | ||
'[object RegExp]': String, | ||
'[object Function]': String, | ||
'[object global]': getGlobalVariable, | ||
'[object Window]': getGlobalVariable | ||
'[object global]': toGlobalVariable, | ||
'[object Window]': toGlobalVariable | ||
}; | ||
|
||
/** | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
It should be
if (str === undefined) {