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 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 thesrc
folder).match=!test
will filter out paths containingtest
.match=!test,!.sum
will filter out paths containingtest
or.sum
.match=.json$,!^package-lock.json$
will show only json files except forpackage-lock.json
file.
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
.