Various improvements #169
1 changed files with 3 additions and 2 deletions
Use named group
commit
29784eb600
|
|
@ -9,7 +9,7 @@ import { isBinary } from "../utils/is-binary";
|
||||||
import type { ServerConfig } from "../services/server-config";
|
import type { ServerConfig } from "../services/server-config";
|
||||||
|
|
||||||
export class FileOperations {
|
export class FileOperations {
|
||||||
private static readonly PARENTHESES_REGEX = / \((\d+)\)$/;
|
private static readonly PARENTHESES_REGEX = / \((?<count>\d+)\)$/;
|
||||||
private readonly fs: SafeFileSystemOperations;
|
private readonly fs: SafeFileSystemOperations;
|
||||||
|
|
|||||||
|
|
||||||
public constructor(
|
public constructor(
|
||||||
|
|
@ -251,7 +251,8 @@ export class FileOperations {
|
||||||
: "";
|
: "";
|
||||||
let stem = extension ? nameParts.slice(0, -1).join(".") : fileName;
|
let stem = extension ? nameParts.slice(0, -1).join(".") : fileName;
|
||||||
let currentCount = Number.parseInt(
|
let currentCount = Number.parseInt(
|
||||||
FileOperations.PARENTHESES_REGEX.exec(stem)?.[1] ?? "0"
|
FileOperations.PARENTHESES_REGEX.exec(stem)?.groups?.["count"] ??
|
||||||
|
"0"
|
||||||
);
|
);
|
||||||
stem = stem.replace(FileOperations.PARENTHESES_REGEX, "");
|
stem = stem.replace(FileOperations.PARENTHESES_REGEX, "");
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue
[nitpick] The named capture group is called 'count' but is accessed as 'groups?.count' in the code at line 265. For consistency with the previous code that used groups?.[0], consider either keeping the array access pattern or updating the comment to explain the named group convention.