2M4U / 2m4u

Welcome Github User to the Code Land of 2M4U (me), What you see below is a future project for updating my In-Game Fortnite Statistics, Feel free to Fork this repository If you wish to see how this works.
12 stars 7 forks source link

Possible fixes for update.js #6

Open OperativeA115 opened 1 year ago

OperativeA115 commented 1 year ago

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 commented 1 year ago

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 commented 1 year ago

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

MasterK0927 commented 1 year ago

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 commented 1 year ago

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

kiranrokkam09 commented 1 year ago

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

anshul-132002 commented 1 year ago

@OperativeA115 Assign me to solve this problem