diff --git a/lib/_http_agent.js b/lib/_http_agent.js index fb20b4780ba332..e8d31d83c26c51 100644 --- a/lib/_http_agent.js +++ b/lib/_http_agent.js @@ -341,7 +341,7 @@ function calculateServerName(options, req) { // abc:123 => abc // [::1] => ::1 // [::1]:123 => ::1 - if (hostHeader.startsWith('[')) { + if (hostHeader[0] === '[') { const index = hostHeader.indexOf(']'); if (index === -1) { // Leading '[', but no ']'. Need to do something... diff --git a/lib/internal/main/watch_mode.js b/lib/internal/main/watch_mode.js index 2fb689bd7d5abe..6e2528e64737c7 100644 --- a/lib/internal/main/watch_mode.js +++ b/lib/internal/main/watch_mode.js @@ -46,7 +46,7 @@ for (let i = 0; i < process.execArgv.length; i++) { if (StringPrototypeStartsWith(arg, '--watch')) { i++; const nextArg = process.execArgv[i]; - if (nextArg && StringPrototypeStartsWith(nextArg, '-')) { + if (nextArg && nextArg[0] === '-') { ArrayPrototypePush(argsWithoutWatchOptions, nextArg); } continue; diff --git a/lib/internal/modules/esm/fetch_module.js b/lib/internal/modules/esm/fetch_module.js index 07904e685becf8..097a2713f09c61 100644 --- a/lib/internal/modules/esm/fetch_module.js +++ b/lib/internal/modules/esm/fetch_module.js @@ -3,9 +3,7 @@ const { ObjectPrototypeHasOwnProperty, PromisePrototypeThen, SafeMap, - StringPrototypeEndsWith, StringPrototypeSlice, - StringPrototypeStartsWith, } = primordials; const { Buffer: { concat: BufferConcat }, @@ -248,8 +246,9 @@ allowList.addRange('127.0.0.1', '127.255.255.255'); async function isLocalAddress(hostname) { try { if ( - StringPrototypeStartsWith(hostname, '[') && - StringPrototypeEndsWith(hostname, ']') + hostname.length && + hostname[0] === '[' && + hostname[hostname.length - 1] === ']' ) { hostname = StringPrototypeSlice(hostname, 1, -1); } diff --git a/lib/internal/modules/esm/resolve.js b/lib/internal/modules/esm/resolve.js index 35925ef0817273..09c0265c8be2a2 100644 --- a/lib/internal/modules/esm/resolve.js +++ b/lib/internal/modules/esm/resolve.js @@ -373,8 +373,9 @@ function resolvePackageTargetString( } if (!StringPrototypeStartsWith(target, './')) { - if (internal && !StringPrototypeStartsWith(target, '../') && - !StringPrototypeStartsWith(target, '/')) { + if (internal && + target[0] !== '/' && + !StringPrototypeStartsWith(target, '../')) { // No need to convert target to string, since it's already presumed to be if (!URLCanParse(target)) { const exportTarget = pattern ? diff --git a/lib/internal/modules/helpers.js b/lib/internal/modules/helpers.js index 172f0fdc02a686..62c7dff1450a64 100644 --- a/lib/internal/modules/helpers.js +++ b/lib/internal/modules/helpers.js @@ -202,7 +202,7 @@ function addBuiltinLibsToObject(object, dummyModuleName) { ArrayPrototypeForEach(builtinModules, (name) => { // Neither add underscored modules, nor ones that contain slashes (e.g., // 'fs/promises') or ones that are already defined. - if (StringPrototypeStartsWith(name, '_') || + if (name[0] === '_' || StringPrototypeIncludes(name, '/') || ObjectPrototypeHasOwnProperty(object, name)) { return; diff --git a/lib/internal/process/per_thread.js b/lib/internal/process/per_thread.js index 9995dadfc648eb..54fde20e220ce4 100644 --- a/lib/internal/process/per_thread.js +++ b/lib/internal/process/per_thread.js @@ -25,7 +25,6 @@ const { StringPrototypeEndsWith, StringPrototypeReplace, StringPrototypeSlice, - StringPrototypeStartsWith, Symbol, SymbolIterator, } = primordials; @@ -296,7 +295,7 @@ function buildAllowedFlags() { } function isAccepted(to) { - if (!StringPrototypeStartsWith(to, '-') || to === '--') return true; + if (!to.length || to[0] !== '-' || to === '--') return true; const recursiveExpansion = aliases.get(to); if (recursiveExpansion) { if (recursiveExpansion[0] === to) diff --git a/lib/internal/process/pre_execution.js b/lib/internal/process/pre_execution.js index dfb672b49b4114..08945a62d4277b 100644 --- a/lib/internal/process/pre_execution.js +++ b/lib/internal/process/pre_execution.js @@ -13,7 +13,6 @@ const { ObjectDefineProperty, ObjectFreeze, String, - StringPrototypeStartsWith, globalThis, } = primordials; @@ -206,8 +205,7 @@ function patchProcessObject(expandArgv1) { let mainEntry; // If requested, update process.argv[1] to replace whatever the user provided with the resolved absolute file path of // the entry point. - if (expandArgv1 && process.argv[1] && - !StringPrototypeStartsWith(process.argv[1], '-')) { + if (expandArgv1 && process.argv[1] && process.argv[1][0] !== '-') { // Expand process.argv[1] into a full path. const path = require('path'); try { diff --git a/lib/internal/repl/utils.js b/lib/internal/repl/utils.js index 27e1011ec9daf6..126f8ae85d0977 100644 --- a/lib/internal/repl/utils.js +++ b/lib/internal/repl/utils.js @@ -10,12 +10,10 @@ const { RegExpPrototypeExec, SafeSet, SafeStringIterator, - StringPrototypeEndsWith, StringPrototypeIndexOf, StringPrototypeLastIndexOf, StringPrototypeReplaceAll, StringPrototypeSlice, - StringPrototypeStartsWith, StringPrototypeToLowerCase, StringPrototypeTrim, Symbol, @@ -298,8 +296,7 @@ function setupPreview(repl, contextSymbol, bufferSymbol, active) { function getInputPreview(input, callback) { // For similar reasons as `defaultEval`, wrap expressions starting with a // curly brace with parenthesis. - if (StringPrototypeStartsWith(input, '{') && - !StringPrototypeEndsWith(input, ';') && !wrapped) { + if (!wrapped && input[0] === '{' && input[input.length - 1] !== ';') { input = `(${input})`; wrapped = true; } diff --git a/lib/internal/url.js b/lib/internal/url.js index b62766b02987d1..0ac80b6f1307cb 100644 --- a/lib/internal/url.js +++ b/lib/internal/url.js @@ -1416,7 +1416,7 @@ function urlToHttpOptions(url) { __proto__: null, ...url, // In case the url object was extended by the user. protocol: url.protocol, - hostname: hostname && StringPrototypeStartsWith(hostname, '[') ? + hostname: hostname && hostname[0] === '[' ? StringPrototypeSlice(hostname, 1, -1) : hostname, hash: url.hash, diff --git a/lib/internal/util/inspect.js b/lib/internal/util/inspect.js index ade91b3c5a6711..9480bcb2619bb1 100644 --- a/lib/internal/util/inspect.js +++ b/lib/internal/util/inspect.js @@ -1190,7 +1190,7 @@ function getClassBase(value, constructor, tag) { function getFunctionBase(value, constructor, tag) { const stringified = FunctionPrototypeToString(value); - if (StringPrototypeStartsWith(stringified, 'class') && StringPrototypeEndsWith(stringified, '}')) { + if (StringPrototypeStartsWith(stringified, 'class') && stringified[stringified.length - 1] === '}') { const slice = StringPrototypeSlice(stringified, 5, -1); const bracketIndex = StringPrototypeIndexOf(slice, '{'); if (bracketIndex !== -1 && @@ -1573,7 +1573,8 @@ function handleMaxCallStackSize(ctx, err, constructorName, indentationLvl) { function addNumericSeparator(integerString) { let result = ''; let i = integerString.length; - const start = StringPrototypeStartsWith(integerString, '-') ? 1 : 0; + assert(i !== 0); + const start = integerString[0] === '-' ? 1 : 0; for (; i >= start + 4; i -= 3) { result = `_${StringPrototypeSlice(integerString, i - 3, i)}${result}`; } diff --git a/lib/repl.js b/lib/repl.js index bbdf3e916daeb6..37b34af2917643 100644 --- a/lib/repl.js +++ b/lib/repl.js @@ -130,7 +130,7 @@ const { shouldColorize } = require('internal/util/colors'); const CJSModule = require('internal/modules/cjs/loader').Module; let _builtinLibs = ArrayPrototypeFilter( CJSModule.builtinModules, - (e) => !StringPrototypeStartsWith(e, '_'), + (e) => e[0] !== '_', ); const nodeSchemeBuiltinLibs = ArrayPrototypeMap( _builtinLibs, (lib) => `node:${lib}`);