Skip to content

Commit 5864fca

Browse files
addaleaxTrott
authored andcommitted
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: #34729 Reviewed-By: James M Snell <[email protected]> Reviewed-By: Ruben Bridgewater <[email protected]> Reviewed-By: Rich Trott <[email protected]>
1 parent 7b8c6b0 commit 5864fca

File tree

3 files changed

+65
-0
lines changed

3 files changed

+65
-0
lines changed

doc/api/buffer.md

+42
Original file line numberDiff line numberDiff line change
@@ -1709,6 +1709,9 @@ console.log(buf.readIntLE(0, 6).toString(16));
17091709
<!-- YAML
17101710
added: v0.5.0
17111711
changes:
1712+
- version: REPLACEME
1713+
pr-url: https://github.com/nodejs/node/pull/34729
1714+
description: This function is also available as `buf.readUint8()`.
17121715
- version: v10.0.0
17131716
pr-url: https://github.com/nodejs/node/pull/18395
17141717
description: Removed `noAssert` and no implicit coercion of the offset
@@ -1736,6 +1739,9 @@ console.log(buf.readUInt8(2));
17361739
<!-- YAML
17371740
added: v0.5.5
17381741
changes:
1742+
- version: REPLACEME
1743+
pr-url: https://github.com/nodejs/node/pull/34729
1744+
description: This function is also available as `buf.readUint16BE()`.
17391745
- version: v10.0.0
17401746
pr-url: https://github.com/nodejs/node/pull/18395
17411747
description: Removed `noAssert` and no implicit coercion of the offset
@@ -1762,6 +1768,9 @@ console.log(buf.readUInt16BE(1).toString(16));
17621768
<!-- YAML
17631769
added: v0.5.5
17641770
changes:
1771+
- version: REPLACEME
1772+
pr-url: https://github.com/nodejs/node/pull/34729
1773+
description: This function is also available as `buf.readUint16LE()`.
17651774
- version: v10.0.0
17661775
pr-url: https://github.com/nodejs/node/pull/18395
17671776
description: Removed `noAssert` and no implicit coercion of the offset
@@ -1790,6 +1799,9 @@ console.log(buf.readUInt16LE(2).toString(16));
17901799
<!-- YAML
17911800
added: v0.5.5
17921801
changes:
1802+
- version: REPLACEME
1803+
pr-url: https://github.com/nodejs/node/pull/34729
1804+
description: This function is also available as `buf.readUint32BE()`.
17931805
- version: v10.0.0
17941806
pr-url: https://github.com/nodejs/node/pull/18395
17951807
description: Removed `noAssert` and no implicit coercion of the offset
@@ -1814,6 +1826,9 @@ console.log(buf.readUInt32BE(0).toString(16));
18141826
<!-- YAML
18151827
added: v0.5.5
18161828
changes:
1829+
- version: REPLACEME
1830+
pr-url: https://github.com/nodejs/node/pull/34729
1831+
description: This function is also available as `buf.readUint32LE()`.
18171832
- version: v10.0.0
18181833
pr-url: https://github.com/nodejs/node/pull/18395
18191834
description: Removed `noAssert` and no implicit coercion of the offset
@@ -1840,6 +1855,9 @@ console.log(buf.readUInt32LE(1).toString(16));
18401855
<!-- YAML
18411856
added: v0.11.15
18421857
changes:
1858+
- version: REPLACEME
1859+
pr-url: https://github.com/nodejs/node/pull/34729
1860+
description: This function is also available as `buf.readUintBE()`.
18431861
- version: v10.0.0
18441862
pr-url: https://github.com/nodejs/node/pull/18395
18451863
description: Removed `noAssert` and no implicit coercion of the offset
@@ -1869,6 +1887,9 @@ console.log(buf.readUIntBE(1, 6).toString(16));
18691887
<!-- YAML
18701888
added: v0.11.15
18711889
changes:
1890+
- version: REPLACEME
1891+
pr-url: https://github.com/nodejs/node/pull/34729
1892+
description: This function is also available as `buf.readUintLE()`.
18721893
- version: v10.0.0
18731894
pr-url: https://github.com/nodejs/node/pull/18395
18741895
description: Removed `noAssert` and no implicit coercion of the offset
@@ -2651,6 +2672,9 @@ console.log(buf);
26512672
<!-- YAML
26522673
added: v0.5.0
26532674
changes:
2675+
- version: REPLACEME
2676+
pr-url: https://github.com/nodejs/node/pull/34729
2677+
description: This function is also available as `buf.writeUint8()`.
26542678
- version: v10.0.0
26552679
pr-url: https://github.com/nodejs/node/pull/18395
26562680
description: Removed `noAssert` and no implicit coercion of the offset
@@ -2682,6 +2706,9 @@ console.log(buf);
26822706
<!-- YAML
26832707
added: v0.5.5
26842708
changes:
2709+
- version: REPLACEME
2710+
pr-url: https://github.com/nodejs/node/pull/34729
2711+
description: This function is also available as `buf.writeUint16BE()`.
26852712
- version: v10.0.0
26862713
pr-url: https://github.com/nodejs/node/pull/18395
26872714
description: Removed `noAssert` and no implicit coercion of the offset
@@ -2711,6 +2738,9 @@ console.log(buf);
27112738
<!-- YAML
27122739
added: v0.5.5
27132740
changes:
2741+
- version: REPLACEME
2742+
pr-url: https://github.com/nodejs/node/pull/34729
2743+
description: This function is also available as `buf.writeUint16LE()`.
27142744
- version: v10.0.0
27152745
pr-url: https://github.com/nodejs/node/pull/18395
27162746
description: Removed `noAssert` and no implicit coercion of the offset
@@ -2740,6 +2770,9 @@ console.log(buf);
27402770
<!-- YAML
27412771
added: v0.5.5
27422772
changes:
2773+
- version: REPLACEME
2774+
pr-url: https://github.com/nodejs/node/pull/34729
2775+
description: This function is also available as `buf.writeUint32BE()`.
27432776
- version: v10.0.0
27442777
pr-url: https://github.com/nodejs/node/pull/18395
27452778
description: Removed `noAssert` and no implicit coercion of the offset
@@ -2768,6 +2801,9 @@ console.log(buf);
27682801
<!-- YAML
27692802
added: v0.5.5
27702803
changes:
2804+
- version: REPLACEME
2805+
pr-url: https://github.com/nodejs/node/pull/34729
2806+
description: This function is also available as `buf.writeUint32LE()`.
27712807
- version: v10.0.0
27722808
pr-url: https://github.com/nodejs/node/pull/18395
27732809
description: Removed `noAssert` and no implicit coercion of the offset
@@ -2796,6 +2832,9 @@ console.log(buf);
27962832
<!-- YAML
27972833
added: v0.5.5
27982834
changes:
2835+
- version: REPLACEME
2836+
pr-url: https://github.com/nodejs/node/pull/34729
2837+
description: This function is also available as `buf.writeUintBE()`.
27992838
- version: v10.0.0
28002839
pr-url: https://github.com/nodejs/node/pull/18395
28012840
description: Removed `noAssert` and no implicit coercion of the offset
@@ -2826,6 +2865,9 @@ console.log(buf);
28262865
<!-- YAML
28272866
added: v0.5.5
28282867
changes:
2868+
- version: REPLACEME
2869+
pr-url: https://github.com/nodejs/node/pull/34729
2870+
description: This function is also available as `buf.writeUintLE()`.
28292871
- version: v10.0.0
28302872
pr-url: https://github.com/nodejs/node/pull/18395
28312873
description: Removed `noAssert` and no implicit coercion of the offset

