get rid of usages of substr which is deprecated

Signed-off-by: Fredrik Adelöw <freben@gmail.com>
This commit is contained in:
Fredrik Adelöw
2023-01-23 14:20:17 +01:00
parent fc94542b2a
commit 85b04f659a
18 changed files with 37 additions and 21 deletions
+16
View File
@@ -0,0 +1,16 @@
---
'@backstage/plugin-catalog-backend-module-bitbucket': patch
'@backstage/plugin-catalog-backend-module-github': patch
'@backstage/plugin-catalog-backend-module-gitlab': patch
'@backstage/plugin-catalog-backend-module-azure': patch
'@backstage/plugin-azure-devops-backend': patch
'@backstage/plugin-git-release-manager': patch
'@backstage/core-components': patch
'@backstage/plugin-playlist-backend': patch
'@backstage/plugin-apache-airflow': patch
'@backstage/plugin-circleci': patch
'@backstage/plugin-bitrise': patch
'@backstage/plugin-sentry': patch
---
Internal refactor to not use deprecated `substr`
+1 -1
View File
@@ -20,7 +20,7 @@ const ondemandMetadata = fs
.reverse()
.map(file => yaml.load(fs.readFileSync(`./data/on-demand/${file}`, 'utf8')));
const truncate = text =>
text.length > 170 ? text.substr(0, 170) + '...' : text;
text.length > 170 ? text.slice(0, 170) + '...' : text;
const addVideoDocsLink = '/docs/overview/support';
const defaultIconUrl = 'img/logo-gradient-on-dark.svg';
+1 -1
View File
@@ -19,7 +19,7 @@ const pluginMetadata = fs
.map(file => yaml.load(fs.readFileSync(`./data/plugins/${file}`, 'utf8')))
.sort((a, b) => a.title.toLowerCase().localeCompare(b.title.toLowerCase()));
const truncate = text =>
text.length > 170 ? text.substr(0, 170) + '...' : text;
text.length > 170 ? text.slice(0, 170) + '...' : text;
const newForDays = 100;
@@ -22,11 +22,11 @@ export function stringToColor(str: string) {
let color = '#';
for (let i = 0; i < 3; i++) {
const value = (hash >> (i * 8)) & 0xff;
color += `00${value.toString(16)}`.substr(-2);
color += `00${value.toString(16)}`.slice(-2);
}
return color;
}
export function extractInitials(value: string) {
return value.match(/\b\w/g)?.join('').substring(0, 2);
return value.match(/\b\w/g)?.join('').slice(0, 2);
}
@@ -26,7 +26,7 @@ const timeDeltaToLabel = (delta: TimeDelta): string => {
let label = '';
const date = new Date(0);
date.setSeconds(delta.seconds);
const time = date.toISOString().substr(11, 8);
const time = date.toISOString().slice(11, 11 + 8);
if (delta.days === 0) {
label = `${time}`;
} else if (delta.days === 1) {
@@ -434,7 +434,7 @@ export function mappedRepoBuild(build: Build): RepoBuild {
queueTime: build.queueTime?.toISOString(),
startTime: build.startTime?.toISOString(),
finishTime: build.finishTime?.toISOString(),
source: `${build.sourceBranch} (${build.sourceVersion?.substr(0, 8)})`,
source: `${build.sourceBranch} (${build.sourceVersion?.slice(0, 8)})`,
uniqueName: build.requestedFor?.uniqueName ?? 'N/A',
};
}
@@ -489,7 +489,7 @@ export function mappedBuildRun(build: Build): BuildRun {
queueTime: build.queueTime?.toISOString(),
startTime: build.startTime?.toISOString(),
finishTime: build.finishTime?.toISOString(),
source: `${build.sourceBranch} (${build.sourceVersion?.substr(0, 8)})`,
source: `${build.sourceBranch} (${build.sourceVersion?.slice(0, 8)})`,
uniqueName: build.requestedFor?.uniqueName ?? 'N/A',
};
}
@@ -81,7 +81,7 @@ const renderSource = (build: BitriseBuildResult): React.ReactNode => {
rel="noreferrer"
startIcon={<GitHubIcon />}
>
{build.commitHash.substr(0, 6)}
{build.commitHash.slice(0, 6)}
</Button>
) : null;
};
@@ -132,7 +132,7 @@ export function parseUrl(urlString: string): {
catalogPath: string;
} {
const url = new URL(urlString);
const path = url.pathname.substr(1).split('/');
const path = url.pathname.slice(1).split('/');
const catalogPath = url.searchParams.get('path') || '/catalog-info.yaml';
@@ -342,7 +342,7 @@ function parseUrl(urlString: string): {
const url = new URL(urlString);
const indexOfProjectSegment =
url.pathname.toLowerCase().indexOf('/projects/') + 1;
const path = url.pathname.substr(indexOfProjectSegment).split('/');
const path = url.pathname.slice(indexOfProjectSegment).split('/');
// /projects/backstage/repos/techdocs-*/catalog-info.yaml
if (path.length > 3 && path[1].length && path[3].length) {
@@ -373,7 +373,7 @@ function parseBitbucketCloudUrl(urlString: string): {
searchEnabled: boolean;
} {
const url = new URL(urlString);
const pathMap = readPathParameters(url.pathname.substr(1).split('/'));
const pathMap = readPathParameters(url.pathname.slice(1).split('/'));
const query = url.searchParams;
if (!pathMap.has('workspaces')) {
@@ -17,7 +17,7 @@
import { GithubTopicFilters } from '../providers/GithubEntityProviderConfig';
export function parseGithubOrgUrl(urlString: string): { org: string } {
const path = new URL(urlString).pathname.substr(1).split('/');
const path = new URL(urlString).pathname.slice(1).split('/');
// /backstage
if (path.length === 1 && path[0].length) {
@@ -176,7 +176,7 @@ export function parseUrl(urlString: string): {
host: string;
} {
const url = new URL(urlString);
const path = url.pathname.substr(1).split('/');
const path = url.pathname.slice(1).split('/');
// /backstage/techdocs-*/blob/master/catalog-info.yaml
// can also be
@@ -423,7 +423,7 @@ export function parseUrl(urlString: string): {
host: string;
} {
const url = new URL(urlString);
const path = url.pathname.substr(1).split('/');
const path = url.pathname.slice(1).split('/');
// /backstage/techdocs-*/blob/master/catalog-info.yaml
// can also be
@@ -193,7 +193,7 @@ export function parseUrl(urlString: string): {
catalogPath: string;
} {
const url = new URL(urlString);
const path = url.pathname.substr(1).split('/');
const path = url.pathname.slice(1).split('/');
// (/group/subgroup)/blob/branch|*/filepath
const blobIndex = path.findIndex(p => p === 'blob');
+1 -1
View File
@@ -64,7 +64,7 @@ const mapSourceDetails = (buildData: BuildSummary) => {
branchName: String(buildData.branch),
commit: {
hash: String(buildData.vcs_revision),
shortHash: String(buildData.vcs_revision).substr(0, 7),
shortHash: String(buildData.vcs_revision).slice(0, 7),
committerName: buildData.committer_name,
url: commitDetails.commit_url,
},
@@ -17,7 +17,7 @@
import { GitReleaseManagerError } from '../errors/GitReleaseManagerError';
export function getShortCommitHash(hash: string) {
const shortCommitHash = hash.substr(0, 7);
const shortCommitHash = hash.slice(0, 7);
if (shortCommitHash.length < 7) {
throw new GitReleaseManagerError(
@@ -79,9 +79,9 @@ export function parseListPlaylistsFilterString(
const equalsIndex = statement.indexOf('=');
const key =
equalsIndex === -1 ? statement : statement.substr(0, equalsIndex).trim();
equalsIndex === -1 ? statement : statement.slice(0, equalsIndex).trim();
const value =
equalsIndex === -1 ? undefined : statement.substr(equalsIndex + 1).trim();
equalsIndex === -1 ? undefined : statement.slice(equalsIndex + 1).trim();
if (!key || !value) {
throw new InputError(
@@ -50,7 +50,7 @@ describe('util', () => {
'should get postgres major version, %p',
async databaseId => {
const knex = await databases.init(databaseId);
const expectedVersion = +databaseId.substr(9);
const expectedVersion = +databaseId.slice(9);
await expect(queryPostgresMajorVersion(knex)).resolves.toBe(
expectedVersion,
@@ -22,7 +22,7 @@ import { BackstageTheme } from '@backstage/theme';
import { Link } from '@backstage/core-components';
function stripText(text: string, maxLength: number) {
return text.length > maxLength ? `${text.substr(0, maxLength)}...` : text;
return text.length > maxLength ? `${text.slice(0, maxLength)}...` : text;
}
const useStyles = makeStyles<BackstageTheme>(theme => ({
root: {