Avoid the use of named capture groups

This commit is contained in:
Simon Warta
2021-05-18 13:19:28 +02:00
parent f17e8b77ad
commit 0852f4f5f2
2 changed files with 4 additions and 4 deletions
+2 -2
View File
@@ -13,11 +13,11 @@ export class GasPrice {
}
public static fromString(gasPrice: string): GasPrice {
const matchResult = gasPrice.match(/^(?<amount>[0-9.]+?)(?<denom>[a-z]+)$/);
const matchResult = gasPrice.match(/^([0-9.]+?)([a-z]+)$/);
if (!matchResult) {
throw new Error("Invalid gas price string");
}
const { amount, denom } = matchResult.groups as { readonly amount: string; readonly denom: string };
const [_, amount, denom] = matchResult;
if (denom.length < 3 || denom.length > 127) {
throw new Error("Gas price denomination must be between 3 and 127 characters");
}
+2 -2
View File
@@ -20,11 +20,11 @@ export class GasPrice {
}
public static fromString(gasPrice: string): GasPrice {
const matchResult = gasPrice.match(/^(?<amount>[0-9.]+?)(?<denom>[a-z]+)$/);
const matchResult = gasPrice.match(/^([0-9.]+?)([a-z]+)$/);
if (!matchResult) {
throw new Error("Invalid gas price string");
}
const { amount, denom } = matchResult.groups as { readonly amount: string; readonly denom: string };
const [_, amount, denom] = matchResult;
if (denom.length < 3 || denom.length > 127) {
throw new Error("Gas price denomination must be between 3 and 127 characters");
}