diff --git a/CHANGELOG.md b/CHANGELOG.md index 355b79907..d7d04d720 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,7 @@ Changes: - Optimize `u8aToHex` with direct (non-hex) conversion +- Change all occurences of `.substr(...)` to `.substring(...)` ## 9.1.1 Apr 30, 2022 diff --git a/packages/util-crypto/src/base32/helpers.ts b/packages/util-crypto/src/base32/helpers.ts index f80076c9d..7e26ad799 100644 --- a/packages/util-crypto/src/base32/helpers.ts +++ b/packages/util-crypto/src/base32/helpers.ts @@ -33,7 +33,7 @@ export function createDecode ({ coder, ipfs }: Config, validate: ValidateFn): De return coder.decode( ipfs && ipfsCompat - ? value.substr(1) + ? value.substring(1) : value ); }; diff --git a/packages/util-crypto/src/key/DeriveJunction.ts b/packages/util-crypto/src/key/DeriveJunction.ts index a7aeee9c9..e705b1e20 100644 --- a/packages/util-crypto/src/key/DeriveJunction.ts +++ b/packages/util-crypto/src/key/DeriveJunction.ts @@ -20,7 +20,7 @@ export class DeriveJunction { public static from (value: string): DeriveJunction { const result = new DeriveJunction(); const [code, isHard] = value.startsWith('/') - ? [value.substr(1), true] + ? [value.substring(1), true] : [value, false]; result.soft( diff --git a/packages/util-crypto/src/key/extractPath.ts b/packages/util-crypto/src/key/extractPath.ts index 54d869f58..c64d21277 100644 --- a/packages/util-crypto/src/key/extractPath.ts +++ b/packages/util-crypto/src/key/extractPath.ts @@ -24,7 +24,7 @@ export function keyExtractPath (derivePath: string): ExtractResult { constructed = parts.join(''); for (const p of parts) { - path.push(DeriveJunction.from(p.substr(1))); + path.push(DeriveJunction.from(p.substring(1))); } } diff --git a/packages/util-crypto/src/mnemonic/toMiniSecret.spec.ts b/packages/util-crypto/src/mnemonic/toMiniSecret.spec.ts index 590801ead..5dd3effb0 100644 --- a/packages/util-crypto/src/mnemonic/toMiniSecret.spec.ts +++ b/packages/util-crypto/src/mnemonic/toMiniSecret.spec.ts @@ -43,7 +43,7 @@ describe('mnemonicToMiniSecret', (): void => { u8aToHex(mnemonicToMiniSecret(mnemonic, 'Substrate', onlyJs)) ).toEqual( // mini returned here, only check first 32-bytes (64 hex + 2 prefix) - seed.substr(0, 66) + seed.substring(0, 66) ); }); }); diff --git a/packages/util/src/format/formatDecimal.ts b/packages/util/src/format/formatDecimal.ts index 98dc127c2..09d1c0481 100644 --- a/packages/util/src/format/formatDecimal.ts +++ b/packages/util/src/format/formatDecimal.ts @@ -9,7 +9,7 @@ export function formatDecimal (value: string): string { // we rather strip and re-add the negative sign in the output const isNegative = value[0].startsWith('-'); const matched = isNegative - ? value.substr(1).match(NUMBER_REGEX) + ? value.substring(1).match(NUMBER_REGEX) : value.match(NUMBER_REGEX); return matched diff --git a/packages/util/src/hex/stripPrefix.ts b/packages/util/src/hex/stripPrefix.ts index 821b0f033..3f14ab591 100644 --- a/packages/util/src/hex/stripPrefix.ts +++ b/packages/util/src/hex/stripPrefix.ts @@ -21,7 +21,7 @@ export function hexStripPrefix (value?: string | null): string { if (!value || value === '0x') { return ''; } else if (REGEX_HEX_PREFIXED.test(value)) { - return value.substr(2); + return value.substring(2); } else if (REGEX_HEX_NOPREFIX.test(value)) { return value; } diff --git a/packages/util/src/hex/toU8a.ts b/packages/util/src/hex/toU8a.ts index fe1be1b98..afa227652 100644 --- a/packages/util/src/hex/toU8a.ts +++ b/packages/util/src/hex/toU8a.ts @@ -42,11 +42,13 @@ export function hexToU8a (_value?: HexString | string | null, bitLength = -1): U const length = endLength - offset - mod; for (let i = 0; i < length; i += 2) { - dv.setUint16(i, HEX_TO_U16[value.substr(i * 2, 4)]); + const idx = i * 2; + + dv.setUint16(i, HEX_TO_U16[value.substring(idx, idx + 4)]); } if (mod) { - dv.setUint8(length, HEX_TO_U8[value.substr(value.length - 2, 2)]); + dv.setUint8(length, HEX_TO_U8[value.substring(value.length - 2)]); } return result; diff --git a/packages/util/src/logger.ts b/packages/util/src/logger.ts index a086bed0d..d097dbfd8 100644 --- a/packages/util/src/logger.ts +++ b/packages/util/src/logger.ts @@ -59,7 +59,7 @@ function formatWithLength (maxLength: number): (v: unknown) => unknown { return r.length < maxLength ? v - : `${r.substr(0, maxLength)} ...`; + : `${r.substring(0, maxLength)} ...`; }; } diff --git a/packages/util/src/string/shorten.ts b/packages/util/src/string/shorten.ts index bc676b2a9..a8e649b4d 100644 --- a/packages/util/src/string/shorten.ts +++ b/packages/util/src/string/shorten.ts @@ -20,5 +20,5 @@ import type { AnyString } from '../types'; export function stringShorten (value: AnyString, prefixLength = 6): string { return value.length <= 2 + 2 * prefixLength ? value.toString() - : `${value.substr(0, prefixLength)}…${value.slice(-prefixLength)}`; + : `${value.substring(0, prefixLength)}…${value.slice(-prefixLength)}`; }