buffer: alias UInt ➡️ Uint in buffer methods

It’s *so* hard to remember that it’s `UintXArray` but not
`(write|read)UintX`. Let’s fix that by just providing aliases. 😊

PR-URL: https://github.com/nodejs/node/pull/34729
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
Reviewed-By: Rich Trott <rtrott@gmail.com>
This commit is contained in:
Anna Henningsen committed 2020-09-22 23:48:06 +02:00
1 parent 987e0cb785
commit 9d07217d2c
3 files changed
+65

No files matched your search

+42
View File
@@ -1705,6 +1705,9 @@ console.log(buf.readIntLE(0, 6).toString(16));
<!-- YAML
added: v0.5.0
changes:
- version: REPLACEME
pr-url: https://github.com/nodejs/node/pull/34729
description: This function is also available as `buf.readUint8()`.
- version: v10.0.0
pr-url: https://github.com/nodejs/node/pull/18395
description: Removed `noAssert` and no implicit coercion of the offset
@@ -1732,6 +1735,9 @@ console.log(buf.readUInt8(2));
<!-- YAML
added: v0.5.5
changes:
- version: REPLACEME
pr-url: https://github.com/nodejs/node/pull/34729
description: This function is also available as `buf.readUint16BE()`.
- version: v10.0.0
pr-url: https://github.com/nodejs/node/pull/18395
description: Removed `noAssert` and no implicit coercion of the offset
@@ -1758,6 +1764,9 @@ console.log(buf.readUInt16BE(1).toString(16));
<!-- YAML
added: v0.5.5
changes:
- version: REPLACEME
pr-url: https://github.com/nodejs/node/pull/34729
description: This function is also available as `buf.readUint16LE()`.
- version: v10.0.0
pr-url: https://github.com/nodejs/node/pull/18395
description: Removed `noAssert` and no implicit coercion of the offset
@@ -1786,6 +1795,9 @@ console.log(buf.readUInt16LE(2).toString(16));
<!-- YAML
added: v0.5.5
changes:
- version: REPLACEME
pr-url: https://github.com/nodejs/node/pull/34729
description: This function is also available as `buf.readUint32BE()`.
- version: v10.0.0
pr-url: https://github.com/nodejs/node/pull/18395
description: Removed `noAssert` and no implicit coercion of the offset
@@ -1810,6 +1822,9 @@ console.log(buf.readUInt32BE(0).toString(16));
<!-- YAML
added: v0.5.5
changes:
- version: REPLACEME
pr-url: https://github.com/nodejs/node/pull/34729
description: This function is also available as `buf.readUint32LE()`.
- version: v10.0.0
pr-url: https://github.com/nodejs/node/pull/18395
description: Removed `noAssert` and no implicit coercion of the offset
@@ -1836,6 +1851,9 @@ console.log(buf.readUInt32LE(1).toString(16));
<!-- YAML
added: v0.11.15
changes:
- version: REPLACEME
pr-url: https://github.com/nodejs/node/pull/34729
description: This function is also available as `buf.readUintBE()`.
- version: v10.0.0
pr-url: https://github.com/nodejs/node/pull/18395
description: Removed `noAssert` and no implicit coercion of the offset
@@ -1865,6 +1883,9 @@ console.log(buf.readUIntBE(1, 6).toString(16));
<!-- YAML
added: v0.11.15
changes:
- version: REPLACEME
pr-url: https://github.com/nodejs/node/pull/34729
description: This function is also available as `buf.readUintLE()`.
- version: v10.0.0
pr-url: https://github.com/nodejs/node/pull/18395
description: Removed `noAssert` and no implicit coercion of the offset
@@ -2643,6 +2664,9 @@ console.log(buf);
<!-- YAML
added: v0.5.0
changes:
- version: REPLACEME
pr-url: https://github.com/nodejs/node/pull/34729
description: This function is also available as `buf.writeUint8()`.
- version: v10.0.0
pr-url: https://github.com/nodejs/node/pull/18395
description: Removed `noAssert` and no implicit coercion of the offset
@@ -2674,6 +2698,9 @@ console.log(buf);
<!-- YAML
added: v0.5.5
changes:
- version: REPLACEME
pr-url: https://github.com/nodejs/node/pull/34729
description: This function is also available as `buf.writeUint16BE()`.
- version: v10.0.0
pr-url: https://github.com/nodejs/node/pull/18395
description: Removed `noAssert` and no implicit coercion of the offset
@@ -2703,6 +2730,9 @@ console.log(buf);
<!-- YAML
added: v0.5.5
changes:
- version: REPLACEME
pr-url: https://github.com/nodejs/node/pull/34729
description: This function is also available as `buf.writeUint16LE()`.
- version: v10.0.0
pr-url: https://github.com/nodejs/node/pull/18395
description: Removed `noAssert` and no implicit coercion of the offset
@@ -2732,6 +2762,9 @@ console.log(buf);
<!-- YAML
added: v0.5.5
changes:
- version: REPLACEME
pr-url: https://github.com/nodejs/node/pull/34729
description: This function is also available as `buf.writeUint32BE()`.
- version: v10.0.0
pr-url: https://github.com/nodejs/node/pull/18395
description: Removed `noAssert` and no implicit coercion of the offset
@@ -2760,6 +2793,9 @@ console.log(buf);
<!-- YAML
added: v0.5.5
changes:
- version: REPLACEME
pr-url: https://github.com/nodejs/node/pull/34729
description: This function is also available as `buf.writeUint32LE()`.
- version: v10.0.0
pr-url: https://github.com/nodejs/node/pull/18395
description: Removed `noAssert` and no implicit coercion of the offset
@@ -2788,6 +2824,9 @@ console.log(buf);
<!-- YAML
added: v0.5.5
changes:
- version: REPLACEME
pr-url: https://github.com/nodejs/node/pull/34729
description: This function is also available as `buf.writeUintBE()`.
- version: v10.0.0
pr-url: https://github.com/nodejs/node/pull/18395
description: Removed `noAssert` and no implicit coercion of the offset
@@ -2818,6 +2857,9 @@ console.log(buf);
<!-- YAML
added: v0.5.5
changes:
- version: REPLACEME
pr-url: https://github.com/nodejs/node/pull/34729
description: This function is also available as `buf.writeUintLE()`.
- version: v10.0.0
pr-url: https://github.com/nodejs/node/pull/18395
description: Removed `noAssert` and no implicit coercion of the offset
+14
View File
@@ -961,6 +961,13 @@ function addBufferPrototypeMethods(proto) {
proto.readUIntBE = readUIntBE;
proto.readUInt32BE = readUInt32BE;
proto.readUInt16BE = readUInt16BE;
proto.readUintLE = readUIntLE;
proto.readUint32LE = readUInt32LE;
proto.readUint16LE = readUInt16LE;
proto.readUint8 = readUInt8;
proto.readUintBE = readUIntBE;
proto.readUint32BE = readUInt32BE;
proto.readUint16BE = readUInt16BE;
proto.readIntLE = readIntLE;
proto.readInt32LE = readInt32LE;
proto.readInt16LE = readInt16LE;
@@ -976,6 +983,13 @@ function addBufferPrototypeMethods(proto) {
proto.writeUIntBE = writeUIntBE;
proto.writeUInt32BE = writeUInt32BE;
proto.writeUInt16BE = writeUInt16BE;
proto.writeUintLE = writeUIntLE;
proto.writeUint32LE = writeUInt32LE;
proto.writeUint16LE = writeUInt16LE;
proto.writeUint8 = writeUInt8;
proto.writeUintBE = writeUIntBE;
proto.writeUint32BE = writeUInt32BE;
proto.writeUint16BE = writeUInt16BE;
proto.writeIntLE = writeIntLE;
proto.writeInt32LE = writeInt32LE;
proto.writeInt16LE = writeInt16LE;
+9
View File
@@ -220,3 +220,12 @@ const assert = require('assert');
val *= 0x100;
}
}
for (const fn of [
'UInt8', 'UInt16LE', 'UInt16BE', 'UInt32LE', 'UInt32BE', 'UIntLE', 'UIntBE'
]) {
const p = Buffer.prototype;
const lowerFn = fn.replace(/UInt/, 'Uint');
assert.strictEqual(p[`write${fn}`], p[`write${lowerFn}`]);
assert.strictEqual(p[`read${fn}`], p[`read${lowerFn}`]);
}