Change all usages of .substr to .substring (#4809)

This commit is contained in:
Jaco
2022-05-10 10:39:15 +03:00
committed by GitHub
parent 22db4f1c3d
commit 54e94ec6bc
6 changed files with 19 additions and 19 deletions
+1 -1
View File
@@ -21,7 +21,7 @@ function retrieveNick (api: DeriveApi, accountId?: AccountId): Observable<string
) as Observable<Option<ITuple<[Bytes, Balance]>> | undefined>).pipe(
map((nameOf): string | undefined =>
nameOf?.isSome
? u8aToString(nameOf.unwrap()[0]).substr(0, (api.consts.nicks.maxLength as u32).toNumber())
? u8aToString(nameOf.unwrap()[0]).substring(0, (api.consts.nicks.maxLength as u32).toNumber())
: undefined
)
);
+2 -2
View File
@@ -80,8 +80,8 @@ describe('Option', (): void => {
// watch the hex prefix and length
expect(
new Option(registry, Bytes, HEX).toHex().substr(6)
).toEqual(HEX.substr(2));
new Option(registry, Bytes, HEX).toHex().substring(6)
).toEqual(HEX.substring(2));
});
it('converts correctly from hex with toNumber (U64)', (): void => {
+1 -1
View File
@@ -118,7 +118,7 @@ describe('Vec', (): void => {
it('exposes a working map', (): void => {
expect(
vector.map((e): string => e.toString().substr(0, 1))
vector.map((e): string => e.toString().substring(0, 1))
).toEqual(['1', '2', '3', '4', '5']);
});
+7 -7
View File
@@ -88,8 +88,8 @@ export function cleanupCompact (): Mapper {
if (value[index] === '<') {
const end = findClosing(value, index + 1) - 14;
if (value.substr(end, 14) === ' as HasCompact') {
value = `Compact<${value.substr(index + 1, end - index - 1)}>`;
if (value.substring(end, end + 14) === ' as HasCompact') {
value = `Compact<${value.substring(index + 1, end)}>`;
}
}
}
@@ -126,7 +126,7 @@ function replaceTagWith (value: string, matcher: string, replacer: (inner: strin
const start = index + matcher.length;
const end = findClosing(value, start);
value = `${value.substr(0, index)}${replacer(value.substr(start, end - start))}${value.substr(end + 1)}`;
value = `${value.substring(0, index)}${replacer(value.substring(start, end))}${value.substring(end + 1)}`;
}
}
@@ -157,7 +157,7 @@ export function removeColons (): Mapper {
index = value.indexOf('::');
if (index === 0) {
value = value.substr(2);
value = value.substring(2);
} else if (index !== -1) {
if (allowNamespaces) {
return value;
@@ -169,7 +169,7 @@ export function removeColons (): Mapper {
start--;
}
value = `${value.substr(0, start + 1)}${value.substr(index + 2)}`;
value = `${value.substring(0, start + 1)}${value.substring(index + 2)}`;
}
}
@@ -185,7 +185,7 @@ export function removeGenerics (): Mapper {
const box = ALLOWED_BOXES.find((box): boolean => {
const start = index - box.length;
return (start >= 0 && value.substr(start, box.length) === box) && (
return (start >= 0 && value.substring(start, start + box.length) === box) && (
// make sure it is stand-alone, i.e. don't catch ElectionResult<...> as Result<...>
start === 0 || BOX_PRECEDING.includes(value[start - 1])
);
@@ -195,7 +195,7 @@ export function removeGenerics (): Mapper {
if (!box) {
const end = findClosing(value, index + 1);
value = `${value.substr(0, index)}${value.substr(end + 1)}`;
value = `${value.substring(0, index)}${value.substring(end + 1)}`;
}
}
}
+6 -6
View File
@@ -128,8 +128,8 @@ function _decodeFixedVec (value: TypeDef, type: string, _: string, count: number
assert(index !== -1, () => `${type}: Unable to extract location of ';'`);
const vecType = type.substr(1, index - 1);
const [strLength, displayName] = type.substr(index + 1, max - index - 1).split(';');
const vecType = type.substring(1, index);
const [strLength, displayName] = type.substring(index + 1, max).split(';');
const length = parseInt(strLength.trim(), 10);
// as a first round, only u8 via u8aFixed, we can add more support
@@ -154,7 +154,7 @@ function _decodeTuple (value: TypeDef, _: string, subType: string, count: number
// decode a Int/UInt<bitLength[, name]>
// eslint-disable-next-line @typescript-eslint/no-unused-vars
function _decodeAnyInt (value: TypeDef, type: string, _: string, clazz: 'Int' | 'UInt'): TypeDef {
const [strLength, displayName] = type.substr(clazz.length + 1, type.length - clazz.length - 1 - 1).split(',');
const [strLength, displayName] = type.substring(clazz.length + 1, type.length - 1).split(',');
const length = parseInt(strLength.trim(), 10);
// as a first round, only u8 via u8aFixed, we can add more support
@@ -178,13 +178,13 @@ function _decodeUInt (value: TypeDef, type: string, subType: string): TypeDef {
function _decodeDoNotConstruct (value: TypeDef, type: string, _: string): TypeDef {
const NAME_LENGTH = 'DoNotConstruct'.length;
value.displayName = type.substr(NAME_LENGTH + 1, type.length - NAME_LENGTH - 1 - 1);
value.displayName = type.substring(NAME_LENGTH + 1, type.length - 1);
return value;
}
function hasWrapper (type: string, [start, end]: [string, string, TypeDefInfo, any?]): boolean {
return (type.substr(0, start.length) === start) && (type.substr(-1 * end.length) === end);
return (type.substring(0, start.length) === start) && (type.slice(-1 * end.length) === end);
}
const nestedExtraction: [string, string, TypeDefInfo, (value: TypeDef, type: string, subType: string, count: number) => TypeDef][] = [
@@ -213,7 +213,7 @@ const wrappedExtraction: [string, string, TypeDefInfo][] = [
];
function extractSubType (type: string, [start, end]: [string, string, TypeDefInfo, any?]): string {
return type.substr(start.length, type.length - start.length - end.length);
return type.substring(start.length, type.length - end.length);
}
// eslint-disable-next-line @typescript-eslint/ban-types
+2 -2
View File
@@ -14,7 +14,7 @@ export function typeSplit (type: string): string[] {
const extract = (index: number): void => {
if (isNotNested(cDepth, fDepth, sDepth, tDepth)) {
result.push(type.substr(start, index - start).trim());
result.push(type.substring(start, index).trim());
start = index + 1;
}
};
@@ -45,7 +45,7 @@ export function typeSplit (type: string): string[] {
assert(isNotNested(cDepth, fDepth, sDepth, tDepth), () => `Invalid definition (missing terminators) found in ${type}`);
// the final leg of the journey
result.push(type.substr(start, type.length - start).trim());
result.push(type.substring(start, type.length).trim());
return result;
}