CtrlK
BlogDocsLog inGet started
Tessl Logo

tessl/npm-snazzy

Format JavaScript Standard Style as Stylish (i.e. snazzy) output

94

1.18x
Overview
Eval results
Files

task.mdevals/scenario-9/

Line Counter CLI

Build a command-line tool that counts non-empty lines from stdin and outputs the count. The tool should follow Unix philosophy: do one thing well, work with pipes, and have minimal dependencies.

Requirements

The tool must:

  • Accept text input from stdin (piped input or explicit - or --stdin flag)
  • Count non-empty lines (lines with at least one non-whitespace character)
  • Output only the count as a single number to stdout
  • Exit with code 0 when successful
  • Handle empty input gracefully (output "0")
  • Display helpful usage message when run without piped input (when stdin is a TTY)

Behavior Examples

When piped text data:

echo -e "hello\nworld\n\n" | line-counter

Output: 2

When using explicit stdin flag:

line-counter - < data.txt
line-counter --stdin < data.txt

When run in terminal without input:

line-counter

Output: Usage message explaining the tool

Test Cases

  • Counting lines with "hello\nworld\n" outputs "2" @test
  • Empty input outputs "0" @test
  • Input with blank lines "a\n\nb\n" outputs "2" @test
  • Running without piped input displays usage message @test

Implementation

@generates

API

/**
 * LineCounterStream - Transform stream that counts non-empty lines
 * Extends stream.Transform from readable-stream
 */
class LineCounterStream extends Transform {
  constructor(options);
  _transform(chunk, encoding, callback);
  _flush(callback);
}

module.exports = LineCounterStream;

Dependencies { .dependencies }

readable-stream { .dependency }

Provides Node.js streams compatibility across versions.

@satisfied-by

minimist { .dependency }

Parses command-line arguments (e.g., --stdin flag).

@satisfied-by

Install with Tessl CLI

npx tessl i tessl/npm-snazzy

tile.json