peekaleet 1.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CONTRIBUTIONS.MD +67 -0
- package/README.MD +62 -0
- package/index.js +125 -0
- package/package.json +23 -0
package/CONTRIBUTIONS.MD
ADDED
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
# Contributing to PeekALeet
|
|
2
|
+
|
|
3
|
+
First off, thank you for considering contributing to **PeekALeet**!
|
|
4
|
+
Your time and effort help improve the project for everyone.
|
|
5
|
+
|
|
6
|
+
This document outlines how to contribute effectively and maintain the quality and architecture of the project.
|
|
7
|
+
|
|
8
|
+
---
|
|
9
|
+
|
|
10
|
+
## Project Philosophy
|
|
11
|
+
|
|
12
|
+
PeekALeet is designed to:
|
|
13
|
+
|
|
14
|
+
- Use a **single GraphQL request**
|
|
15
|
+
- Remain lightweight
|
|
16
|
+
- Avoid unnecessary dependencies
|
|
17
|
+
- Stay backend-friendly
|
|
18
|
+
- Keep public profile support only
|
|
19
|
+
- Maintain performance efficiency
|
|
20
|
+
|
|
21
|
+
Please respect this architecture when contributing.
|
|
22
|
+
|
|
23
|
+
---
|
|
24
|
+
|
|
25
|
+
# How to Contribute
|
|
26
|
+
|
|
27
|
+
## 1. Fork the Repository
|
|
28
|
+
|
|
29
|
+
Click the **Fork** button at the top-right of the GitHub repository.
|
|
30
|
+
|
|
31
|
+
---
|
|
32
|
+
|
|
33
|
+
## 2️. Clone Your Fork
|
|
34
|
+
|
|
35
|
+
```bash
|
|
36
|
+
git clone https://github.com/your-username/PeekALeet.git
|
|
37
|
+
cd PeekALeet
|
|
38
|
+
```
|
|
39
|
+
## 3. Create a feature branch
|
|
40
|
+
```bash
|
|
41
|
+
git checkout -b feature/your-feature-name
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
## 4. Commit Changes
|
|
45
|
+
```bash
|
|
46
|
+
git commit -m "Add: TypeScript support"
|
|
47
|
+
```
|
|
48
|
+
## 5. Raise a PR
|
|
49
|
+
```bash
|
|
50
|
+
git push origin feature/your-feature-name
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
# Architectural Rules
|
|
54
|
+
|
|
55
|
+
These are important:
|
|
56
|
+
|
|
57
|
+
❗ Do NOT convert to multiple GraphQL calls
|
|
58
|
+
|
|
59
|
+
❗ Do NOT add scraping logic
|
|
60
|
+
|
|
61
|
+
❗ Do NOT introduce authentication dependencies
|
|
62
|
+
|
|
63
|
+
❗ Keep it public-profile only
|
|
64
|
+
|
|
65
|
+
❗ Maintain single-request efficiency
|
|
66
|
+
|
|
67
|
+
Performance is a **core** principle of this project.
|
package/README.MD
ADDED
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
# PeekALeet
|
|
2
|
+
|
|
3
|
+
> Lightweight Node.js utility for fetching public LeetCode user data using a single optimized GraphQL request.
|
|
4
|
+
|
|
5
|
+
PeekALeet consolidates profile details, contest history, problem statistics, streak data, and recent submissions into **one efficient API call** — reducing latency and eliminating redundant network requests.
|
|
6
|
+
|
|
7
|
+
---
|
|
8
|
+
|
|
9
|
+
## Why PeekALeet?
|
|
10
|
+
|
|
11
|
+
Most implementations fetch LeetCode data using multiple HTTP calls.
|
|
12
|
+
PeekALeet uses **one consolidated GraphQL query** to retrieve everything at once.
|
|
13
|
+
|
|
14
|
+
### Benefits
|
|
15
|
+
|
|
16
|
+
- Single request → lower latency
|
|
17
|
+
- Reduced network overhead
|
|
18
|
+
- Clean class-based architecture
|
|
19
|
+
- Easy backend integration
|
|
20
|
+
- Selective data loading
|
|
21
|
+
- No authentication required (public profiles only)
|
|
22
|
+
|
|
23
|
+
---
|
|
24
|
+
|
|
25
|
+
## Installation
|
|
26
|
+
|
|
27
|
+
```bash
|
|
28
|
+
npm install peekaleet
|
|
29
|
+
```
|
|
30
|
+
## Basic Usage
|
|
31
|
+
```javascript
|
|
32
|
+
const PeekALeet = require("peekaleet");
|
|
33
|
+
|
|
34
|
+
async function example() {
|
|
35
|
+
const user = new PeekALeet("leetcode_username");
|
|
36
|
+
|
|
37
|
+
await user.load({
|
|
38
|
+
totalCount: true,
|
|
39
|
+
topicwise: true,
|
|
40
|
+
recent: true,
|
|
41
|
+
contest: true,
|
|
42
|
+
streak: true
|
|
43
|
+
});
|
|
44
|
+
|
|
45
|
+
console.log("Profile:", user.profile);
|
|
46
|
+
console.log("Total Solved:", user.totalCount);
|
|
47
|
+
console.log("Streak:", user.streak);
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
example();
|
|
51
|
+
```
|
|
52
|
+
## Option Configurations
|
|
53
|
+
```json
|
|
54
|
+
await user.load({
|
|
55
|
+
totalCount: true,
|
|
56
|
+
topicwise: true,
|
|
57
|
+
recent: false,
|
|
58
|
+
contest: true,
|
|
59
|
+
streak: true
|
|
60
|
+
});
|
|
61
|
+
```
|
|
62
|
+
---
|
package/index.js
ADDED
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
const axios = require("axios");
|
|
2
|
+
|
|
3
|
+
class PeekALeet {
|
|
4
|
+
constructor(username) {
|
|
5
|
+
this.username = username;
|
|
6
|
+
|
|
7
|
+
this.profile = null;
|
|
8
|
+
this.totalCount = null;
|
|
9
|
+
this.topicwise = null;
|
|
10
|
+
this.recent = null;
|
|
11
|
+
this.streak = null;
|
|
12
|
+
this.contest = null;
|
|
13
|
+
|
|
14
|
+
this.endpoint = "https://leetcode.com/graphql/";
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
async load(options = {}) {
|
|
18
|
+
const query = `
|
|
19
|
+
query fullUserData($username: String!, $limit: Int!) {
|
|
20
|
+
|
|
21
|
+
matchedUser(username: $username) {
|
|
22
|
+
username
|
|
23
|
+
githubUrl
|
|
24
|
+
twitterUrl
|
|
25
|
+
linkedinUrl
|
|
26
|
+
|
|
27
|
+
profile {
|
|
28
|
+
ranking
|
|
29
|
+
userAvatar
|
|
30
|
+
realName
|
|
31
|
+
aboutMe
|
|
32
|
+
school
|
|
33
|
+
countryName
|
|
34
|
+
company
|
|
35
|
+
jobTitle
|
|
36
|
+
reputation
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
userCalendar {
|
|
40
|
+
streak
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
tagProblemCounts {
|
|
44
|
+
advanced { tagName problemsSolved }
|
|
45
|
+
intermediate { tagName problemsSolved }
|
|
46
|
+
fundamental { tagName problemsSolved }
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
languageProblemCount {
|
|
50
|
+
problemsSolved
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
recentAcSubmissionList(username: $username, limit: $limit) {
|
|
55
|
+
id
|
|
56
|
+
title
|
|
57
|
+
titleSlug
|
|
58
|
+
timestamp
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
userContestRankingHistory(username: $username) {
|
|
62
|
+
ranking
|
|
63
|
+
rating
|
|
64
|
+
contest {
|
|
65
|
+
title
|
|
66
|
+
startTime
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
`;
|
|
71
|
+
|
|
72
|
+
const res = await axios.post(
|
|
73
|
+
this.endpoint,
|
|
74
|
+
{
|
|
75
|
+
query,
|
|
76
|
+
variables: {
|
|
77
|
+
username: this.username,
|
|
78
|
+
limit: 15
|
|
79
|
+
}
|
|
80
|
+
},
|
|
81
|
+
{
|
|
82
|
+
headers: { "Content-Type": "application/json" }
|
|
83
|
+
}
|
|
84
|
+
);
|
|
85
|
+
|
|
86
|
+
const data = res.data.data;
|
|
87
|
+
|
|
88
|
+
if (!data || !data.matchedUser) {
|
|
89
|
+
throw new Error("User not found");
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
const user = data.matchedUser;
|
|
93
|
+
|
|
94
|
+
this.profile = user;
|
|
95
|
+
|
|
96
|
+
if (options.streak) {
|
|
97
|
+
this.streak = user.userCalendar?.streak || 0;
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
if (options.topicwise) {
|
|
101
|
+
this.topicwise = user.tagProblemCounts;
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
if (options.totalCount) {
|
|
105
|
+
this.totalCount = user.languageProblemCount.reduce(
|
|
106
|
+
(sum, lang) => sum + lang.problemsSolved,
|
|
107
|
+
0
|
|
108
|
+
);
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
if (options.recent) {
|
|
112
|
+
this.recent = data.recentAcSubmissionList;
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
if (options.contest) {
|
|
116
|
+
this.contest = data.userContestRankingHistory.map(item => ({
|
|
117
|
+
title: item.contest.title,
|
|
118
|
+
ranking: item.ranking,
|
|
119
|
+
rating: item.rating
|
|
120
|
+
}));
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
module.exports = PeekALeet;
|
package/package.json
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "peekaleet",
|
|
3
|
+
"version": "1.0.1",
|
|
4
|
+
"description": "",
|
|
5
|
+
"main": "index.js",
|
|
6
|
+
"scripts": {
|
|
7
|
+
"test": "echo \"Error: no test specified\" && exit 1"
|
|
8
|
+
},
|
|
9
|
+
"repository": {
|
|
10
|
+
"type": "git",
|
|
11
|
+
"url": "git+https://github.com/ajdeevs/peekaleet.git"
|
|
12
|
+
},
|
|
13
|
+
"keywords": [],
|
|
14
|
+
"author": "",
|
|
15
|
+
"license": "ISC",
|
|
16
|
+
"bugs": {
|
|
17
|
+
"url": "https://github.com/ajdeevs/peekaleet/issues"
|
|
18
|
+
},
|
|
19
|
+
"homepage": "https://github.com/ajdeevs/peekaleet#readme",
|
|
20
|
+
"dependencies": {
|
|
21
|
+
"axios": "^1.13.4"
|
|
22
|
+
}
|
|
23
|
+
}
|