Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

263
Views
¿Cómo puedo extraer los idiomas utilizados por los usuarios de la API de GitHub y sus porcentajes en mi página html?

mi clase ui js:

 constructor(){ this.profile=document.getElementById("profile"); } showRepoInfo(repos){ this.profile.innerHTML= ""; repos.forEach(repo => { this.profile.innerHTML += ` <div id="languages" class="lang"> <span class="badge" id="repoStar">${repo.language}</span> <span class="badgee" id="repoSize">${repo.size} KB</span> </div> `; }); }

¿Cómo puedo imprimir los idiomas que el usuario está usando en su repositorio y los percentiles de los idiomas? (imprimí el nombre de usuario, el nombre, el apellido y los nombres de repositorio que obtuve del usuario)

mi clase github js:

 class Github{ constructor(){ this.url = "https://api.github.com/users/"; } async getGithubData(username){ const responseUser = await fetch(this.url+username); const responseRepo = await fetch(this.url+username + "/repos"); const userData = await responseUser.json(); const repoData = await responseRepo.json(); return{ user:userData, repo:repoData } }
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Agregué una nueva función en su clase de github y ahora puede obtener el porcentaje de idioma usando ${repo.languagesPercentage} en html. Nota -> 1. Esta será una matriz, por lo que debe agregar un forEach o convertirlo en una cadena usando toString(). 2. Aumentará el número de llamadas de API en caso de repositorios grandes y se puede optimizar dando un botón en html llamado % de lenguaje de búsqueda.

 class Github { constructor() { this.url = "https://api.github.com/users/"; this.repoUrl = "https://api.github.com/repos/"; } async getGithubData(username) { const responseUser = await fetch(this.url + username); const responseRepo = await fetch(this.url + username + "/repos"); const userData = await responseUser.json(); const repoData = await responseRepo.json(); // set language percentage of each repo for (let i in repoData) { // get language percentage of repo repoData[i].languagesPercentage = await this.getRepoLanguagePercentage( username, repoData[i].name ); } return { user: userData, repo: repoData, }; } async getRepoLanguagePercentage(username, reponame) { const ls = await fetch( this.repoUrl + username + "/" + reponame + "/languages" ); const languageStats = await ls.json(); const totalPtsArr = Object.values(languageStats); var sumTotalPts = 0; totalPtsArr.forEach((pts) => { sumTotalPts += pts; }); const languagesPercentage = {}; Object.keys(languageStats).forEach((lang) => { languagesPercentage[lang] = (languageStats[lang] * 100) / sumTotalPts; }); return languagesPercentage; } }

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!