From d526ac68c5d94db5629b965b03129157425a160e Mon Sep 17 00:00:00 2001 From: assumecs Date: Thu, 29 Jul 2021 12:09:11 +0800 Subject: [PATCH] Get slug from problem list for a new option of filename in English. --- src/commands/list.ts | 5 +++-- src/commands/show.ts | 2 ++ src/explorer/LeetCodeNode.ts | 3 +++ src/shared.ts | 2 ++ 4 files changed, 10 insertions(+), 2 deletions(-) diff --git a/src/commands/list.ts b/src/commands/list.ts index 7e7b36a7..b9c22842 100644 --- a/src/commands/list.ts +++ b/src/commands/list.ts @@ -19,11 +19,11 @@ export async function listProblems(): Promise { const result: string = await leetCodeExecutor.listProblems(showLocked, useEndpointTranslation); const problems: IProblem[] = []; const lines: string[] = result.split("\n"); - const reg: RegExp = /^(.)\s(.{1,2})\s(.)\s\[\s*(\d*)\s*\]\s*(.*)\s*(Easy|Medium|Hard)\s*\((\s*\d+\.\d+ %)\)/; + const reg: RegExp = /^(.)\s(.{1,2})\s(.)\s\[\s*(\d*)\s*\]\s*(.*)\s*(Easy|Medium|Hard)\s*\((\s*\d+\.\d+ %)\)\s*(.*)/; const { companies, tags } = await leetCodeExecutor.getCompaniesAndTags(); for (const line of lines) { const match: RegExpMatchArray | null = line.match(reg); - if (match && match.length === 8) { + if (match && match.length === 9) { const id: string = match[4].trim(); problems.push({ id, @@ -33,6 +33,7 @@ export async function listProblems(): Promise { name: match[5].trim(), difficulty: match[6].trim(), passRate: match[7].trim(), + slug: match[8].trim(), companies: companies[id] || ["Unknown"], tags: tags[id] || ["Unknown"], }); diff --git a/src/commands/show.ts b/src/commands/show.ts index 3aebce8f..5f299939 100644 --- a/src/commands/show.ts +++ b/src/commands/show.ts @@ -234,6 +234,8 @@ async function resolveRelativePath(relativePath: string, node: IProblem, selecte return node.id; case "name": return node.name; + case "slug": + return node.slug; case "camelcasename": return _.camelCase(node.name); case "pascalcasename": diff --git a/src/explorer/LeetCodeNode.ts b/src/explorer/LeetCodeNode.ts index 67aad324..39d209fe 100644 --- a/src/explorer/LeetCodeNode.ts +++ b/src/explorer/LeetCodeNode.ts @@ -14,6 +14,9 @@ export class LeetCodeNode { public get name(): string { return this.data.name; } + public get slug(): string { + return this.data.slug; + } public get state(): ProblemState { return this.data.state; diff --git a/src/shared.ts b/src/shared.ts index e09943f8..7a878ee1 100644 --- a/src/shared.ts +++ b/src/shared.ts @@ -76,6 +76,7 @@ export interface IProblem { state: ProblemState; id: string; name: string; + slug: string; difficulty: string; passRate: string; companies: string[]; @@ -88,6 +89,7 @@ export const defaultProblem: IProblem = { state: ProblemState.Unknown, id: "", name: "", + slug: "", difficulty: "", passRate: "", companies: [] as string[], pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy