# herb

> The Logging Monster!

Latest version **2.3.0** (published 2024-07-15) · MIT license · 0 weekly downloads

## Install

```sh
npm install herb
pnpm add herb
yarn add herb
bun add herb
```

## 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 | 2.3.0 |
| Published | 2024-07-15 |
| First published | 2014-12-22 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 3 |
| Unpacked size | 576.2 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 4 |
| Author | Schahriar SaffarShargh |
| Maintainers | schahriar |
| Keywords | herb, console, log, logs, logging, table, paragraph, line, CLI, color, styling |

## Links

- npm: https://www.npmjs.com/package/herb
- Repository: https://github.com/schahriar/herb
- Issues: https://github.com/schahriar/herb/issues
- npm.io page: https://npm.io/package/herb

## Dependencies (3)

- [lodash](https://npm.io/package/lodash.md) ^4.17.21
- [culinary](https://npm.io/package/culinary.md) ^1.1.0
- [cli-table](https://npm.io/package/cli-table.md) ^0.3.1

## Alternatives

- [@lexical/table](https://npm.io/package/@lexical/table.md) — 3.0M weekly downloads
- [mantine-datatable](https://npm.io/package/mantine-datatable.md) — 98.2K weekly downloads
- [react-native-collapsible-tab-view](https://npm.io/package/react-native-collapsible-tab-view.md) — 70.6K weekly downloads
- [@handsontable/vue3](https://npm.io/package/@handsontable/vue3.md) — 16.1K weekly downloads
- [vuewordcloud](https://npm.io/package/vuewordcloud.md) — 7.2K weekly downloads

## Recent versions

- 2.3.0 (latest) — 2024-07-15
- 2.2.6 — 2015-05-17
- 2.2.5 — 2015-05-17
- 2.2.4 — 2015-05-16
- 2.2.3 — 2015-05-16
- 2.2.2 — 2015-05-16
- 2.2.1 — 2015-05-16
- 2.2.0 — 2015-05-16
- 2.1.1 — 2015-01-02
- 2.1.0 — 2015-01-02
- 1.3.7 — 2014-12-24
- 1.3.6 — 2014-12-24
- 1.3.5 — 2014-12-23
- 1.3.4 — 2014-12-22
- 1.3.3 — 2014-12-22
- … 4 more at https://npm.io/package/herb/versions

## README

![Herbal Logo](logo.png)

Add some true flavour to your **NodeJS** console!
======

**herb** is a magical layer for the most complex *logs*. To put it in simple words it enables advanced functions missing in the current Node logging system (console.log). **You can group, count, and add lines, paragraphs or tables** all in *color!* and the best part about it is the fact that you can just replace the global ***console*** with **herb** without further modifications!

## Installation
```javascript
npm install herb
```
or if you are developing a module
```javascript
npm install herb --save
```

## Usage
### Logging
Either
```javascript
var herb = require('herb');

herb.log("An herb log");
herb.warn("An herb warning");
```
Or
```javascript
var console = require('herb');

console.log("An herb log");
console.warn("An herb warning");
// Even
console.count('label');
```

## Colors & Styles
All [Culinary](https://www.npmjs.com/package/culinary) styles and colors are supported!
e.g.
```
herb.log(herb.green('SUCCESS'), herb.underline('www.example.com'))
```
- **Colors:** Black, White, Green, Blue, Cyan, Magenta, Red, Yellow
- **Backgrounds:** bgBlack, bgWhite, bgGreen, bgBlue, bgCyan, bgMagenta, bgRed, bgYellow
- **Spices:** bold, underline, ~~strikethrough~~ *(barely supported by clients)*, italic, **hidden**, invert, reset

## Methods
**Info, Log, Warn, Error** (color:blue, blue, yellow, red, verbosity:4, 3, 2, 1) -> herb.log(log, json, ...)

**Write** "Writes logs through process.stdout rather than console.log but retains similar behavior" -> herb.write(log1, log2, ...)

**Template** "Allows for color templating" -> herb.template(type, color1, color2, style3, ...)
```javascript
var header = herb.template('log', 'green', 'white', 'green');
header('This will be green', 'white here', '& back to green again', 'this will be ignored');
```

**Clear** "Clears console screen" -> herb.clear()

**ClearLine** "Clears last line for writing" -> herb.clearLine()

**Count** "Counts to label" -> herb.count(label)
```javascript
herb.count("Apples");
herb.count("Apples");
/// Output:
// Apples : 1
// Apples : 2
```
---------------
**Group, GroupEnd** "Creates a group" -> herb.group(title)
```javascript
herb.group("Fruits");
herb.log("Apples");
herb.log("Oranges");
herb.groupEnd();
herb.warn("Group ended!");
/// Output:
// > Fruits
// | Apples
// | Oranges
// Group ended!
```
---------------
**Time, TimeEnd** "Measure time in ms" -> herb.time(label)
```javascript
herb.time("timeout");
setTimeout(function() { herb.timeEnd("timeout") }, 1200);
/// Output after 1200ms: (the output includes timeout computation time ~ 4ms to 12ms)
// timeout: 1200ms
```
---------------

**Humanify** "Output human friendly json" -> herb.humanify(json)
```javascript
herb.humanify({
	"_id": "54a643971784e5031c7a34a2",
	"index": 3,
	"guid": "37f345d8-de55-46c2-9071-73d0b6982194",
	"isActive": true,
	"name": "Head Schneider"
});
/// Output:
// _id:       54a643971784e5031c7a34a2
// index:     3
// guid:      37f345d8-de55-46c2-9071-73d0b6982194
// isActive:  true
// name:      Head Schneider
```
---------------

**Paragraph** "Output a formatted paragraph" -> herb.paragraph(text)
```javascript
herb.paragraph("Anim magna velit ipsum id et dolor labore."
+ "Irure ipsum enim in laborum deserunt elit sit eu sit id"
+ "et adipisicing eu do. Ad nulla ullamco excepteur consequat"
+ "veniam ut. Tempor elit excepteur nulla pariatur irure nisi.",
{ alignment: "center", color: "green", width: '50%', margin: '50%' });
/// Outputs a green centered text with half width in the middle of the screen
```
---------------

**Table** "Output a formatted table" -> herb.table({ headers: [...], rows: [[...],[...],...], borders: false })
```javascript
herb.table({
	headers: ['id','name','email','last logged'],
	rows: [
		['1', 'Lorem ipsum', 'lorem@example.com', 'January 1st 2015'],
		['2', '', '', ''],
		['3', 'John Doe', 'info@example.com', 'November 5th 2014']
	],
	borders: false // Full is a table style
});
/// Outputs a green centered text with half width in the middle of the screen
```
---------------

**Line** "Output a divider" -> herb.line('_')
```javascript
herb.line('_');
// Or combine multiple characters
herb.line('<-->');
/// Outputs two full width (console width) lines e.g.:
// _________________________
// <--><--><--><--><--><--><-
```
---------------
[You can check out pictures of these methods here.](./tutorials/methods.md)


## Config & LogFile
```javascript
var herb = require('herb');

// Config is dynamic
// You can modify config at any point
herb.config({
  // Verbosity of logs (integer)
  // Note that higher numbers cover the entire group e.g. 3 = ['Log','Warn','Error']
  verbose: 3, // 4: Info, 3: Log, 2: Warn, 1: Error, 0: Fatal

  prependTime: false, // Prepends time [hour:minute:seconds] to every log if enabled

  // Can be set to a file e.g. "./log" & logs every log within the verbosity into the file
  logFile: undefined,

  // Add a prefix to all output
  prefix: undefined
})
```
Log files can be read using a simple code:
```javascript
var fs = require('fs');
console.log(fs.readFileSync('./log', {encoding: 'utf8'}));
```

## Marker
You can modify **background**, **color** and **style** of every output using marker. If { permanent: boolean } is set to true then the marker will override every output otherwise it will be cleared after each output.
```javascript
var herb = require('herb');

herb.marker({ color: 'green' }).log('A success story!');
// A Magenta line
herb.marker({ color: 'magenta' }).line('-');
```

## Test Suite
You can do a complex yet boring test by running the following in the source directory:
```javascript
npm install mocha -g
npm test
```
*I'll soon add a visual test.*

## Contributing
The goal is to create a *rich command-line interface experience* for NodeJS.
I am currently looking for active contributors to create **documentation**, **improve** the code and add **innovations** to the module. If you are interested you can contact me directly at <info@schahriar.com>!

## License
MIT © Schahriar SaffarShargh <info@schahriar.com>

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