From 62e96096faf5ebe159352e19dad7d39073e5bd21 Mon Sep 17 00:00:00 2001 From: James M Snell Date: Wed, 15 Feb 2017 14:29:00 -0800 Subject: [PATCH] lib: more consistent use of module.exports = {} model MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Switch to using the more efficient module.exports = {} where possible. PR-URL: https://github.com/nodejs/node/pull/11406 Reviewed-By: Anna Henningsen Reviewed-By: Michaƫl Zasso --- lib/internal/buffer.js | 6 +++++- lib/internal/child_process.js | 14 +++++++------- lib/internal/fs.js | 11 ++++++----- lib/internal/net.js | 7 +++++-- 4 files changed, 23 insertions(+), 15 deletions(-) diff --git a/lib/internal/buffer.js b/lib/internal/buffer.js index 744bf2dcab6ec4..92e7ba99319b8c 100644 --- a/lib/internal/buffer.js +++ b/lib/internal/buffer.js @@ -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); @@ -28,4 +28,8 @@ exports.transcode = function transcode(source, fromEncoding, toEncoding) { err.code = code; err.errno = result; throw err; +} + +module.exports = { + transcode }; diff --git a/lib/internal/child_process.js b/lib/internal/child_process.js index 780ccabec4690f..104ac4f6363ff9 100644 --- a/lib/internal/child_process.js +++ b/lib/internal/child_process.js @@ -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 = { @@ -900,3 +893,10 @@ function maybeClose(subprocess) { subprocess.emit('close', subprocess.exitCode, subprocess.signalCode); } } + +module.exports = { + ChildProcess, + setupChannel, + _validateStdio, + getSocketList +}; diff --git a/lib/internal/fs.js b/lib/internal/fs.js index 881679f99c4000..97a4c16aed19b5 100644 --- a/lib/internal/fs.js +++ b/lib/internal/fs.js @@ -20,7 +20,6 @@ function assertEncoding(encoding) { throw new Error(`Unknown encoding: ${encoding}`); } } -exports.assertEncoding = assertEncoding; function stringToFlags(flag) { if (typeof flag === 'number') { @@ -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) { @@ -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') +}; diff --git a/lib/internal/net.js b/lib/internal/net.js index d19bc4c219a796..8f279cad1608f5 100644 --- a/lib/internal/net.js +++ b/lib/internal/net.js @@ -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) { @@ -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 +};