2M4U / 2M4U/2m4u

Possible fixes for update.js

Offen
#6 9 Kommentare 0 Reaktionen 0 zugewiesene Personen Auf GitHub ansehen
Vorherrschende Sprache
JavaScript
Sterne
17
Forks
14
PR-Merge-Kennzahlen
Keine gemergten PRs in 30 T.

Beschreibung

Hello *2M4U* usually I am a C / C++ type person but again here I am helping make your JS code better LMAO!

Use more descriptive and clear variable and function names to improve code readability. For example, `const getDateSuffix = (date)` could be named `getDateSuffix()`, and `const WriteReadMe = async ()` could be named `writeReadMe()`.

Use `const` and `let` keywords instead of `var` keyword to declare variables. This would prevent accidental reassignment of variables and improve code readability.

Use the `async/await` syntax instead of Promises to make the code easier to read and write. This would make the code look similar to synchronous code, while still allowing it to run asynchronously.

Use template literals (backticks) to create strings that contain expressions. This would make the code more readable and easier to maintain.

Use the newline character (\n) to improve the readability of long strings by adding line breaks where appropriate.

Consider using a destructuring assignment to extract properties from an object and store them in separate variables. This would make the code more concise and easier to read.

Here is how the code might look after applying these suggestions:
```JS
const { join } = require("path");
const fetch = require("node-fetch");
const { writeFileSync } = require("fs");
const Twitter = require("twitter");
const days = ["Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"];
const months = [
"Jan",
"Feb",
"Mar",
"Apr",
"May",
"Jun",
"Jul",
"Aug",
"Sep",
"Oct",
"Nov",
"Dec",
];

const getDateSuffix = (date) => {
if (date >= 10 && date < 20) {
return "th";
}

return (
{
1: "st",
2: "nd",
3: "rd",
}[date % 10] ?? "th"
);
};

const make2Digit = (num) => `0${num}`.slice(-2);

const client = new Twitter({
consumer_key: process.env.TWITTER_API_KEY,
consumer_secret: process.env.TWITTER_SECRET,
access_token_key: process.env.TWITTER_ACCESS_KEY,
access_token_secret: process.env.TWITTER_TOKEN_SECRET,
});

let stars = 0,
page = 1;

const countStars = async () => {
const starsData = await fetch(
`https://api.github.com/users/2M4U/starred?per_page=100&page=${page}`
).then((res) => res.json());
stars += starsData.length;
page++;
if (starsData.length === 100) countStars();
else writeReadMe();
};

const writeReadMe = async () => {
const readMePath = join(__dirname, "..", "README.md");
const now = new Date();

const { screen_name: screenName, count } = { screen_name: "
```

Hope this helps if you need anymore feedback LMK!
__Thanks OperativeA115 - C++ / C Programmer__

Beitragsleitfaden

Für dieses Repository ist kein Beitragsleitfaden indexiert

Bewertung

Dieses Issue wurde noch nicht bewertet.

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.