GeezerVison is showing github.com — lib: refactor code with startsWith/endsWith · nodejs/node@e644eb3
File treeExpand file treeCollapse file tree Open diff view settings Expand file treeCollapse file tree Open diff view settings Collapse file Copy file name to clipboardExpand all lines: lib/_debug_agent.js +2-2Lines changed: 2 additions & 2 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -119,10 +119,10 @@ Client.prototype._transform = function _transform(data, enc, cb) { | 119 | 119 | while (true) { | 120 | 120 | if (this.state === 'headers') { | 121 | 121 | // Not enough data | 122 | | - if (!/\r\n/.test(this.buffer)) | | 122 | + if (!this.buffer.includes('\r\n')) | 123 | 123 | break; | 124 | 124 |
| 125 | | - if (/^\r\n/.test(this.buffer)) { | | 125 | + if (this.buffer.startsWith('\r\n')) { | 126 | 126 | this.buffer = this.buffer.slice(2); | 127 | 127 | this.state = 'body'; | 128 | 128 | continue; | |
Collapse file Copy file name to clipboardExpand all lines: lib/_debugger.js +1-1Lines changed: 1 addition & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
@@ -1349,7 +1349,7 @@ Interface.prototype.setBreakpoint = function(script, line, | 1349 | 1349 | } | 1350 | 1350 |
| 1351 | 1351 | let req; | 1352 | | - if (/\(\)$/.test(script)) { | | 1352 | + if (script.endsWith('()')) { | 1353 | 1353 | // setBreakpoint('functionname()'); | 1354 | 1354 | req = { | 1355 | 1355 | type: 'function', | |
Collapse file Copy file name to clipboardExpand all lines: lib/cluster.js +2-3Lines changed: 2 additions & 3 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -237,9 +237,8 @@ function masterInit() { | 237 | 237 | // Without --logfile=v8-%p.log, everything ends up in a single, unusable | 238 | 238 | // file. (Unusable because what V8 logs are memory addresses and each | 239 | 239 | // process has its own memory mappings.) | 240 | | - if (settings.execArgv.some(function(s) { return /^--prof/.test(s); }) && | 241 | | - !settings.execArgv.some(function(s) { return /^--logfile=/.test(s); })) | 242 | | - { | | 240 | + if (settings.execArgv.some((s) => s.startsWith('--prof')) && | | 241 | + !settings.execArgv.some((s) => s.startsWith('--logfile='))) { | 243 | 242 | settings.execArgv = settings.execArgv.concat(['--logfile=v8-%p.log']); | 244 | 243 | } | 245 | 244 | cluster.settings = settings; | |
Collapse file Copy file name to clipboardExpand all lines: lib/os.js +5-5Lines changed: 5 additions & 5 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -24,23 +24,23 @@ exports.platform = function() { | 24 | 24 | return process.platform; | 25 | 25 | }; | 26 | 26 |
| 27 | | -const trailingSlashRe = isWindows ? /[^:]\\$/ | 28 | | - : /.\/$/; | 29 | | - | 30 | 27 | exports.tmpdir = function() { | 31 | 28 | var path; | 32 | 29 | if (isWindows) { | 33 | 30 | path = process.env.TEMP || | 34 | 31 | process.env.TMP || | 35 | 32 | (process.env.SystemRoot || process.env.windir) + '\\temp'; | | 33 | + if (path.length > 1 && path.endsWith('\\') && !path.endsWith(':\\')) | | 34 | + path = path.slice(0, -1); | 36 | 35 | } else { | 37 | 36 | path = process.env.TMPDIR || | 38 | 37 | process.env.TMP || | 39 | 38 | process.env.TEMP || | 40 | 39 | '/tmp'; | | 40 | + if (path.length > 1 && path.endsWith('/')) | | 41 | + path = path.slice(0, -1); | 41 | 42 | } | 42 | | - if (trailingSlashRe.test(path)) | 43 | | - path = path.slice(0, -1); | | 43 | + | 44 | 44 | return path; | 45 | 45 | }; | 46 | 46 |
| |
Collapse file Copy file name to clipboardExpand all lines: lib/readline.js +1-1Lines changed: 1 addition & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
@@ -330,7 +330,7 @@ Interface.prototype._normalWrite = function(b) { | 330 | 330 | this._line_buffer = null; | 331 | 331 | } | 332 | 332 | if (newPartContainsEnding) { | 333 | | - this._sawReturn = /\r$/.test(string); | | 333 | + this._sawReturn = string.endsWith('\r'); | 334 | 334 |
| 335 | 335 | // got one or more newlines; process into "line" events | 336 | 336 | var lines = string.split(lineEnding); | |
Collapse file Copy file name to clipboardExpand all lines: lib/repl.js +1-1Lines changed: 1 addition & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
@@ -446,7 +446,7 @@ function REPLServer(prompt, | 446 | 446 | self.memory(cmd); | 447 | 447 |
| 448 | 448 | self.wrappedCmd = false; | 449 | | - if (e && !self.bufferedCommand && cmd.trim().match(/^npm /)) { | | 449 | + if (e && !self.bufferedCommand && cmd.trim().startsWith('npm ')) { | 450 | 450 | self.outputStream.write('npm should be run outside of the ' + | 451 | 451 | 'node repl, in your normal shell.\n' + | 452 | 452 | '(Press Control-D to exit.)\n'); | |
Collapse file Copy file name to clipboardExpand all lines: lib/tls.js +2-2Lines changed: 2 additions & 2 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -75,7 +75,7 @@ exports.checkServerIdentity = function checkServerIdentity(host, cert) { | 75 | 75 | // Create regexp to much hostnames | 76 | 76 | function regexpify(host, wildcards) { | 77 | 77 | // Add trailing dot (make hostnames uniform) | 78 | | - if (!/\.$/.test(host)) host += '.'; | | 78 | + if (!host || !host.endsWith('.')) host += '.'; | 79 | 79 |
| 80 | 80 | // The same applies to hostname with more than one wildcard, | 81 | 81 | // if hostname has wildcard when wildcards are not allowed, | @@ -144,7 +144,7 @@ exports.checkServerIdentity = function checkServerIdentity(host, cert) { | 144 | 144 | } | 145 | 145 | } else if (cert.subject) { | 146 | 146 | // Transform hostname to canonical form | 147 | | - if (!/\.$/.test(host)) host += '.'; | | 147 | + if (!host || !host.endsWith('.')) host += '.'; | 148 | 148 |
| 149 | 149 | // Otherwise check all DNS/URI records from certificate | 150 | 150 | // (with allowed wildcards) | |
|