Giter Club home page Giter Club logo

sloc's Introduction

sloc

Create stats of your source code:

  • physical lines
  • lines of code (source)
  • lines with comments
  • lines with single-line comments
  • lines with block comments
  • lines mixed up with source and comments
  • empty lines
  • lines with TODO's

Build Status Dependency Status NPM version Bower version License Minified size

Supported outputs

In addition to the default terminal output (see examples below), sloc provides an alternative set of output formatters:

  • CSV
  • JSON
  • Commandline table

Install

To use sloc as an application install it globally:

sudo npm install -g sloc

If you're going to use it as a Node.js module within your project:

npm install --save sloc

Browser

You can also use sloc within your browser application.

Link sloc.js in your HTML file:

<script src="lib/sloc.js"></script>

sloc is also available via bower:

bower install sloc

Note: You need to compile the coffee-script files yourself. If you want to use a precompiled bower package, you can run

bower install sloc-bower

Usage

CLI

sloc [option] <file>|<directory>

Options:

-h, --help                  output usage information
-V, --version               output the version number
-e, --exclude <regex>       regular expression to exclude files and folders
-f, --format <format>       format output: json, csv, cli-table
    --format-option [value] add formatter option
-k, --keys <keys>           report only numbers of the given keys
-d, --details               report stats of each analzed file
-a, --alias <custom ext>=<standard ext> alias custom ext to act like standard ext (eg. php5=php,less=css)

e.g.:

$ sloc src/

---------- Result ------------

            Physical :  1202
              Source :  751
             Comment :  322
 Single-line comment :  299
       Block comment :  23
               Mixed :  116
               Empty :  245

Number of files read :  10

------------------------------

or

$ sloc --details \
       --format cli-table \
       --keys total,source,comment \
       --exclude i18n*.\.coffee \
       --format-option no-head src/

┌─────────────────────────────────┬──────────┬────────┬─────────┐
│ src/cli.coffee                  │ 98       │ 74     │ 7       │
├─────────────────────────────────┼──────────┼────────┼─────────┤
│ src/helpers.coffee              │ 26       │ 20     │ 0       │
├─────────────────────────────────┼──────────┼────────┼─────────┤
│ src/sloc.coffee                 │ 196      │ 142    │ 20      │
├─────────────────────────────────┼──────────┼────────┼─────────┤
│ src/formatters/simple.coffee    │ 44       │ 28     │ 7       │
├─────────────────────────────────┼──────────┼────────┼─────────┤
│ src/formatters/csv.coffee       │ 25       │ 14     │ 5       │
├─────────────────────────────────┼──────────┼────────┼─────────┤
│ src/formatters/cli-table.coffee │ 22       │ 13     │ 0       │
└─────────────────────────────────┴──────────┴────────┴─────────┘

Node.js

Or use it in your own node module

var fs    = require('fs');
var sloc  = require('sloc');

fs.readFile("mySourceFile.coffee", "utf8", function(err, code){

  if(err){ console.error(err); }
  else{
    var stats = sloc(code,"coffee");
    for(i in sloc.keys){
      var k = sloc.keys[i];
      console.log(k + " : " + stats[k]);
    }
  }
});

Browser

var sourceCode = "foo();\n /* bar */\n baz();";

var stats = window.sloc(sourceCode,"javascript");

Contribute an new formatter

  1. Fork this repo

  2. add the new formatter into src/formatters/ that exports a method with three arguments:

    1. results (object)
    2. global options (object)
    3. formatter specific options (array)
  3. add the formatter in src/cli.coffee

  4. open a pull request

sloc adapters

Supported languages

  • Assembly
  • Brightscript
  • CoffeeScript / IcedCoffeeScript
  • C / C++
  • C#
  • Clojure / ClojureScript
  • CSS / SCSS / SASS / LESS / Stylus
  • Crystal
  • Erlang
  • Go
  • Groovy
  • HTML
  • Handlebars
  • Haskell
  • Haxe
  • Hilbert
  • hy
  • Jade
  • Java
  • JavaScript
  • JSX
  • Julia
  • Kotlin
  • Lua
  • LiveScript
  • Nix
  • Mochi
  • Monkey
  • Mustache
  • Nim
  • OCaml
  • Perl 5
  • Python
  • PHP
  • R
  • Racket
  • Ruby
  • Rust
  • Scala
  • Squirrel
  • SVG
  • Swift
  • Objective-C / Objective-C++
  • Typescript
  • Visual Basic
  • Yaml
  • XML

Run tests

npm test

Build

npm run prepublish

Changelog

see CHANGELOG.md

License

sloc is licensed under the MIT license

sloc's People

Contributors

flosse avatar bwin avatar stevenvachon avatar liamsi avatar tomsmeding avatar as3boyan avatar tw avatar hollingberry avatar hsablonniere avatar impressivewebs avatar mikevalstar avatar aglitchman avatar lopezloo avatar feugy avatar codetorex avatar yoshi6jp avatar wabain avatar sargunv avatar lewapkon avatar ungoldman avatar masimplo avatar markmontymark avatar mark-hahn avatar lvcabral avatar capaj avatar the-jake-z avatar ggilder avatar daclayton avatar prepor avatar

Watchers

James Cloos avatar Lucky avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.