This repository was archived by the owner on May 11, 2025. It is now read-only.
File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ .idea
2+ package-lock.json
3+ node_modules
Original file line number Diff line number Diff line change 11# codeline-statistic
22Parse the lines of code for each language in the repository and generate the results. (using nodeJS)
3+
4+
5+ # Initialization
6+ ``` shell
7+ npm install
8+ ```
Original file line number Diff line number Diff line change 1+ const express = require ( 'express' ) ;
2+ const axios = require ( 'axios' ) ;
3+ const app = express ( ) ;
4+
5+ async function syncAxios ( url ) {
6+ return ( await axios . get ( url ) ) . data ;
7+ }
8+
9+ async function getLanguage ( user , repo ) {
10+ return await syncAxios ( `https://api.github.com/repos/${ user } /${ repo } /languages` ) ;
11+ }
12+ app . get ( '/user/:user/' , async function ( req , res ) {
13+ const username = req . params . user ;
14+ const response = await syncAxios ( `https://api.github.com/users/${ username } /repos` ) ;
15+ const statistic = Object . values ( response ) . map ( async ( resp ) => {
16+ return await getLanguage ( username , resp [ 'name' ] ) ;
17+ } ) ;
18+ res . send ( statistic ) ;
19+ } )
20+
21+ app . get ( '/repo/:user/:repo/' , function ( req , res ) {
22+ res . send ( getLanguage ( req . params [ 'user' ] , req . params [ 'repo' ] ) ) ;
23+ } )
24+
25+ app . listen ( 3000 ) ;
Original file line number Diff line number Diff line change 1+ {
2+ "name" : " codeline-statistic" ,
3+ "version" : " 1.0.0" ,
4+ "description" : " Parse the lines of code for each language in the repository/account and generate the results. " ,
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/zmh-program/codeline-statistic.git"
12+ },
13+ "keywords" : [
14+ " line-statistic"
15+ ],
16+ "author" : " zmh-program" ,
17+ "license" : " MIT" ,
18+ "bugs" : {
19+ "url" : " https://github.com/zmh-program/codeline-statistic/issues"
20+ },
21+ "homepage" : " https://github.com/zmh-program/codeline-statistic#readme" ,
22+ "dependencies" : {
23+ "axios" : " ^1.3.2" ,
24+ "express" : " ^4.18.2"
25+ }
26+ }
You can’t perform that action at this time.
0 commit comments