Chore: Replace deprecated String.prototype.substr() (#46763)

.substr() is deprecated so we replace it with .slice() which works similarily but isn't deprecated
Signed-off-by: Tobias Speicher <rootcommander@gmail.com>
This commit is contained in:
CommanderRoot
2022-04-04 11:08:06 +02:00
committed by GitHub
parent ed140906de
commit d29b8e8858
25 changed files with 37 additions and 37 deletions
@@ -84,7 +84,7 @@ export const getTimeZoneGroups = memoize(
return groups;
}
const group = zone.substr(0, delimiter);
const group = zone.slice(0, delimiter);
groups[group] = groups[group] ?? [];
groups[group].push(zone);
+1 -1
View File
@@ -49,7 +49,7 @@ export function stringToMs(str: string): number {
}
const nr = parseInt(str, 10);
const unit = str.substr(String(nr).length);
const unit = str.slice(String(nr).length);
const s = 1000;
const m = s * 60;
const h = m * 60;
@@ -29,7 +29,7 @@ function clamp(value: number, min = 0, max = 1) {
* @beta
*/
export function hexToRgb(color: string) {
color = color.substr(1);
color = color.slice(1);
const re = new RegExp(`.{1,${color.length >= 6 ? 2 : 1}}`, 'g');
let colors = color.match(re);
@@ -141,7 +141,7 @@ export function decomposeColor(color: string | DecomposeColor): DecomposeColor {
values = values.split(' ');
colorSpace = values.shift();
if (values.length === 4 && values[3].charAt(0) === '/') {
values[3] = values[3].substr(1);
values[3] = values[3].slice(1);
}
if (['srgb', 'display-p3', 'a98-rgb', 'prophoto-rgb', 'rec-2020'].indexOf(colorSpace) === -1) {
throw new Error(
+2 -2
View File
@@ -87,7 +87,7 @@ export class CSVReader {
// #{columkey}#a,b,c
const idx = first.indexOf('#', 2);
if (idx > 0) {
const k = first.substr(1, idx - 1);
const k = first.slice(1, idx);
const isName = 'name' === k;
// Simple object used to check if headers match
@@ -103,7 +103,7 @@ export class CSVReader {
this.data.push(this.current);
}
const v = first.substr(idx + 1);
const v = first.slice(idx + 1);
if (isName) {
this.current.addFieldFor(undefined, v);
for (let j = 1; j < line.length; j++) {
@@ -66,7 +66,7 @@ export function toFixed(value: number, decimals?: DecimalCount): string {
const decimalPos = formatted.indexOf('.');
const precision = decimalPos === -1 ? 0 : formatted.length - decimalPos - 1;
if (precision < decimals) {
return (precision ? formatted : formatted + '.') + String(factor).substr(1, decimals - precision);
return (precision ? formatted : formatted + '.') + String(factor).slice(1, decimals - precision + 1);
}
return formatted;
@@ -105,7 +105,7 @@ export class DataSourcePicker extends PureComponent<DataSourcePickerProps, DataS
if (ds) {
return {
label: ds.name.substr(0, 37),
label: ds.name.slice(0, 37),
value: ds.uid,
imgUrl: ds.meta.info.logos.small,
hideText: hideTextValue,
@@ -11,7 +11,7 @@ var fs = require('fs');
var githubClient_1 = tslib_1.__importDefault(require('./githubClient'));
var resolveContentType = function (extension) {
if (extension.startsWith('.')) {
extension = extension.substr(1);
extension = extension.slice(1);
}
switch (extension) {
case 'zip':
@@ -8,7 +8,7 @@ import { AxiosResponse } from 'axios';
const resolveContentType = (extension: string): string => {
if (extension.startsWith('.')) {
extension = extension.substr(1);
extension = extension.slice(1);
}
switch (extension) {
case 'zip':
@@ -197,7 +197,7 @@ const getBaseWebpackConfig: WebpackConfigurationGetter = async (options) => {
(context, request, callback) => {
const prefix = 'grafana/';
if (request.indexOf(prefix) === 0) {
return callback(null, request.substr(prefix.length));
return callback(null, request.slice(prefix.length));
}
// @ts-ignore
+1 -1
View File
@@ -37,5 +37,5 @@ export function getNextCharacter(global?: any) {
const range = selection.getRangeAt(0);
const text = selection.anchorNode.textContent;
const offset = range.startOffset;
return text!.substr(offset, 1);
return text!.slice(offset, offset + 1);
}
@@ -32,7 +32,7 @@ export default function filterSpans(textFilter: string, spans: TraceSpan[] | TNi
.filter(Boolean)
.forEach((w) => {
if (w[0] === '-') {
excludeKeys.push(w.substr(1).toLowerCase());
excludeKeys.push(w.slice(1).toLowerCase());
} else {
includeFilters.push(w.toLowerCase());
}