Skip to content

Commit 54e94ec

Browse files
authored
Change all usages of .substr to .substring (#4809)
1 parent 22db4f1 commit 54e94ec

File tree

6 files changed

+19
-19
lines changed

6 files changed

+19
-19
lines changed

packages/api-derive/src/accounts/info.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ function retrieveNick (api: DeriveApi, accountId?: AccountId): Observable<string
2121
) as Observable<Option<ITuple<[Bytes, Balance]>> | undefined>).pipe(
2222
map((nameOf): string | undefined =>
2323
nameOf?.isSome
24-
? u8aToString(nameOf.unwrap()[0]).substr(0, (api.consts.nicks.maxLength as u32).toNumber())
24+
? u8aToString(nameOf.unwrap()[0]).substring(0, (api.consts.nicks.maxLength as u32).toNumber())
2525
: undefined
2626
)
2727
);

packages/types-codec/src/base/Option.spec.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,8 +80,8 @@ describe('Option', (): void => {
8080

8181
// watch the hex prefix and length
8282
expect(
83-
new Option(registry, Bytes, HEX).toHex().substr(6)
84-
).toEqual(HEX.substr(2));
83+
new Option(registry, Bytes, HEX).toHex().substring(6)
84+
).toEqual(HEX.substring(2));
8585
});
8686

8787
it('converts correctly from hex with toNumber (U64)', (): void => {

packages/types-codec/src/base/Vec.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ describe('Vec', (): void => {
118118

119119
it('exposes a working map', (): void => {
120120
expect(
121-
vector.map((e): string => e.toString().substr(0, 1))
121+
vector.map((e): string => e.toString().substring(0, 1))
122122
).toEqual(['1', '2', '3', '4', '5']);
123123
});
124124

packages/types-codec/src/utils/sanitize.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -88,8 +88,8 @@ export function cleanupCompact (): Mapper {
8888
if (value[index] === '<') {
8989
const end = findClosing(value, index + 1) - 14;
9090

91-
if (value.substr(end, 14) === ' as HasCompact') {
92-
value = `Compact<${value.substr(index + 1, end - index - 1)}>`;
91+
if (value.substring(end, end + 14) === ' as HasCompact') {
92+
value = `Compact<${value.substring(index + 1, end)}>`;
9393
}
9494
}
9595
}
@@ -126,7 +126,7 @@ function replaceTagWith (value: string, matcher: string, replacer: (inner: strin
126126
const start = index + matcher.length;
127127
const end = findClosing(value, start);
128128

129-
value = `${value.substr(0, index)}${replacer(value.substr(start, end - start))}${value.substr(end + 1)}`;
129+
value = `${value.substring(0, index)}${replacer(value.substring(start, end))}${value.substring(end + 1)}`;
130130
}
131131
}
132132

@@ -157,7 +157,7 @@ export function removeColons (): Mapper {
157157
index = value.indexOf('::');
158158

159159
if (index === 0) {
160-
value = value.substr(2);
160+
value = value.substring(2);
161161
} else if (index !== -1) {
162162
if (allowNamespaces) {
163163
return value;
@@ -169,7 +169,7 @@ export function removeColons (): Mapper {
169169
start--;
170170
}
171171

172-
value = `${value.substr(0, start + 1)}${value.substr(index + 2)}`;
172+
value = `${value.substring(0, start + 1)}${value.substring(index + 2)}`;
173173
}
174174
}
175175

@@ -185,7 +185,7 @@ export function removeGenerics (): Mapper {
185185
const box = ALLOWED_BOXES.find((box): boolean => {
186186
const start = index - box.length;
187187

188-
return (start >= 0 && value.substr(start, box.length) === box) && (
188+
return (start >= 0 && value.substring(start, start + box.length) === box) && (
189189
// make sure it is stand-alone, i.e. don't catch ElectionResult<...> as Result<...>
190190
start === 0 || BOX_PRECEDING.includes(value[start - 1])
191191
);
@@ -195,7 +195,7 @@ export function removeGenerics (): Mapper {
195195
if (!box) {
196196
const end = findClosing(value, index + 1);
197197

198-
value = `${value.substr(0, index)}${value.substr(end + 1)}`;
198+
value = `${value.substring(0, index)}${value.substring(end + 1)}`;
199199
}
200200
}
201201
}

packages/types-create/src/util/getTypeDef.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -128,8 +128,8 @@ function _decodeFixedVec (value: TypeDef, type: string, _: string, count: number
128128

129129
assert(index !== -1, () => `${type}: Unable to extract location of ';'`);
130130

131-
const vecType = type.substr(1, index - 1);
132-
const [strLength, displayName] = type.substr(index + 1, max - index - 1).split(';');
131+
const vecType = type.substring(1, index);
132+
const [strLength, displayName] = type.substring(index + 1, max).split(';');
133133
const length = parseInt(strLength.trim(), 10);
134134

135135
// 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
154154
// decode a Int/UInt<bitLength[, name]>
155155
// eslint-disable-next-line @typescript-eslint/no-unused-vars
156156
function _decodeAnyInt (value: TypeDef, type: string, _: string, clazz: 'Int' | 'UInt'): TypeDef {
157-
const [strLength, displayName] = type.substr(clazz.length + 1, type.length - clazz.length - 1 - 1).split(',');
157+
const [strLength, displayName] = type.substring(clazz.length + 1, type.length - 1).split(',');
158158
const length = parseInt(strLength.trim(), 10);
159159

160160
// 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 {
178178
function _decodeDoNotConstruct (value: TypeDef, type: string, _: string): TypeDef {
179179
const NAME_LENGTH = 'DoNotConstruct'.length;
180180

181-
value.displayName = type.substr(NAME_LENGTH + 1, type.length - NAME_LENGTH - 1 - 1);
181+
value.displayName = type.substring(NAME_LENGTH + 1, type.length - 1);
182182

183183
return value;
184184
}
185185

186186
function hasWrapper (type: string, [start, end]: [string, string, TypeDefInfo, any?]): boolean {
187-
return (type.substr(0, start.length) === start) && (type.substr(-1 * end.length) === end);
187+
return (type.substring(0, start.length) === start) && (type.slice(-1 * end.length) === end);
188188
}
189189

190190
const nestedExtraction: [string, string, TypeDefInfo, (value: TypeDef, type: string, subType: string, count: number) => TypeDef][] = [
@@ -213,7 +213,7 @@ const wrappedExtraction: [string, string, TypeDefInfo][] = [
213213
];
214214

215215
function extractSubType (type: string, [start, end]: [string, string, TypeDefInfo, any?]): string {
216-
return type.substr(start.length, type.length - start.length - end.length);
216+
return type.substring(start.length, type.length - end.length);
217217
}
218218

219219
// eslint-disable-next-line @typescript-eslint/ban-types

packages/types-create/src/util/typeSplit.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ export function typeSplit (type: string): string[] {
1414

1515
const extract = (index: number): void => {
1616
if (isNotNested(cDepth, fDepth, sDepth, tDepth)) {
17-
result.push(type.substr(start, index - start).trim());
17+
result.push(type.substring(start, index).trim());
1818
start = index + 1;
1919
}
2020
};
@@ -45,7 +45,7 @@ export function typeSplit (type: string): string[] {
4545
assert(isNotNested(cDepth, fDepth, sDepth, tDepth), () => `Invalid definition (missing terminators) found in ${type}`);
4646

4747
// the final leg of the journey
48-
result.push(type.substr(start, type.length - start).trim());
48+
result.push(type.substring(start, type.length).trim());
4949

5050
return result;
5151
}

0 commit comments

Comments
 (0)