# print-code

> Print visualized slice of code from its content, line and column for CLI

Latest version **1.0.2** (published 2016-01-20) · MIT license · 0 weekly downloads

## Install

```sh
npm install print-code
pnpm add print-code
yarn add print-code
bun add print-code
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.2 |
| Published | 2016-01-20 |
| First published | 2016-01-04 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Node | >=4.0.0 |
| Dependencies | 3 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 1 |
| Author | kaelzhang |
| Maintainers | kael |
| Keywords | print-code, visualize, visualization, cli, command-line, code, slice |

## Links

- npm: https://www.npmjs.com/package/print-code
- Repository: https://github.com/kaelzhang/node-print-code
- Homepage: https://github.com/kaelzhang/node-print-code#readme
- Issues: https://github.com/kaelzhang/node-print-code/issues
- npm.io page: https://npm.io/package/print-code

## Dependencies (3)

- [chalk](https://npm.io/package/chalk.md) ^1.1.1
- [make-array](https://npm.io/package/make-array.md) ^1.0.1
- [set-options](https://npm.io/package/set-options.md) ^1.0.2

## Alternatives

- [@salesforce/cli](https://npm.io/package/@salesforce/cli.md) — 389.7K weekly downloads
- [@mintlify/cli](https://npm.io/package/@mintlify/cli.md) — 208.9K weekly downloads
- [@grafana/e2e-selectors](https://npm.io/package/@grafana/e2e-selectors.md) — 128.7K weekly downloads
- [mintlify](https://npm.io/package/mintlify.md) — 112.0K weekly downloads
- [@intlayer/cli](https://npm.io/package/@intlayer/cli.md) — 22.8K weekly downloads

## Recent versions

- 1.0.2 (latest) — 2016-01-20
- 1.0.1 — 2016-01-08
- 0.0.0 — 2016-01-04

## README

[![Build Status](https://travis-ci.org/kaelzhang/node-print-code.svg?branch=master)](https://travis-ci.org/kaelzhang/node-print-code)
<!-- optional npm version
[![NPM version](https://badge.fury.io/js/print-code.svg)](http://badge.fury.io/js/print-code)
-->
<!-- optional npm downloads
[![npm module downloads per month](http://img.shields.io/npm/dm/print-code.svg)](https://www.npmjs.org/package/print-code)
-->
<!-- optional dependency status
[![Dependency Status](https://david-dm.org/kaelzhang/node-print-code.svg)](https://david-dm.org/kaelzhang/node-print-code)
-->

# print-code

Print visualized slice of code from its content, line and column for CLI.

## Install

```sh
$ npm install print-code --save
```

## Usage

```js
var code = require('print-code');
code(content)
  .highlight(4)
  .slice(1, 6)
  .max_columns(68)
  .arrow_mark(4, 10)
  .print()
```

And then the output might be (Line No 4 is red):

```
    1| 'use strict';
    2|
    3| module.exports = code
    4| code.Code = Code
----------------^ column: 10
    5|
```

#### .slice([from] [, to])

Specify which lines should be printed.

- **from** `Number=` The line number begins to be printed, and the value will be `parseInt()`ed. If not specified, it will print all lines. If 
- **to** `Number=` If not specified, it will only print the line of `from`

```js
code(content).slice().print();       // print all code
code(content).slice(10).print();     // print line 10
code(content).slice(10, 20).print(); // print lines from [10, 20)
```

Special cases:

```js
code(content).slice(-1, 10).print(); // will print lines from [0, 10)
code(content).slice(0, -1).print();  // will print lines except for the last line.
code(content).slice(10, 9);          // will only print line 10
code(content).slice(10, 11);         // will print line 10
```

#### .highlight(line [, ...])

Specify which line number(s) should be highlighted.

- line `Number` The number of code line, starts from `1`

#### .max_columns(max)

Limit the max columns to be printed.

- max `Number=` default to the max columns of the current terminal.

#### .arrow_mark(line, column)

Set a mark, and draw an arrow mark to the target coordinate (line, column).

#### .get()

Get the formated result content.

#### .print()

`console.log` the formated result content.

## License

MIT

---
_Source: https://npm.io/package/print-code · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
