[examples][cli][routing-utils][static-build] replace deprecated String.prototype.substr() (#7588)

.substr() is deprecated so we replace it with .slice() or substring() which aren't deprecated
Signed-off-by: Tobias Speicher <rootcommander@gmail.com>

Co-authored-by: Steven <steven@ceriously.com>
This commit is contained in:
CommanderRoot
2022-03-24 22:03:40 +01:00
committed by GitHub
parent 06e7753df0
commit d2ba06c6cb
13 changed files with 42 additions and 42 deletions

View File

@@ -56,7 +56,7 @@ async function main() {
// if it's an empty string, just ignore it
if (!formatted) return false;
let type = url.substr(-3) == 'css' ? 'style' : 'script';
let type = url.slice(-3) == 'css' ? 'style' : 'script';
results += `</${formatted}>;rel=preload;as=${type},`;
});

View File

@@ -11,7 +11,7 @@ export class AppProfile {
normalize(name: string): string {
if (name) {
return name.substr(0, 1).toUpperCase() + name.substr(1).toLowerCase();
return name.slice(0, 1).toUpperCase() + name.slice(1).toLowerCase();
}
return '';
}

View File

@@ -892,8 +892,8 @@ const parseEnv = (env?: string[] | Dictionary<string>) => {
if (equalsSign === -1) {
key = e;
} else {
key = e.substr(0, equalsSign);
value = e.substr(equalsSign + 1);
key = e.slice(0, equalsSign);
value = e.slice(equalsSign + 1);
}
o[key] = value;

View File

@@ -42,7 +42,7 @@ const emailAutoComplete = (value: string, teamSlug: string) => {
domains.unshift(teamSlug);
for (const domain of domains) {
if (domain.startsWith(host)) {
suggestion = domain.substr(host.length);
suggestion = domain.slice(host.length);
break;
}
}

View File

@@ -86,7 +86,7 @@ export async function staticFiles(
// but we don't ignore if the user is explicitly listing files
// under the now namespace, or using files in combination with gitignore
const accepts = (file: string) => {
const relativePath = file.substr(prefixLength);
const relativePath = file.slice(prefixLength);
if (relativePath === '') {
return true;

View File

@@ -5,6 +5,6 @@ export default function humanizePath(path: string) {
const resolved = resolve(path);
const _homedir = homedir();
return resolved.indexOf(_homedir) === 0
? `~${resolved.substr(_homedir.length)}`
? `~${resolved.slice(_homedir.length)}`
: resolved;
}

View File

@@ -180,22 +180,22 @@ export default function text({
}
char = placeholder[value.length + caretOffset];
value =
value.substr(0, value.length + caretOffset - 2) +
value.substring(0, value.length + caretOffset - 2) +
char +
value.substr(value.length + caretOffset - 1);
value.slice(value.length + caretOffset - 1);
caretOffset--;
} else {
char = placeholder[value.length + caretOffset - 1];
value =
value.substr(0, value.length + caretOffset - 1) +
value.substring(0, value.length + caretOffset - 1) +
char +
value.substr(value.length + caretOffset);
value.slice(value.length + caretOffset);
}
caretOffset--;
} else {
value =
value.substr(0, value.length + caretOffset - 1) +
value.substr(value.length + caretOffset);
value.substring(0, value.length + caretOffset - 1) +
value.slice(value.length + caretOffset);
}
suggestion = '';
} else if (resolveChars.has(data)) {
@@ -222,9 +222,9 @@ export default function text({
return;
} else if (!ansiRegex().test(data)) {
let tmp =
value.substr(0, value.length + caretOffset) +
value.substring(0, value.length + caretOffset) +
data +
value.substr(value.length + caretOffset);
value.slice(value.length + caretOffset);
if (mask) {
if (/\d/.test(data) && caretOffset !== 0) {
@@ -236,9 +236,9 @@ export default function text({
if (value[value.length + caretOffset + 1] === ' ') {
tmp =
value.substr(0, value.length + caretOffset) +
value.substring(0, value.length + caretOffset) +
formattedData +
value.substr(value.length + caretOffset + formattedData.length);
value.slice(value.length + caretOffset + formattedData.length);
caretOffset += formattedData.length + 1;
@@ -247,9 +247,9 @@ export default function text({
}
} else {
tmp =
value.substr(0, value.length + caretOffset) +
value.substring(0, value.length + caretOffset) +
formattedData +
value.substr(value.length + caretOffset + formattedData.length);
value.slice(value.length + caretOffset + formattedData.length);
caretOffset += formattedData.length;
}

View File

@@ -4122,7 +4122,7 @@ class ZipOpenFS extends BasePortableFakeFS {
let filePath = ``;
while (true) {
const parts = FILE_PARTS_REGEX.exec(p.substr(filePath.length));
const parts = FILE_PARTS_REGEX.exec(p.slice(filePath.length));
if (!parts) return null;
filePath = this.pathUtils.join(filePath, parts[0]);
@@ -4143,7 +4143,7 @@ class ZipOpenFS extends BasePortableFakeFS {
return {
archivePath: filePath,
subPath: this.pathUtils.join(PortablePath.root, p.substr(filePath.length))
subPath: this.pathUtils.join(PortablePath.root, p.slice(filePath.length))
};
}
}
@@ -5540,7 +5540,7 @@ function makeApi(runtimeState, opts) {
while (from < packageLocationLengths.length && packageLocationLengths[from] > relativeLocation.length) from += 1;
for (let t = from; t < packageLocationLengths.length; ++t) {
const locator = packageLocatorsByLocations.get(relativeLocation.substr(0, packageLocationLengths[t]));
const locator = packageLocatorsByLocations.get(relativeLocation.slice(0, packageLocationLengths[t]));
if (typeof locator === `undefined`) continue; // Ensures that the returned locator isn't a blacklisted one.
//
// Blacklisted packages are packages that cannot be used because their dependencies cannot be deduced. This only
@@ -6806,7 +6806,7 @@ var PATH = {
},
normalize: function(path) {
var isAbsolute = path.charAt(0) === "/",
trailingSlash = path.substr(-1) === "/";
trailingSlash = path.slice(-1) === "/";
path = PATH.normalizeArray(
path.split("/").filter(function(p) {
return !!p;
@@ -6829,7 +6829,7 @@ var PATH = {
return ".";
}
if (dir) {
dir = dir.substr(0, dir.length - 1);
dir = dir.slice(0, -1);
}
return root + dir;
},
@@ -6839,7 +6839,7 @@ var PATH = {
path = path.replace(/\/$/, "");
var lastSlash = path.lastIndexOf("/");
if (lastSlash === -1) return path;
return path.substr(lastSlash + 1);
return path.slice(lastSlash + 1);
},
extname: function(path) {
return PATH.splitPath(path)[3];
@@ -6879,8 +6879,8 @@ var PATH_FS = {
return (resolvedAbsolute ? "/" : "") + resolvedPath || ".";
},
relative: function(from, to) {
from = PATH_FS.resolve(from).substr(1);
to = PATH_FS.resolve(to).substr(1);
from = PATH_FS.resolve(from).slice(1);
to = PATH_FS.resolve(to).slice(1);
function trim(arr) {
var start = 0;
for (; start < arr.length; start++) {
@@ -9280,7 +9280,7 @@ var FS = {
},
joinPath: function(parts, forceRelative) {
var path = PATH.join.apply(null, parts);
if (forceRelative && path[0] == "/") path = path.substr(1);
if (forceRelative && path[0] == "/") path = path.slice(1);
return path;
},
absolutePath: function(relative, base) {
@@ -9871,7 +9871,7 @@ var SYSCALLS = {
},
doMkdir: function(path, mode) {
path = PATH.normalize(path);
if (path[path.length - 1] === "/") path = path.substr(0, path.length - 1);
if (path[path.length - 1] === "/") path = path.slice(0, -1);
FS.mkdir(path, mode, 0);
return 0;
},
@@ -10620,7 +10620,7 @@ module.exports = require("path");;
/************************************************************************/
/******/ // The module cache
/******/ var __webpack_module_cache__ = {};
/******/
/******/
/******/ // The require function
/******/ function __webpack_require__(moduleId) {
/******/ // Check if module is in cache
@@ -10633,14 +10633,14 @@ module.exports = require("path");;
/******/ // no module.loaded needed
/******/ exports: {}
/******/ };
/******/
/******/
/******/ // Execute the module function
/******/ __webpack_modules__[moduleId](module, module.exports, __webpack_require__);
/******/
/******/
/******/ // Return the exports of the module
/******/ return module.exports;
/******/ }
/******/
/******/
/************************************************************************/
/******/ /* webpack/runtime/compat get default export */
/******/ (() => {
@@ -10653,7 +10653,7 @@ module.exports = require("path");;
/******/ return getter;
/******/ };
/******/ })();
/******/
/******/
/******/ /* webpack/runtime/define property getters */
/******/ (() => {
/******/ // define getter functions for harmony exports
@@ -10665,12 +10665,12 @@ module.exports = require("path");;
/******/ }
/******/ };
/******/ })();
/******/
/******/
/******/ /* webpack/runtime/hasOwnProperty shorthand */
/******/ (() => {
/******/ __webpack_require__.o = (obj, prop) => Object.prototype.hasOwnProperty.call(obj, prop)
/******/ })();
/******/
/******/
/************************************************************************/
/******/ // module exports must be returned from runtime so entry inlining is disabled
/******/ // startup
@@ -10678,4 +10678,4 @@ module.exports = require("path");;
/******/ return __webpack_require__(936);
/******/ })()
.default;
});
});

View File

@@ -381,7 +381,7 @@ function safelyCompile(
// the value needs to start with a forward-slash to be compiled
// correctly
return compile(`/${value}`, { validate: false })(indexes).substr(1);
return compile(`/${value}`, { validate: false })(indexes).slice(1);
}
function toSegmentDest(index: number): string {

View File

@@ -14,7 +14,7 @@ const envPublicUrl = process.env.PUBLIC_URL;
function ensureSlash(inputPath, needsSlash) {
const hasSlash = inputPath.endsWith('/');
if (hasSlash && !needsSlash) {
return inputPath.substr(0, inputPath.length - 1);
return inputPath.slice(0, -1);
} else if (!hasSlash && needsSlash) {
return `${inputPath}/`;
} else {

View File

@@ -11,7 +11,7 @@ export class AppProfile {
normalize(name: string): string {
if (name) {
return name.substr(0, 1).toUpperCase() + name.substr(1).toLowerCase();
return name.slice(0, 1).toUpperCase() + name.slice(1).toLowerCase();
}
return '';
}

View File

@@ -56,7 +56,7 @@ async function main() {
// if it's an empty string, just ignore it
if (!formatted) return false;
let type = url.substr(-3) == 'css' ? 'style' : 'script';
let type = url.slice(-3) == 'css' ? 'style' : 'script';
results += `</${formatted}>;rel=preload;as=${type},`;
});
await browser.close();

View File

@@ -199,7 +199,7 @@ async function testDeployment(
probe.path =
probe.path.substring(0, nextScriptIndex) +
scriptRelativePath +
probe.path.substr(scriptNameEnd + 1);
probe.path.slice(scriptNameEnd + 1);
}
const probeUrl = `https://${deploymentUrl}${probe.path}`;