blob: a89be36d87f2ebfe23a019b3ddb3a92d06b4075c (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
|
# @npmcli/disparity-colors
[![NPM version](https://img.shields.io/npm/v/@npmcli/disparity-colors)](https://www.npmjs.com/package/@npmcli/disparity-colors)
[![Build Status](https://img.shields.io/github/workflow/status/npm/disparity-colors/node-ci)](https://github.com/npm/disparity-colors)
[![License](https://img.shields.io/github/license/npm/disparity-colors)](https://github.com/npm/disparity-colors/blob/master/LICENSE)
Spiritual sucessor to [disparity](https://www.npmjs.com/package/disparity). Colorizes [Diff Unified format](https://en.wikipedia.org/wiki/Diff#Unified_format) output using [ansi-styles](https://www.npmjs.com/package/ansi-styles).
## Install
`npm install @npmcli/disparity-colors`
## Usage:
```js
const colorize = require('@npmcli/disparity-colors')
mapWorkspaces(`--- a/src/index.js
+++ b/src/index.js
@@ -1,4 +1,5 @@
"use strict";
+"use foo";
const os = require("os");
`)
// [33m--- a/src/index.js[39m
// [33m+++ b/src/index.js[39m
// [35m@@ -1,4 +1,5 @@[39m
// "use strict";
// [32m+"use foo";[39m
//
// const os = require("os");
```
## API:
### `colorize(str, opts = {}) -> String`
- `str`: A [Diff Unified format](https://en.wikipedia.org/wiki/Diff#Unified_format) string
- `opts`:
- `headerLength`: A **Number** defining how many lines should be colorized as header
#### Returns
A **String** including the appropriate [ANSI escape codes](https://en.wikipedia.org/wiki/ANSI_escape_code#Colors_and_Styles)
## LICENSE
[ISC](./LICENSE)
|