Skip to content

Commit d526ac6

Browse files
committed
Get slug from problem list for a new option of filename in English.
1 parent adf255c commit d526ac6

File tree

4 files changed

+10
-2
lines changed

4 files changed

+10
-2
lines changed

src/commands/list.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,11 @@ export async function listProblems(): Promise<IProblem[]> {
1919
const result: string = await leetCodeExecutor.listProblems(showLocked, useEndpointTranslation);
2020
const problems: IProblem[] = [];
2121
const lines: string[] = result.split("\n");
22-
const reg: RegExp = /^(.)\s(.{1,2})\s(.)\s\[\s*(\d*)\s*\]\s*(.*)\s*(Easy|Medium|Hard)\s*\((\s*\d+\.\d+ %)\)/;
22+
const reg: RegExp = /^(.)\s(.{1,2})\s(.)\s\[\s*(\d*)\s*\]\s*(.*)\s*(Easy|Medium|Hard)\s*\((\s*\d+\.\d+ %)\)\s*(.*)/;
2323
const { companies, tags } = await leetCodeExecutor.getCompaniesAndTags();
2424
for (const line of lines) {
2525
const match: RegExpMatchArray | null = line.match(reg);
26-
if (match && match.length === 8) {
26+
if (match && match.length === 9) {
2727
const id: string = match[4].trim();
2828
problems.push({
2929
id,
@@ -33,6 +33,7 @@ export async function listProblems(): Promise<IProblem[]> {
3333
name: match[5].trim(),
3434
difficulty: match[6].trim(),
3535
passRate: match[7].trim(),
36+
slug: match[8].trim(),
3637
companies: companies[id] || ["Unknown"],
3738
tags: tags[id] || ["Unknown"],
3839
});

src/commands/show.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -234,6 +234,8 @@ async function resolveRelativePath(relativePath: string, node: IProblem, selecte
234234
return node.id;
235235
case "name":
236236
return node.name;
237+
case "slug":
238+
return node.slug;
237239
case "camelcasename":
238240
return _.camelCase(node.name);
239241
case "pascalcasename":

src/explorer/LeetCodeNode.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,9 @@ export class LeetCodeNode {
1414
public get name(): string {
1515
return this.data.name;
1616
}
17+
public get slug(): string {
18+
return this.data.slug;
19+
}
1720

1821
public get state(): ProblemState {
1922
return this.data.state;

src/shared.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ export interface IProblem {
7676
state: ProblemState;
7777
id: string;
7878
name: string;
79+
slug: string;
7980
difficulty: string;
8081
passRate: string;
8182
companies: string[];
@@ -88,6 +89,7 @@ export const defaultProblem: IProblem = {
8889
state: ProblemState.Unknown,
8990
id: "",
9091
name: "",
92+
slug: "",
9193
difficulty: "",
9294
passRate: "",
9395
companies: [] as string[],

0 commit comments

Comments
 (0)