# traceback.js

> 代码回溯。指定文本的位置，格式化显示选定区域

Latest version **0.3.0** (published 2021-05-22) · MIT license · 0 weekly downloads

## Install

```sh
npm install traceback.js
pnpm add traceback.js
yarn add traceback.js
bun add traceback.js
```

## Health

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

Positive: no vulnerabilities.

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

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.3.0 |
| Published | 2021-05-22 |
| First published | 2020-04-18 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 16.4 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Author | LitileXueZha |
| Maintainers | litilexuezha |
| Keywords | stack, stacktrace, trace, traceback, code, format |

## Links

- npm: https://www.npmjs.com/package/traceback.js
- Repository: https://github.com/LitileXueZha/traceback.js
- Homepage: https://github.com/LitileXueZha/traceback.js#readme
- Issues: https://github.com/LitileXueZha/traceback.js/issues
- npm.io page: https://npm.io/package/traceback.js

## Alternatives

- [flatbuffers](https://npm.io/package/flatbuffers.md) — 6.0M weekly downloads
- [jwt-simple](https://npm.io/package/jwt-simple.md) — 259.5K weekly downloads
- [@exodus/patch-broken-hermes-typed-arrays](https://npm.io/package/@exodus/patch-broken-hermes-typed-arrays.md) — 28.5K weekly downloads
- [@native-to-anchor/buffer-layout](https://npm.io/package/@native-to-anchor/buffer-layout.md) — 12.2K weekly downloads
- [binary-parser-encoder](https://npm.io/package/binary-parser-encoder.md) — 5.3K weekly downloads

## Recent versions

- 0.3.0 (latest) — 2021-05-22
- 0.2.1 — 2021-05-18
- 0.1.2 — 2020-05-30
- 0.0.2 — 2020-04-18

## README

# traceback.js

代码回溯。指定一段文本的位置，格式化显示

![预览图](https://tao-1252397519.cos.ap-shanghai.myqcloud.com/github-projects/traceback-js.jpg)

## 使用

安装：

```shell
npm install traceback.js --save
```

可使用的 API 有：`init`、`render`、`renderToString`

### `init`

初始化配置并渲染源文本：

```javascript
import TracebackJS from 'traceback.js';

TracebackJS.init('.traceback-js', { highlightRow: 5 });
```

1. 第一个参数 `selectors` 为 css 选择符
2. 第二个参数 `opts` 为配置对象

配置对象 `opts`:

```javascript
// 下面的值均为默认值
{
    highlightRow: 1, // 高亮行
    start: 1, // 起始行号
    displayRows: '-5+5', // 展示规则。可以是 -1|string|object
    separator: '\n', // 分隔符。全部源文本使用它分隔成一行行
}
```

`displayRows` 展示规则：

+ `-1` 展示全部行
+ `'-10+8'` 展示前 10 行、后 8 行
+ `{ upward, downward }` 展示前 upward 行、后 downward 行

### `render` (底层 API)

根据源文本，返回渲染 dom：

```javascript
fetch('sometext.txt')
    .then(res => res.text())
    .then((data) => {
        const $dom = TracebackJS.render(data, opts);

        insert($dom); // 可供操作的 dom
    });
```

### `renderToString`

返回 html 字符串而不是添加到 dom 中。

```javascript
TracebackJS.renderToString(data, { highlightRow: 4 }); // html 字符串
// '<div class="traceback-js">...</div>'
```

1. 第一个参数 `rawInput` 为源文本
2. 第二个参数 `opts` 为配置对象

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