yigitcukuren / linguist

A tool to count the code in the repo

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

github-linguist

đź’» Counts the number of lines of code, written in TypeScript.

Warning: This package uses regular expressions to approximate the lines of code in a project. The results are not 100% precise because the regular expressions can return mistakes in edge cases, for example if comment tokens are present inside of multiline strings.

Prerequisites

  • Node.js 6+

Install

npm install github-linguist

or

yarn add github-linguist

Usage

You can use loc in you ternimal, or as a npm package in your projects.

Command line mode

Supports counting lines of code of a file or directory.

1. Lines of code in a single file

# loc file <path>
loc file src/index.ts

loc file <path>

2. Lines of code in a directory

# loc <pattern>
loc dir **/*.ts

loc dir <pattern>

Third-party mode

import { LocFile, LocDir } from 'github-linguist';

// for a file.
const file = new LocFile(filePath);
const { info } = file.getInfo();

//  for a directory.
const dir = new LocDir({
  cwd: // root directory, or leave blank to use process.cwd()
  include: // string or string[] containing path patterns to include (default include all)
  exclude: // string or string[] containing path patterns to exclude (default exclude none)
});
const { info } = dir.loadInfo();

License

MIT License.

About

A tool to count the code in the repo


Languages

Language:TypeScript 88.8%Language:Less 4.6%Language:JavaScript 3.3%Language:EJS 3.1%Language:C# 0.1%Language:Python 0.1%Language:Ruby 0.0%Language:HTML 0.0%