Skip to content

Commit 62e9609

Browse files
committed
lib: more consistent use of module.exports = {} model
Switch to using the more efficient module.exports = {} where possible. PR-URL: #11406 Reviewed-By: Anna Henningsen <[email protected]> Reviewed-By: Michaël Zasso <[email protected]>
1 parent 88c3f57 commit 62e9609

File tree

4 files changed

+23
-15
lines changed

4 files changed

+23
-15
lines changed

lib/internal/buffer.js

+5-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ const { isUint8Array } = process.binding('util');
1212

1313
// Transcodes the Buffer from one encoding to another, returning a new
1414
// Buffer instance.
15-
exports.transcode = function transcode(source, fromEncoding, toEncoding) {
15+
function transcode(source, fromEncoding, toEncoding) {
1616
if (!isUint8Array(source))
1717
throw new TypeError('"source" argument must be a Buffer or Uint8Array');
1818
if (source.length === 0) return Buffer.alloc(0);
@@ -28,4 +28,8 @@ exports.transcode = function transcode(source, fromEncoding, toEncoding) {
2828
err.code = code;
2929
err.errno = result;
3030
throw err;
31+
}
32+
33+
module.exports = {
34+
transcode
3135
};

lib/internal/child_process.js

+7-7
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,6 @@ const errnoException = util._errnoException;
2222
const SocketListSend = SocketList.SocketListSend;
2323
const SocketListReceive = SocketList.SocketListReceive;
2424

25-
module.exports = {
26-
ChildProcess,
27-
setupChannel,
28-
_validateStdio,
29-
getSocketList
30-
};
31-
3225
// this object contain function to convert TCP objects to native handle objects
3326
// and back again.
3427
const handleConversion = {
@@ -900,3 +893,10 @@ function maybeClose(subprocess) {
900893
subprocess.emit('close', subprocess.exitCode, subprocess.signalCode);
901894
}
902895
}
896+
897+
module.exports = {
898+
ChildProcess,
899+
setupChannel,
900+
_validateStdio,
901+
getSocketList
902+
};

lib/internal/fs.js

+6-5
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ function assertEncoding(encoding) {
2020
throw new Error(`Unknown encoding: ${encoding}`);
2121
}
2222
}
23-
exports.assertEncoding = assertEncoding;
2423

2524
function stringToFlags(flag) {
2625
if (typeof flag === 'number') {
@@ -54,7 +53,6 @@ function stringToFlags(flag) {
5453

5554
throw new Error('Unknown file open flag: ' + flag);
5655
}
57-
exports.stringToFlags = stringToFlags;
5856

5957
// Temporary hack for process.stdout and process.stderr when piped to files.
6058
function SyncWriteStream(fd, options) {
@@ -95,6 +93,9 @@ SyncWriteStream.prototype.destroy = function() {
9593
return true;
9694
};
9795

98-
exports.SyncWriteStream = SyncWriteStream;
99-
100-
exports.realpathCacheKey = Symbol('realpathCacheKey');
96+
module.exports = {
97+
assertEncoding,
98+
stringToFlags,
99+
SyncWriteStream,
100+
realpathCacheKey: Symbol('realpathCacheKey')
101+
};

lib/internal/net.js

+5-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
'use strict';
22

3-
module.exports = { isLegalPort, assertPort };
4-
53
// Check that the port number is not NaN when coerced to a number,
64
// is an integer and that it falls within the legal range of port numbers.
75
function isLegalPort(port) {
@@ -16,3 +14,8 @@ function assertPort(port) {
1614
if (typeof port !== 'undefined' && !isLegalPort(port))
1715
throw new RangeError('"port" argument must be >= 0 and < 65536');
1816
}
17+
18+
module.exports = {
19+
isLegalPort,
20+
assertPort
21+
};

0 commit comments

Comments
 (0)