An open API service indexing awesome lists of open source software.

https://github.com/rollercodester/consolate

Customize your Node.JS console like a dignitary.
https://github.com/rollercodester/consolate

animation bullets cli-spinners console-error console-log console-tool console-visualization progress spinner steps terminal-themes

Last synced: 3 months ago
JSON representation

Customize your Node.JS console like a dignitary.

Awesome Lists containing this project

README

          

[![npm](http://img.shields.io/npm/v/consolate.svg)](https://www.npmjs.org/package/consolate)
[![travis](https://travis-ci.org/rollercodester/consolate.svg?branch=master)](https://travis-ci.org/rollercodester/consolate)
[![Dependency Status](https://david-dm.org/rollercodester/consolate.svg)](https://david-dm.org/rollercodester/consolate)

# consolate
#### Customize your Node.JS console like a dignitary.
Easily create intuitive log functions on the console object—even override built-in console functions (error, info, warn, etc.) And while you're at it, feel free to easily define colors, prefixes, and bullets that can automatically animate [cli-cursors](https://www.npmjs.com/package/cli-spinners).

![examples/6-cicd-pipeline.js](https://cloud.githubusercontent.com/assets/1450389/23842310/a584cdfc-0770-11e7-8969-f2d6659ca41a.gif)

## Index

* [Examples](#examples)
* [Super-simple Custom Console Method](#example1)
* [Overriding Built-in Console Methods](#example2)
* [Animated vs Static Bullets](#example3)
* [Smart Log Argument Handling](#example4)
* [Apollo 11](#example5)
* [CI/CD Pipeline Console](#example6)
* [API Reference](#api)

## Examples

Super-simple Custom Console Method

![examples/1-simple-custom-method.js](https://cloud.githubusercontent.com/assets/1450389/23828435/20fe2f50-0686-11e7-962f-fbf2702ea259.gif)

```javascript
var consolate = require('consolate')

consolate.init({
arrow: {
color: consolate.colors.cyan,
prefix: {
chars: '>>>>>----->',
color: consolate.colors.lightCyan
}
}
})

console.arrow('My customized "arrow" log method!')

setTimeout(() => {
console.arrow('Just think of the possibilities :-)')
}, 1500)

setTimeout(() => {
console.arrow('And we haven\'t even scratched the surface.')
}, 3000)

setTimeout(() => {
console.arrow('Okay, one more time before moving on.')
console.log()
}, 4500)
```

Overriding Built-in Console Methods

![examples/2-console-overrides-on-built-in-methods.js](https://cloud.githubusercontent.com/assets/1450389/23828470/7610d2f8-0687-11e7-8410-fdf2b567775a.gif)

Animated vs Static Bullets

![examples/3-animated-and-static-bullets.js](https://cloud.githubusercontent.com/assets/1450389/23828520/e8a89fd4-0688-11e7-9c95-aa3959920f46.gif)

Smart Log Argument Handling

![examples/4-smart-log-argument-handling.js](https://cloud.githubusercontent.com/assets/1450389/23831679/bd7c44d6-06e3-11e7-9e8c-087b0b996a75.gif)

Apollo 11

![examples/5-apollo-11.js](https://cloud.githubusercontent.com/assets/1450389/23831850/6751c74a-06e6-11e7-8340-66e53124a7c0.gif)

CI/CD Pipeline Console

![examples/6-cicd-pipeline.js](https://cloud.githubusercontent.com/assets/1450389/23842310/a584cdfc-0770-11e7-8969-f2d6659ca41a.gif)

## API Reference

## consolate.init(options)
The initialization function that must be called to enable consolate.

**Kind**: static method of [consolate](#module_consolate)

| Param | Type | Description |
| --- | --- | --- |
| options | consolateOptions | (or string) Options object with values that drive consolate behavior OR this parameter can be a filepath to options yaml file. If options is not provided, then a default options file consolate.yml will be searched for in working directory. See example #6 (examples/6-cicd-pipeline.js) for an example options yaml file. |

## consolate~colors : enum
Color representations of ANSI output text codes that consolate supports.

**Kind**: inner enum of [consolate](#module_consolate)
**Read only**: true
**Properties**

| Name | Type | Default | Description |
| --- | --- | --- | --- |
| reset | number | 0 | Not a color, per se...rather used to reset the active color back to default |
| default | number | 39 | The default color configured by your terminal |
| black | number | 30 | |
| red | number | 31 | |
| green | number | 32 | |
| yellow | number | 33 | |
| blue | number | 34 | |
| magenta | number | 35 | |
| cyan | number | 36 | |
| lightGray | number | 37 | |
| darkGray | number | 90 | |
| lightRed | number | 91 | |
| lightGreen | number | 92 | |
| lightYellow | number | 93 | |
| lightBlue | number | 94 | |
| lightMagenta | number | 95 | |
| lightCyan | number | 96 | |
| white | number | 97 | |

## consolate~restore
Restores the console object back to its native state by removing all consolate modifications.

**Kind**: inner constant of [consolate](#module_consolate)

## consolate~consolateOptions : Object
The consolate options object that defines output methods and their respective settings and/or overrides existing log methods and their behavior.

**Kind**: inner typedef of [consolate](#module_consolate)
**Properties**

| Name | Type | Description |
| --- | --- | --- |
| key | string | The name of an output method (built-in or user-defined), which consolate will use to create a log method (of same name) on the console object. |
| value | outputMethodSettings | The settings to apply to the respecive output method. |

## consolate~outputMethodSettings : Object
An object that represents the settings for the output method that has the same name as this object's key.

**Kind**: inner typedef of [consolate](#module_consolate)
**Properties**

| Name | Type | Description |
| --- | --- | --- |
| inPlace | boolean | Specifies that when a series of calls are made for this output method, all subsequent output will be rendered on the same line after the initial call—in effect overwriting the previous console output. |
| color | colors | The color to use for the output text. |
| prefix | prefix | The prefix option (if any) to use for this output method. |
| bullet | bullet | The bullet option (if any) to use for this output method. |

## consolate~prefix : Object
Specifies preferences (if any) for including an automatic prefix to all console output for an output method.

**Kind**: inner typedef of [consolate](#module_consolate)
**Properties**

| Name | Type | Description |
| --- | --- | --- |
| chars | string | One or more characters to use as the prefix. |
| color | colors | The color to use for the prefix text. |
| leftPadding | number | The number of spaces to pad on the left side of the prefix. |
| rightPadding | number | The number of spaces to pad on the right side of the prefix. |

## consolate~bullet : Object
Specifies preferences (if any) for including an automatic left-aligned bullet to all console output for an output method.

**Kind**: inner typedef of [consolate](#module_consolate)
**Properties**

| Name | Type | Description |
| --- | --- | --- |
| cliSpinner | string | For an animated bullet, this is the spinner name to use per the [cli-spinners](https://www.npmjs.com/package/cli-spinners) library. Note: The animation will continue until a different output method is called, which will then overwrite the animation output, thus stopping and clearing it. |
| chars | string | For a static (non-animated) bullet, this is one or more characters to use as the bullet. This property is ignored if cliSpinner is specified. |
| color | colors | The color to use for the bullet text. |
| leftPadding | number | The number of spaces to pad on the left side of the bullet. |
| rightPadding | number | The number of spaces to pad on the right side of the bullet. |