Skip to content

Commit

Permalink
module: replace "magic" numbers by constants
Browse files Browse the repository at this point in the history
- add new constants
- replace numbers by constants

PR-URL: nodejs#18869
Reviewed-By: Colin Ihrig <[email protected]>
Reviewed-By: Michaël Zasso <[email protected]>
Reviewed-By: Ruben Bridgewater <[email protected]>
Reviewed-By: Matheus Marchini <[email protected]>
  • Loading branch information
daynin authored and BridgeAR committed May 1, 2018
1 parent 8de20e0 commit d22a97e
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions lib/internal/modules/cjs/helpers.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
'use strict';

const {
CHAR_LINE_FEED,
CHAR_CARRIAGE_RETURN,
CHAR_EXCLAMATION_MARK,
CHAR_HASH,
} = require('internal/constants');

// Invoke with makeRequireFunction(module) where |module| is the Module object
// to use as the context for the require() function.
function makeRequireFunction(mod) {
Expand Down Expand Up @@ -55,8 +62,8 @@ function stripShebang(content) {
// Remove shebang
var contLen = content.length;
if (contLen >= 2) {
if (content.charCodeAt(0) === 35/*#*/ &&
content.charCodeAt(1) === 33/*!*/) {
if (content.charCodeAt(0) === CHAR_HASH &&
content.charCodeAt(1) === CHAR_EXCLAMATION_MARK) {
if (contLen === 2) {
// Exact match
content = '';
Expand All @@ -65,7 +72,7 @@ function stripShebang(content) {
var i = 2;
for (; i < contLen; ++i) {
var code = content.charCodeAt(i);
if (code === 10/*\n*/ || code === 13/*\r*/)
if (code === CHAR_LINE_FEED || code === CHAR_CARRIAGE_RETURN)
break;
}
if (i === contLen)
Expand Down

0 comments on commit d22a97e

Please sign in to comment.