lib/internal/buffer.js

+14
Original file line numberDiff line numberDiff line change
@@ -966,6 +966,13 @@ function addBufferPrototypeMethods(proto) {
966966
proto.readUIntBE = readUIntBE;
967967
proto.readUInt32BE = readUInt32BE;
968968
proto.readUInt16BE = readUInt16BE;
969+
proto.readUintLE = readUIntLE;
970+
proto.readUint32LE = readUInt32LE;
971+
proto.readUint16LE = readUInt16LE;
972+
proto.readUint8 = readUInt8;
973+
proto.readUintBE = readUIntBE;
974+
proto.readUint32BE = readUInt32BE;
975+
proto.readUint16BE = readUInt16BE;
969976
proto.readIntLE = readIntLE;
970977
proto.readInt32LE = readInt32LE;
971978
proto.readInt16LE = readInt16LE;
@@ -981,6 +988,13 @@ function addBufferPrototypeMethods(proto) {
981988
proto.writeUIntBE = writeUIntBE;
982989
proto.writeUInt32BE = writeUInt32BE;
983990
proto.writeUInt16BE = writeUInt16BE;
991+
proto.writeUintLE = writeUIntLE;
992+
proto.writeUint32LE = writeUInt32LE;
993+
proto.writeUint16LE = writeUInt16LE;
994+
proto.writeUint8 = writeUInt8;
995+
proto.writeUintBE = writeUIntBE;
996+
proto.writeUint32BE = writeUInt32BE;
997+
proto.writeUint16BE = writeUInt16BE;
984998
proto.writeIntLE = writeIntLE;
985999
proto.writeInt32LE = writeInt32LE;
9861000
proto.writeInt16LE = writeInt16LE;

test/parallel/test-buffer-writeuint.js

+9
Original file line numberDiff line numberDiff line change
@@ -220,3 +220,12 @@ const assert = require('assert');
220220
val *= 0x100;
221221
}
222222
}
223+
224+
for (const fn of [
225+
'UInt8', 'UInt16LE', 'UInt16BE', 'UInt32LE', 'UInt32BE', 'UIntLE', 'UIntBE'
226+
]) {
227+
const p = Buffer.prototype;
228+
const lowerFn = fn.replace(/UInt/, 'Uint');
229+
assert.strictEqual(p[`write${fn}`], p[`write${lowerFn}`]);
230+
assert.strictEqual(p[`read${fn}`], p[`read${lowerFn}`]);
231+
}

0 commit comments

Comments
 (0)