ghloc is a project for counting the number of non-empty lines of code in a project.
It was made for my GitHub LOC Chrome extension and contains following changes:
- Supports private repositories
- Requires additional authorization
- Optimized for Vercel deployment
The project requires the following environment variables:
AUTH_TOKEN: Authentication token for API access (optional, no auth if empty)MAX_REPO_SIZE_MB: Maximum repository size in MB (optional, default: 100)MAX_AGE: Cache max age in seconds (optional, default: 300)
go mod downloadvercel devThe idea is simple: you make a request to the API in the format /<username>/<repository>/<branch> and you get the response with human-readable JSON.
You can see only some files using match URL parameter, e.g. with /someuser/somerepo?match=js only paths containing js will be considered. Examples of more powerful usage:
match=.js$will show only paths ending with.js.match=^src/will show only paths starting withsrc/(i.e. placed in thesrcfolder).match=!testwill filter out paths containingtest.match=!test,!.sumwill filter out paths containingtestor.sum.match=.json$,!^package-lock.json$will show only json files except forpackage-lock.jsonfile.
There is also filter URL parameter, which has the opposite behavior to match parameter. filter has the same syntax but it declares which files must be filtered out.
To make the response more compact (removing spaces from the json) you can use pretty=false, e.g. /someuser/somerepo?pretty=false.