Skip to content

Commit

Permalink
lib: more consistent use of module.exports = {} model
Browse files Browse the repository at this point in the history
Switch to using the more efficient module.exports = {}
where possible.

PR-URL: #11406
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Michaël Zasso <targos@protonmail.com>
  • Loading branch information
jasnell committed Feb 22, 2017
1 parent 88c3f57 commit 62e9609
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 15 deletions.
6 changes: 5 additions & 1 deletion lib/internal/buffer.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ const { isUint8Array } = process.binding('util');

// Transcodes the Buffer from one encoding to another, returning a new
// Buffer instance.
exports.transcode = function transcode(source, fromEncoding, toEncoding) {
function transcode(source, fromEncoding, toEncoding) {
if (!isUint8Array(source))
throw new TypeError('"source" argument must be a Buffer or Uint8Array');
if (source.length === 0) return Buffer.alloc(0);
Expand All @@ -28,4 +28,8 @@ exports.transcode = function transcode(source, fromEncoding, toEncoding) {
err.code = code;
err.errno = result;
throw err;
}

module.exports = {
transcode
};
14 changes: 7 additions & 7 deletions lib/internal/child_process.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,6 @@ const errnoException = util._errnoException;
const SocketListSend = SocketList.SocketListSend;
const SocketListReceive = SocketList.SocketListReceive;

module.exports = {
ChildProcess,
setupChannel,
_validateStdio,
getSocketList
};

// this object contain function to convert TCP objects to native handle objects
// and back again.
const handleConversion = {
Expand Down Expand Up @@ -900,3 +893,10 @@ function maybeClose(subprocess) {
subprocess.emit('close', subprocess.exitCode, subprocess.signalCode);
}
}

module.exports = {
ChildProcess,
setupChannel,
_validateStdio,
getSocketList
};
11 changes: 6 additions & 5 deletions lib/internal/fs.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ function assertEncoding(encoding) {
throw new Error(`Unknown encoding: ${encoding}`);
}
}
exports.assertEncoding = assertEncoding;

function stringToFlags(flag) {
if (typeof flag === 'number') {
Expand Down Expand Up @@ -54,7 +53,6 @@ function stringToFlags(flag) {

throw new Error('Unknown file open flag: ' + flag);
}
exports.stringToFlags = stringToFlags;

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

exports.SyncWriteStream = SyncWriteStream;

exports.realpathCacheKey = Symbol('realpathCacheKey');
module.exports = {
assertEncoding,
stringToFlags,
SyncWriteStream,
realpathCacheKey: Symbol('realpathCacheKey')
};
7 changes: 5 additions & 2 deletions lib/internal/net.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
'use strict';

module.exports = { isLegalPort, assertPort };

// Check that the port number is not NaN when coerced to a number,
// is an integer and that it falls within the legal range of port numbers.
function isLegalPort(port) {
Expand All @@ -16,3 +14,8 @@ function assertPort(port) {
if (typeof port !== 'undefined' && !isLegalPort(port))
throw new RangeError('"port" argument must be >= 0 and < 65536');
}

module.exports = {
isLegalPort,
assertPort
};

0 comments on commit 62e9609

Please sign in to comment.