npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

kloc-cli

v2.1.3

Published

A simple CLI tool to count lines of code in current working directory

Downloads

329

Readme

kloc

Kloc is a simple CLI tool to count lines of code in current working directory.

Install

npm i -g kloc-cli@latest

Usage

You can use kloc by providing flags for each command, or by running the commands without flags. If you use flags, the corresponding function will run. If you run a command without flags, you will be given a list of options to chose from for that specific command.

Commands

Kloc has 2 sets of commands, one set to configure kloc and the other set to use kloc.

Get

By default, kloc ignores all files and directories that start with a dot. Using the kloc get command, you can get the path to configuration files to further customize kloc.

Config

This command returns the path to the kloc.config.json file. This file contains arrays for file extensions to count and ignore.

kloc get --config

Then you will have to open the file using a text editor:

code "path-to-kloc.config.json"

Sample kloc.config.json file:

{
    "count": [
        ".js",
        ".md"
    ],
    "ignore": [
        ".json",
    ]
}

Ignore

This command returns the path to the .klocignore file. Tis file contains a list of directories that kloc will ignore.

kloc get --ignore

Then you will have to open the file using a text editor:

code "path-to-.klocignore"

Sample .klocignore file:

node_modules
build
dist

Count

This is the command used to count the number of lines of code in the current working directory. Before you use this, ensure you are in the directory you want to count in:

cd path/to/code

Oneline

This command counts the total number of lines of code and displays it in a single line.

kloc count --oneline

Sample output:

Loc for my-project 1000

File

This command counts the number of lines of code for each file and displays it in a tree.

kloc count --file

Sample output:

kloc
├── bin
│   └── kloc.js 115
└── src
    ├── commands
    │   ├── count
    │   │   ├── file.js 34
    │   │   ├── index.js 4
    │   │   ├── oneline.js 31
    │   │   └── table.js 45
    │   └── get
    │       ├── config.js 20
    │       ├── ignore.js 21
    │       └── index.js 2
    └── utils
        ├── constants.js 9
        ├── tableConfig.js 26
        └── validateItem.js 17

Table

This command counts number of lines of code for each language (file extension) and displays it in a table.

kloc count --table

Sample output:

┌─────────────────┬─────────────────┐
│ Language        │ Loc             │
├─────────────────┼─────────────────┤
│ js              │ 324             │
├─────────────────┼─────────────────┤
│ md              │ 149             │
└─────────────────┴─────────────────┘