Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Possible fixes for update.js #6

Open
OperativeA115 opened this issue Dec 6, 2022 · 7 comments
Open

Possible fixes for update.js #6

OperativeA115 opened this issue Dec 6, 2022 · 7 comments

Comments

@OperativeA115
Copy link

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:

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

@2M4U
Copy link
Owner

2M4U commented Dec 9, 2022

Hello, I will take a long at this when I have some spare time, as I might need to rewrite this script anyway due it bugging out from time to timeimage

@dushyantpant5
Copy link

dushyantpant5 commented Sep 23, 2023

Hey @2M4U , could you assign me this issue?

@MasterK0927
Copy link

Hey @2M4U Keshav this side, I am looking forward to contribute in this project. I am fluent in JS and understood your problem. Please assign me this issue.

@dushyantpant5
Copy link

Hey @2M4U , I am ready for the task.

@kiranrokkam09
Copy link

Hey @2M4U , I am Interested in the task.

@anshul-132002
Copy link

@OperativeA115 Assign me to solve this problem

@Kartikey1306
Copy link

@OperativeA115 Assign me to this task

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

7 participants