Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit e644eb3

Browse filesBrowse files
JacksonTianevanlucas
authored andcommitted
lib: refactor code with startsWith/endsWith
reduce using RegExp for string test. This pull reuqest replaces various usages of regular expressions in favor of the ES2015 startsWith and endsWith methods. PR-URL: #5753 Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com> Reviewed-By: Brian White <mscdex@mscdex.net>
1 parent e1a012f commit e644eb3
Copy full SHA for e644eb3

File tree

Expand file treeCollapse file tree

7 files changed

+14
-15
lines changed
Open diff view settings
Filter options
Expand file treeCollapse file tree

7 files changed

+14
-15
lines changed
Open diff view settings
Collapse file

‎lib/_debug_agent.js‎

Copy file name to clipboardExpand all lines: lib/_debug_agent.js
+2-2Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -119,10 +119,10 @@ Client.prototype._transform = function _transform(data, enc, cb) {
119119
while (true) {
120120
if (this.state === 'headers') {
121121
// Not enough data
122-
if (!/\r\n/.test(this.buffer))
122+
if (!this.buffer.includes('\r\n'))
123123
break;
124124

125-
if (/^\r\n/.test(this.buffer)) {
125+
if (this.buffer.startsWith('\r\n')) {
126126
this.buffer = this.buffer.slice(2);
127127
this.state = 'body';
128128
continue;
Collapse file

‎lib/_debugger.js‎

Copy file name to clipboardExpand all lines: lib/_debugger.js
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1349,7 +1349,7 @@ Interface.prototype.setBreakpoint = function(script, line,
13491349
}
13501350

13511351
let req;
1352-
if (/\(\)$/.test(script)) {
1352+
if (script.endsWith('()')) {
13531353
// setBreakpoint('functionname()');
13541354
req = {
13551355
type: 'function',
Collapse file

‎lib/cluster.js‎

Copy file name to clipboardExpand all lines: lib/cluster.js
+2-3Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -237,9 +237,8 @@ function masterInit() {
237237
// Without --logfile=v8-%p.log, everything ends up in a single, unusable
238238
// file. (Unusable because what V8 logs are memory addresses and each
239239
// 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='))) {
243242
settings.execArgv = settings.execArgv.concat(['--logfile=v8-%p.log']);
244243
}
245244
cluster.settings = settings;
Collapse file

‎lib/os.js‎

Copy file name to clipboardExpand all lines: lib/os.js
+5-5Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,23 +24,23 @@ exports.platform = function() {
2424
return process.platform;
2525
};
2626

27-
const trailingSlashRe = isWindows ? /[^:]\\$/
28-
: /.\/$/;
29-
3027
exports.tmpdir = function() {
3128
var path;
3229
if (isWindows) {
3330
path = process.env.TEMP ||
3431
process.env.TMP ||
3532
(process.env.SystemRoot || process.env.windir) + '\\temp';
33+
if (path.length > 1 && path.endsWith('\\') && !path.endsWith(':\\'))
34+
path = path.slice(0, -1);
3635
} else {
3736
path = process.env.TMPDIR ||
3837
process.env.TMP ||
3938
process.env.TEMP ||
4039
'/tmp';
40+
if (path.length > 1 && path.endsWith('/'))
41+
path = path.slice(0, -1);
4142
}
42-
if (trailingSlashRe.test(path))
43-
path = path.slice(0, -1);
43+
4444
return path;
4545
};
4646

Collapse file

‎lib/readline.js‎

Copy file name to clipboardExpand all lines: lib/readline.js
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -330,7 +330,7 @@ Interface.prototype._normalWrite = function(b) {
330330
this._line_buffer = null;
331331
}
332332
if (newPartContainsEnding) {
333-
this._sawReturn = /\r$/.test(string);
333+
this._sawReturn = string.endsWith('\r');
334334

335335
// got one or more newlines; process into "line" events
336336
var lines = string.split(lineEnding);
Collapse file

‎lib/repl.js‎

Copy file name to clipboardExpand all lines: lib/repl.js
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -446,7 +446,7 @@ function REPLServer(prompt,
446446
self.memory(cmd);
447447

448448
self.wrappedCmd = false;
449-
if (e && !self.bufferedCommand && cmd.trim().match(/^npm /)) {
449+
if (e && !self.bufferedCommand && cmd.trim().startsWith('npm ')) {
450450
self.outputStream.write('npm should be run outside of the ' +
451451
'node repl, in your normal shell.\n' +
452452
'(Press Control-D to exit.)\n');
Collapse file

‎lib/tls.js‎

Copy file name to clipboardExpand all lines: lib/tls.js
+2-2Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ exports.checkServerIdentity = function checkServerIdentity(host, cert) {
7575
// Create regexp to much hostnames
7676
function regexpify(host, wildcards) {
7777
// Add trailing dot (make hostnames uniform)
78-
if (!/\.$/.test(host)) host += '.';
78+
if (!host || !host.endsWith('.')) host += '.';
7979

8080
// The same applies to hostname with more than one wildcard,
8181
// if hostname has wildcard when wildcards are not allowed,
@@ -144,7 +144,7 @@ exports.checkServerIdentity = function checkServerIdentity(host, cert) {
144144
}
145145
} else if (cert.subject) {
146146
// Transform hostname to canonical form
147-
if (!/\.$/.test(host)) host += '.';
147+
if (!host || !host.endsWith('.')) host += '.';
148148

149149
// Otherwise check all DNS/URI records from certificate
150150
// (with allowed wildcards)

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.