Skip to content

Commit 1376516

Browse files
CommanderRootdgp1130
authored andcommitted
refactor: replace deprecated String.prototype.substr()
.substr() is deprecated so we replace it with .slice() which works similarily but isn't deprecated Signed-off-by: Tobias Speicher <[email protected]>
1 parent 09a71ba commit 1376516

File tree

17 files changed

+25
-25
lines changed

17 files changed

+25
-25
lines changed

lib/bootstrap-local.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ if (!__dirname.match(new RegExp(`\\${path.sep}node_modules\\${path.sep}`))) {
109109
} else {
110110
const match = Object.keys(packages).find((pkgName) => request.startsWith(pkgName + '/'));
111111
if (match) {
112-
const p = path.join(packages[match].root, request.substr(match.length));
112+
const p = path.join(packages[match].root, request.slice(match.length));
113113
return oldResolve.call(this, p, parent);
114114
} else if (!resolved) {
115115
if (exception) {

lib/packages.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -211,7 +211,7 @@ export const packages: PackageMap = packageJsonPaths
211211
const experimental = !!packageJson.private || !!packageJson.experimental;
212212

213213
packages[name] = {
214-
build: path.join(distRoot, pkgRoot.substr(path.dirname(__dirname).length)),
214+
build: path.join(distRoot, pkgRoot.slice(path.dirname(__dirname).length)),
215215
dist: path.join(distRoot, name),
216216
root: pkgRoot,
217217
relative: path.relative(path.dirname(__dirname), pkgRoot),

packages/angular_devkit/build_angular/src/utils/process-bundle.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ export async function inlineLocales(options: InlineOptions) {
156156
// Same errors will contain the full content of the file as the error message
157157
// Which makes it hard to find the actual error message.
158158
const index = error.message.indexOf(')\n');
159-
const msg = index !== -1 ? error.message.substr(0, index + 1) : error.message;
159+
const msg = index !== -1 ? error.message.slice(0, index + 1) : error.message;
160160
throw new Error(`${msg}\nAn error occurred inlining file "${options.filename}"`);
161161
}
162162
}

packages/angular_devkit/build_angular/src/webpack/configs/dev-server.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ export function buildServePath(
111111
}
112112

113113
if (servePath.endsWith('/')) {
114-
servePath = servePath.substr(0, servePath.length - 1);
114+
servePath = servePath.slice(0, -1);
115115
}
116116

117117
if (!servePath.startsWith('/')) {

packages/angular_devkit/build_angular/src/webpack/configs/styles.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,7 @@ export function getStylesConfig(wco: WebpackConfigOptions): Configuration {
169169
: undefined,
170170
plugins: [
171171
postcssImports({
172-
resolve: (url: string) => (url.startsWith('~') ? url.substr(1) : url),
172+
resolve: (url: string) => (url.startsWith('~') ? url.slice(1) : url),
173173
load: (filename: string) => {
174174
return new Promise<string>((resolve, reject) => {
175175
loader.fs.readFile(filename, (err: Error, data: Buffer) => {

packages/angular_devkit/build_angular/src/webpack/plugins/postcss-cli-resources.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ export default function (options?: PostcssCliResourcesOptions): Plugin {
7777
// If starts with a caret, remove and return remainder
7878
// this supports bypassing asset processing
7979
if (inputUrl.startsWith('^')) {
80-
return inputUrl.substr(1);
80+
return inputUrl.slice(1);
8181
}
8282

8383
const cacheKey = path.resolve(context, inputUrl);
@@ -87,7 +87,7 @@ export default function (options?: PostcssCliResourcesOptions): Plugin {
8787
}
8888

8989
if (inputUrl.startsWith('~')) {
90-
inputUrl = inputUrl.substr(1);
90+
inputUrl = inputUrl.slice(1);
9191
}
9292

9393
const { pathname, hash, search } = url.parse(inputUrl.replace(/\\/g, '/'));

packages/angular_devkit/core/src/json/parser.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -587,7 +587,7 @@ function _readIdentifier(
587587
kind: 'identifier',
588588
start,
589589
end: context.position,
590-
text: context.original.substr(start.offset, context.position.offset),
590+
text: context.original.slice(start.offset, start.offset + context.position.offset),
591591
value,
592592
comments,
593593
};
@@ -894,8 +894,8 @@ export function parseJsonAst(input: string, mode = JsonParseMode.Default): JsonA
894894

895895
const ast = _readValue(context);
896896
if (context.position.offset < input.length) {
897-
const rest = input.substr(context.position.offset);
898-
const i = rest.length > 20 ? rest.substr(0, 20) + '...' : rest;
897+
const rest = input.slice(context.position.offset);
898+
const i = rest.length > 20 ? rest.slice(0, 20) + '...' : rest;
899899
throw new Error(
900900
`Expected end of file, got "${i}" at ` +
901901
`${context.position.line}:${context.position.character}.`,

packages/angular_devkit/core/src/utils/strings.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ export function underscore(str: string): string {
129129
@return {String} The capitalized string.
130130
*/
131131
export function capitalize(str: string): string {
132-
return str.charAt(0).toUpperCase() + str.substr(1);
132+
return str.charAt(0).toUpperCase() + str.slice(1);
133133
}
134134

135135
/**

packages/angular_devkit/core/src/virtual-fs/path.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ export function extname(path: Path): string {
7575
if (i < 1) {
7676
return '';
7777
} else {
78-
return base.substr(i);
78+
return base.slice(i);
7979
}
8080
}
8181

@@ -87,7 +87,7 @@ export function basename(path: Path): PathFragment {
8787
if (i == -1) {
8888
return fragment(path);
8989
} else {
90-
return fragment(path.substr(path.lastIndexOf(NormalizedSep) + 1));
90+
return fragment(path.slice(path.lastIndexOf(NormalizedSep) + 1));
9191
}
9292
}
9393

@@ -102,7 +102,7 @@ export function dirname(path: Path): Path {
102102

103103
const endIndex = index === 0 ? 1 : index; // case of file under root: '/file'
104104

105-
return normalize(path.substr(0, endIndex));
105+
return normalize(path.slice(0, endIndex));
106106
}
107107

108108
/**
@@ -233,7 +233,7 @@ export function noCacheNormalize(path: string): Path {
233233
// Match absolute windows path.
234234
const original = path;
235235
if (path.match(/^[A-Z]:[/\\]/i)) {
236-
path = '\\' + path[0] + '\\' + path.substr(3);
236+
path = '\\' + path[0] + '\\' + path.slice(3);
237237
}
238238

239239
// We convert Windows paths as well here.

packages/angular_devkit/core/src/workspace/json/utilities.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -287,7 +287,7 @@ function create(
287287
}
288288

289289
for (const key of cache.keys()) {
290-
const relativeKey = key.substr(path.length + 1);
290+
const relativeKey = key.slice(path.length + 1);
291291
if (relativeKey.length > 0 && !relativeKey.includes('/')) {
292292
keys.push(`${unescapeKey(relativeKey)}`);
293293
}

0 commit comments

Comments
 (0)