From 25af8df341442bd15416feed31237cb323f19cbf Mon Sep 17 00:00:00 2001 From: Feross Aboukhadijeh Date: Fri, 5 Jul 2019 14:44:28 -0700 Subject: [PATCH] standard --- index.js | 2 +- test/basic.js | 4 ++-- test/from-string.js | 36 ++++++++++++++++++------------------ test/methods.js | 4 ++-- test/to-string.js | 42 +++++++++++++++++++++--------------------- test/write.js | 2 +- 6 files changed, 45 insertions(+), 45 deletions(-) diff --git a/index.js b/index.js index c1719db..cee72d8 100644 --- a/index.js +++ b/index.js @@ -729,7 +729,7 @@ function bidirectionalIndexOf (buffer, val, byteOffset, encoding, dir) { return Uint8Array.prototype.lastIndexOf.call(buffer, val, byteOffset) } } - return arrayIndexOf(buffer, [ val ], byteOffset, encoding, dir) + return arrayIndexOf(buffer, [val], byteOffset, encoding, dir) } throw new TypeError('val must be string, number or Buffer') diff --git a/test/basic.js b/test/basic.js index b30c507..42808ac 100644 --- a/test/basic.js +++ b/test/basic.js @@ -25,7 +25,7 @@ test('indexes from a string', function (t) { }) test('indexes from an array', function (t) { - var buf = new B([ 97, 98, 99 ]) + var buf = new B([97, 98, 99]) t.equal(buf[0], 97) t.equal(buf[1], 98) t.equal(buf[2], 99) @@ -33,7 +33,7 @@ test('indexes from an array', function (t) { }) test('setting index value should modify buffer contents', function (t) { - var buf = new B([ 97, 98, 99 ]) + var buf = new B([97, 98, 99]) t.equal(buf[2], 99) t.equal(buf.toString(), 'abc') diff --git a/test/from-string.js b/test/from-string.js index 7b6601a..630dc15 100644 --- a/test/from-string.js +++ b/test/from-string.js @@ -18,14 +18,14 @@ test('detect utf16 surrogate pairs over U+20000 until U+10FFFF', function (t) { test('replace orphaned utf16 surrogate lead code point', function (t) { var text = '\uD83D\uDE38' + '\uD83D' + '\uD83D\uDC4D' var buf = new B(text) - t.deepEqual(buf, new B([ 0xf0, 0x9f, 0x98, 0xb8, 0xef, 0xbf, 0xbd, 0xf0, 0x9f, 0x91, 0x8d ])) + t.deepEqual(buf, new B([0xf0, 0x9f, 0x98, 0xb8, 0xef, 0xbf, 0xbd, 0xf0, 0x9f, 0x91, 0x8d])) t.end() }) test('replace orphaned utf16 surrogate trail code point', function (t) { var text = '\uD83D\uDE38' + '\uDCAD' + '\uD83D\uDC4D' var buf = new B(text) - t.deepEqual(buf, new B([ 0xf0, 0x9f, 0x98, 0xb8, 0xef, 0xbf, 0xbd, 0xf0, 0x9f, 0x91, 0x8d ])) + t.deepEqual(buf, new B([0xf0, 0x9f, 0x98, 0xb8, 0xef, 0xbf, 0xbd, 0xf0, 0x9f, 0x91, 0x8d])) t.end() }) @@ -44,42 +44,42 @@ test('handle partial utf16 code points when encoding to utf8 the way node does', var buf = new B(8) buf.fill(0) buf.write(text) - t.deepEqual(buf, new B([ 0xf0, 0x9f, 0x98, 0xb8, 0xf0, 0x9f, 0x91, 0x8d ])) + t.deepEqual(buf, new B([0xf0, 0x9f, 0x98, 0xb8, 0xf0, 0x9f, 0x91, 0x8d])) buf = new B(7) buf.fill(0) buf.write(text) - t.deepEqual(buf, new B([ 0xf0, 0x9f, 0x98, 0xb8, 0x00, 0x00, 0x00 ])) + t.deepEqual(buf, new B([0xf0, 0x9f, 0x98, 0xb8, 0x00, 0x00, 0x00])) buf = new B(6) buf.fill(0) buf.write(text) - t.deepEqual(buf, new B([ 0xf0, 0x9f, 0x98, 0xb8, 0x00, 0x00 ])) + t.deepEqual(buf, new B([0xf0, 0x9f, 0x98, 0xb8, 0x00, 0x00])) buf = new B(5) buf.fill(0) buf.write(text) - t.deepEqual(buf, new B([ 0xf0, 0x9f, 0x98, 0xb8, 0x00 ])) + t.deepEqual(buf, new B([0xf0, 0x9f, 0x98, 0xb8, 0x00])) buf = new B(4) buf.fill(0) buf.write(text) - t.deepEqual(buf, new B([ 0xf0, 0x9f, 0x98, 0xb8 ])) + t.deepEqual(buf, new B([0xf0, 0x9f, 0x98, 0xb8])) buf = new B(3) buf.fill(0) buf.write(text) - t.deepEqual(buf, new B([ 0x00, 0x00, 0x00 ])) + t.deepEqual(buf, new B([0x00, 0x00, 0x00])) buf = new B(2) buf.fill(0) buf.write(text) - t.deepEqual(buf, new B([ 0x00, 0x00 ])) + t.deepEqual(buf, new B([0x00, 0x00])) buf = new B(1) buf.fill(0) buf.write(text) - t.deepEqual(buf, new B([ 0x00 ])) + t.deepEqual(buf, new B([0x00])) t.end() }) @@ -90,42 +90,42 @@ test('handle invalid utf16 code points when encoding to utf8 the way node does', var buf = new B(8) buf.fill(0) buf.write(text) - t.deepEqual(buf, new B([ 0x61, 0xef, 0xbf, 0xbd, 0xef, 0xbf, 0xbd, 0x62 ])) + t.deepEqual(buf, new B([0x61, 0xef, 0xbf, 0xbd, 0xef, 0xbf, 0xbd, 0x62])) buf = new B(7) buf.fill(0) buf.write(text) - t.deepEqual(buf, new B([ 0x61, 0xef, 0xbf, 0xbd, 0xef, 0xbf, 0xbd ])) + t.deepEqual(buf, new B([0x61, 0xef, 0xbf, 0xbd, 0xef, 0xbf, 0xbd])) buf = new B(6) buf.fill(0) buf.write(text) - t.deepEqual(buf, new B([ 0x61, 0xef, 0xbf, 0xbd, 0x00, 0x00 ])) + t.deepEqual(buf, new B([0x61, 0xef, 0xbf, 0xbd, 0x00, 0x00])) buf = new B(5) buf.fill(0) buf.write(text) - t.deepEqual(buf, new B([ 0x61, 0xef, 0xbf, 0xbd, 0x00 ])) + t.deepEqual(buf, new B([0x61, 0xef, 0xbf, 0xbd, 0x00])) buf = new B(4) buf.fill(0) buf.write(text) - t.deepEqual(buf, new B([ 0x61, 0xef, 0xbf, 0xbd ])) + t.deepEqual(buf, new B([0x61, 0xef, 0xbf, 0xbd])) buf = new B(3) buf.fill(0) buf.write(text) - t.deepEqual(buf, new B([ 0x61, 0x00, 0x00 ])) + t.deepEqual(buf, new B([0x61, 0x00, 0x00])) buf = new B(2) buf.fill(0) buf.write(text) - t.deepEqual(buf, new B([ 0x61, 0x00 ])) + t.deepEqual(buf, new B([0x61, 0x00])) buf = new B(1) buf.fill(0) buf.write(text) - t.deepEqual(buf, new B([ 0x61 ])) + t.deepEqual(buf, new B([0x61])) t.end() }) diff --git a/test/methods.js b/test/methods.js index a63e4c4..273532b 100644 --- a/test/methods.js +++ b/test/methods.js @@ -5,7 +5,7 @@ test('buffer.toJSON', function (t) { var data = [1, 2, 3, 4] t.deepEqual( new B(data).toJSON(), - { type: 'Buffer', data: [ 1, 2, 3, 4 ] } + { type: 'Buffer', data: [1, 2, 3, 4] } ) t.end() }) @@ -41,7 +41,7 @@ test('test offset returns are correct', function (t) { test('concat() a varying number of buffers', function (t) { var zero = [] - var one = [ new B('asdf') ] + var one = [new B('asdf')] var long = [] for (var i = 0; i < 10; i++) { long.push(new B('asdf')) diff --git a/test/to-string.js b/test/to-string.js index b7305d0..393627f 100644 --- a/test/to-string.js +++ b/test/to-string.js @@ -117,11 +117,11 @@ test('utf8 to binary', function (t) { test('utf8 replacement chars (1 byte sequence)', function (t) { t.equal( - new B([ 0x80 ]).toString(), + new B([0x80]).toString(), '\uFFFD' ) t.equal( - new B([ 0x7F ]).toString(), + new B([0x7F]).toString(), '\u007F' ) t.end() @@ -129,19 +129,19 @@ test('utf8 replacement chars (1 byte sequence)', function (t) { test('utf8 replacement chars (2 byte sequences)', function (t) { t.equal( - new B([ 0xC7 ]).toString(), + new B([0xC7]).toString(), '\uFFFD' ) t.equal( - new B([ 0xC7, 0xB1 ]).toString(), + new B([0xC7, 0xB1]).toString(), '\u01F1' ) t.equal( - new B([ 0xC0, 0xB1 ]).toString(), + new B([0xC0, 0xB1]).toString(), '\uFFFD\uFFFD' ) t.equal( - new B([ 0xC1, 0xB1 ]).toString(), + new B([0xC1, 0xB1]).toString(), '\uFFFD\uFFFD' ) t.end() @@ -149,15 +149,15 @@ test('utf8 replacement chars (2 byte sequences)', function (t) { test('utf8 replacement chars (3 byte sequences)', function (t) { t.equal( - new B([ 0xE0 ]).toString(), + new B([0xE0]).toString(), '\uFFFD' ) t.equal( - new B([ 0xE0, 0xAC ]).toString(), + new B([0xE0, 0xAC]).toString(), '\uFFFD\uFFFD' ) t.equal( - new B([ 0xE0, 0xAC, 0xB9 ]).toString(), + new B([0xE0, 0xAC, 0xB9]).toString(), '\u0B39' ) t.end() @@ -165,27 +165,27 @@ test('utf8 replacement chars (3 byte sequences)', function (t) { test('utf8 replacement chars (4 byte sequences)', function (t) { t.equal( - new B([ 0xF4 ]).toString(), + new B([0xF4]).toString(), '\uFFFD' ) t.equal( - new B([ 0xF4, 0x8F ]).toString(), + new B([0xF4, 0x8F]).toString(), '\uFFFD\uFFFD' ) t.equal( - new B([ 0xF4, 0x8F, 0x80 ]).toString(), + new B([0xF4, 0x8F, 0x80]).toString(), '\uFFFD\uFFFD\uFFFD' ) t.equal( - new B([ 0xF4, 0x8F, 0x80, 0x84 ]).toString(), + new B([0xF4, 0x8F, 0x80, 0x84]).toString(), '\uDBFC\uDC04' ) t.equal( - new B([ 0xFF ]).toString(), + new B([0xFF]).toString(), '\uFFFD' ) t.equal( - new B([ 0xFF, 0x8F, 0x80, 0x84 ]).toString(), + new B([0xFF, 0x8F, 0x80, 0x84]).toString(), '\uFFFD\uFFFD\uFFFD\uFFFD' ) t.end() @@ -193,7 +193,7 @@ test('utf8 replacement chars (4 byte sequences)', function (t) { test('utf8 replacement chars on 256 random bytes', function (t) { t.equal( - new B([ 152, 130, 206, 23, 243, 238, 197, 44, 27, 86, 208, 36, 163, 184, 164, 21, 94, 242, 178, 46, 25, 26, 253, 178, 72, 147, 207, 112, 236, 68, 179, 190, 29, 83, 239, 147, 125, 55, 143, 19, 157, 68, 157, 58, 212, 224, 150, 39, 128, 24, 94, 225, 120, 121, 75, 192, 112, 19, 184, 142, 203, 36, 43, 85, 26, 147, 227, 139, 242, 186, 57, 78, 11, 102, 136, 117, 180, 210, 241, 92, 3, 215, 54, 167, 249, 1, 44, 225, 146, 86, 2, 42, 68, 21, 47, 238, 204, 153, 216, 252, 183, 66, 222, 255, 15, 202, 16, 51, 134, 1, 17, 19, 209, 76, 238, 38, 76, 19, 7, 103, 249, 5, 107, 137, 64, 62, 170, 57, 16, 85, 179, 193, 97, 86, 166, 196, 36, 148, 138, 193, 210, 69, 187, 38, 242, 97, 195, 219, 252, 244, 38, 1, 197, 18, 31, 246, 53, 47, 134, 52, 105, 72, 43, 239, 128, 203, 73, 93, 199, 75, 222, 220, 166, 34, 63, 236, 11, 212, 76, 243, 171, 110, 78, 39, 205, 204, 6, 177, 233, 212, 243, 0, 33, 41, 122, 118, 92, 252, 0, 157, 108, 120, 70, 137, 100, 223, 243, 171, 232, 66, 126, 111, 142, 33, 3, 39, 117, 27, 107, 54, 1, 217, 227, 132, 13, 166, 3, 73, 53, 127, 225, 236, 134, 219, 98, 214, 125, 148, 24, 64, 142, 111, 231, 194, 42, 150, 185, 10, 182, 163, 244, 19, 4, 59, 135, 16 ]).toString(), + new B([152, 130, 206, 23, 243, 238, 197, 44, 27, 86, 208, 36, 163, 184, 164, 21, 94, 242, 178, 46, 25, 26, 253, 178, 72, 147, 207, 112, 236, 68, 179, 190, 29, 83, 239, 147, 125, 55, 143, 19, 157, 68, 157, 58, 212, 224, 150, 39, 128, 24, 94, 225, 120, 121, 75, 192, 112, 19, 184, 142, 203, 36, 43, 85, 26, 147, 227, 139, 242, 186, 57, 78, 11, 102, 136, 117, 180, 210, 241, 92, 3, 215, 54, 167, 249, 1, 44, 225, 146, 86, 2, 42, 68, 21, 47, 238, 204, 153, 216, 252, 183, 66, 222, 255, 15, 202, 16, 51, 134, 1, 17, 19, 209, 76, 238, 38, 76, 19, 7, 103, 249, 5, 107, 137, 64, 62, 170, 57, 16, 85, 179, 193, 97, 86, 166, 196, 36, 148, 138, 193, 210, 69, 187, 38, 242, 97, 195, 219, 252, 244, 38, 1, 197, 18, 31, 246, 53, 47, 134, 52, 105, 72, 43, 239, 128, 203, 73, 93, 199, 75, 222, 220, 166, 34, 63, 236, 11, 212, 76, 243, 171, 110, 78, 39, 205, 204, 6, 177, 233, 212, 243, 0, 33, 41, 122, 118, 92, 252, 0, 157, 108, 120, 70, 137, 100, 223, 243, 171, 232, 66, 126, 111, 142, 33, 3, 39, 117, 27, 107, 54, 1, 217, 227, 132, 13, 166, 3, 73, 53, 127, 225, 236, 134, 219, 98, 214, 125, 148, 24, 64, 142, 111, 231, 194, 42, 150, 185, 10, 182, 163, 244, 19, 4, 59, 135, 16]).toString(), '\uFFFD\uFFFD\uFFFD\u0017\uFFFD\uFFFD\uFFFD\u002C\u001B\u0056\uFFFD\u0024\uFFFD\uFFFD\uFFFD\u0015\u005E\uFFFD\uFFFD\u002E\u0019\u001A\uFFFD\uFFFD\u0048\uFFFD\uFFFD\u0070\uFFFD\u0044\uFFFD\uFFFD\u001D\u0053\uFFFD\uFFFD\u007D\u0037\uFFFD\u0013\uFFFD\u0044\uFFFD\u003A\uFFFD\uFFFD\uFFFD\u0027\uFFFD\u0018\u005E\uFFFD\u0078\u0079\u004B\uFFFD\u0070\u0013\uFFFD\uFFFD\uFFFD\u0024\u002B\u0055\u001A\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD\u0039\u004E\u000B\u0066\uFFFD\u0075\uFFFD\uFFFD\uFFFD\u005C\u0003\uFFFD\u0036\uFFFD\uFFFD\u0001\u002C\uFFFD\uFFFD\u0056\u0002\u002A\u0044\u0015\u002F\uFFFD\u0319\uFFFD\uFFFD\uFFFD\u0042\uFFFD\uFFFD\u000F\uFFFD\u0010\u0033\uFFFD\u0001\u0011\u0013\uFFFD\u004C\uFFFD\u0026\u004C\u0013\u0007\u0067\uFFFD\u0005\u006B\uFFFD\u0040\u003E\uFFFD\u0039\u0010\u0055\uFFFD\uFFFD\u0061\u0056\uFFFD\uFFFD\u0024\uFFFD\uFFFD\uFFFD\uFFFD\u0045\uFFFD\u0026\uFFFD\u0061\uFFFD\uFFFD\uFFFD\uFFFD\u0026\u0001\uFFFD\u0012\u001F\uFFFD\u0035\u002F\uFFFD\u0034\u0069\u0048\u002B\uFFFD\uFFFD\uFFFD\u0049\u005D\uFFFD\u004B\uFFFD\u0726\u0022\u003F\uFFFD\u000B\uFFFD\u004C\uFFFD\uFFFD\u006E\u004E\u0027\uFFFD\uFFFD\u0006\uFFFD\uFFFD\uFFFD\uFFFD\u0000\u0021\u0029\u007A\u0076\u005C\uFFFD\u0000\uFFFD\u006C\u0078\u0046\uFFFD\u0064\uFFFD\uFFFD\uFFFD\uFFFD\u0042\u007E\u006F\uFFFD\u0021\u0003\u0027\u0075\u001B\u006B\u0036\u0001\uFFFD\uFFFD\uFFFD\u000D\uFFFD\u0003\u0049\u0035\u007F\uFFFD\uFFFD\uFFFD\uFFFD\u0062\uFFFD\u007D\uFFFD\u0018\u0040\uFFFD\u006F\uFFFD\uFFFD\u002A\uFFFD\uFFFD\u000A\uFFFD\uFFFD\uFFFD\u0013\u0004\u003B\uFFFD\u0010' ) t.end() @@ -201,23 +201,23 @@ test('utf8 replacement chars on 256 random bytes', function (t) { test('utf8 replacement chars for anything in the surrogate pair range', function (t) { t.equal( - new B([ 0xED, 0x9F, 0xBF ]).toString(), + new B([0xED, 0x9F, 0xBF]).toString(), '\uD7FF' ) t.equal( - new B([ 0xED, 0xA0, 0x80 ]).toString(), + new B([0xED, 0xA0, 0x80]).toString(), '\uFFFD\uFFFD\uFFFD' ) t.equal( - new B([ 0xED, 0xBE, 0x8B ]).toString(), + new B([0xED, 0xBE, 0x8B]).toString(), '\uFFFD\uFFFD\uFFFD' ) t.equal( - new B([ 0xED, 0xBF, 0xBF ]).toString(), + new B([0xED, 0xBF, 0xBF]).toString(), '\uFFFD\uFFFD\uFFFD' ) t.equal( - new B([ 0xEE, 0x80, 0x80 ]).toString(), + new B([0xEE, 0x80, 0x80]).toString(), '\uE000' ) t.end() diff --git a/test/write.js b/test/write.js index f6fc9f3..94e99d0 100644 --- a/test/write.js +++ b/test/write.js @@ -34,7 +34,7 @@ test('hex of write{Uint,Int}{8,16,32}{LE,BE}', function (t) { '03', '0300', '0003', '03000000', '00000003', 'fd', 'fdff', 'fffd', 'fdffffff', 'fffffffd' ] - var reads = [ 3, 3, 3, 3, 3, -3, -3, -3, -3, -3 ] + var reads = [3, 3, 3, 3, 3, -3, -3, -3, -3, -3] var xs = ['UInt', 'Int'] var ys = [8, 16, 32] for (var i = 0; i < xs.length; i++) { -- 2.34.1