npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

leetcode-api-typescript

v1.12.2

Published

Leetcode api with typescript and full async

Downloads

57

Readme

Leetcode API TS

Leetcode API written with TypeScript, fully support async.

Thanks for the excellent work for leetcode-cli project! ❤️

GitHub package.json dynamic GitHub package.json version Build Lint

Install

  • npm: npm i leetcode-api-typescript
  • yarn: yarn add leetcode-api-typescript
  • pnpm: pnpm i leetcode-api-typescript

Usage

(async (): Promise<void> => {

    // Login
    const leetcode: Leetcode = await Leetcode.build(
        "your username",
        "your password",
        EndPoint.US     // or EndPoint.CN
    );

    // Get a special problem
    const problem: Problem = new Problem("two-sum");

    // Fetch more properties of this problem
    await problem.detail();

    // Show problem content, test case, code snippet etc
    const content: string = problem.content;
    const testCase: string = problem.sampleTestCase;
    const codeSnippets: Array<codeSnippets> = problem.codeSnippets;

    // submit your answer
    problem.submit("your code language", "your code here");

    // Get All problems' base information
    const problems: Array<Problem> = await leetcode.getAllProblems();

    // Filter problems by status, difficulty, etc
    const acceptedProblems: Array<Problem> = problems.filter((p: Problem) => {
        return p.status === ProblemStatus.Accept;
    });

    acceptedProblems.forEach(async (problem: Problem) => {

        // Get all submissions
        const submissions: Array<Submission> = await problem.getSubmissions();

        // Filter submission which lang = cpp
        const cppSubmissions: Array<Submission> = submissions.filter((s: Submission) => {
            return s.lang === "cpp";
        });

        submissions.forEach((submission: Submission) => {

            // Get submission's status
            const code: string = await submission.detail();

            // Then you can handle them casually
        });
    });
})();

Tips

I especially recommend you fetch base properties first because of the large number of problems. Then call Problem.detail() or Submission.detail() fetch all properties of them.

TODO

  • [X] ~~Support Leetcode CN.~~ [2019-08-24]
  • [ ] Fetch more user profile.
  • [ ] Fully parse submission status type.
  • [ ] Support problems filter by categories.
  • [ ] Support problems filter by companies.

Test

  • cp .env.example .env
  • Update your leetcode account in .env
  • pnpm test.

Contribute

  • start: pnpm start
  • build: pnpm build
  • lint: pnpm lint

License

MIT.