From 487f407a2ea117c4011f27ba4e08dc62f3c73e1b Mon Sep 17 00:00:00 2001 From: Feross Aboukhadijeh Date: Wed, 7 May 2014 16:13:57 -0700 Subject: [PATCH] code style --- index.js | 25 +++++++++++++------------ 1 file changed, 13 insertions(+), 12 deletions(-) diff --git a/index.js b/index.js index 2eafb89..d7210dd 100644 --- a/index.js +++ b/index.js @@ -135,7 +135,7 @@ Buffer.isBuffer = function (b) { Buffer.byteLength = function (str, encoding) { var ret - str = str + '' + str = str.toString() switch (encoding || 'utf8') { case 'hex': ret = str.length / 2 @@ -165,8 +165,7 @@ Buffer.byteLength = function (str, encoding) { } Buffer.concat = function (list, totalLength) { - assert(isArray(list), 'Usage: Buffer.concat(list, [totalLength])\n' + - 'list should be an Array.') + assert(isArray(list), 'Usage: Buffer.concat(list[, length])') if (list.length === 0) { return new Buffer(0) @@ -175,7 +174,7 @@ Buffer.concat = function (list, totalLength) { } var i - if (typeof totalLength !== 'number') { + if (totalLength === undefined) { totalLength = 0 for (i = 0; i < list.length; i++) { totalLength += list[i].length @@ -331,9 +330,7 @@ Buffer.prototype.toString = function (encoding, start, end) { encoding = String(encoding || 'utf8').toLowerCase() start = Number(start) || 0 - end = (end !== undefined) - ? Number(end) - : end = self.length + end = (end === undefined) ? self.length : Number(end) // Fastpath empty strings if (end === start) @@ -415,8 +412,9 @@ Buffer.prototype.copy = function (target, target_start, start, end) { var len = end - start if (len < 100 || !Buffer._useTypedArrays) { - for (var i = 0; i < len; i++) + for (var i = 0; i < len; i++) { target[i + target_start] = this[i + start] + } } else { target._set(this.subarray(start, start + len), target_start) } @@ -451,8 +449,9 @@ function _asciiSlice (buf, start, end) { var ret = '' end = Math.min(buf.length, end) - for (var i = start; i < end; i++) + for (var i = start; i < end; i++) { ret += String.fromCharCode(buf[i]) + } return ret } @@ -477,7 +476,7 @@ function _utf16leSlice (buf, start, end) { var bytes = buf.slice(start, end) var res = '' for (var i = 0; i < bytes.length; i += 2) { - res += String.fromCharCode(bytes[i] + bytes[i+1] * 256) + res += String.fromCharCode(bytes[i] + bytes[i + 1] * 256) } return res } @@ -938,8 +937,9 @@ Buffer.prototype.toArrayBuffer = function () { return (new Buffer(this)).buffer } else { var buf = new Uint8Array(this.length) - for (var i = 0, len = buf.length; i < len; i += 1) + for (var i = 0, len = buf.length; i < len; i += 1) { buf[i] = this[i] + } return buf.buffer } } else { @@ -1060,8 +1060,9 @@ function utf8ToBytes (str) { var start = i if (b >= 0xD800 && b <= 0xDFFF) i++ var h = encodeURIComponent(str.slice(start, i+1)).substr(1).split('%') - for (var j = 0; j < h.length; j++) + for (var j = 0; j < h.length; j++) { byteArray.push(parseInt(h[j], 16)) + } } } return byteArray -- 2.34.1