{"id":24998029,"url":"https://github.com/riennevaplus/console2","last_synced_at":"2025-04-12T06:24:41.230Z","repository":{"id":57206137,"uuid":"41839870","full_name":"RienNeVaPlus/console2","owner":"RienNeVaPlus","description":"▶ Improves log readability using ASCII box-drawing characters.","archived":false,"fork":false,"pushed_at":"2022-07-13T02:29:03.000Z","size":471,"stargazers_count":9,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-03-26T01:51:07.605Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/RienNeVaPlus.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2015-09-03T03:15:46.000Z","updated_at":"2022-01-12T03:04:09.000Z","dependencies_parsed_at":"2022-09-19T12:10:36.601Z","dependency_job_id":null,"html_url":"https://github.com/RienNeVaPlus/console2","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/RienNeVaPlus%2Fconsole2","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/RienNeVaPlus%2Fconsole2/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/RienNeVaPlus%2Fconsole2/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/RienNeVaPlus%2Fconsole2/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/RienNeVaPlus","download_url":"https://codeload.github.com/RienNeVaPlus/console2/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248526381,"owners_count":21118878,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2025-02-04T17:38:25.827Z","updated_at":"2025-04-12T06:24:41.195Z","avatar_url":"https://github.com/RienNeVaPlus.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"\u003ch1 align=\"center\"\u003e\n\t\u003cimg src=\"media/logo.png\" alt=\"console2\"\u003e\n\u003c/h1\u003e\n\n#### Massively extends the `console` features to produce human readable output. Provides content boxes using ASCII box-drawing characters, improvements for the output of object inspections (using tables), stack traces and more. It can even beep! ####\n\n#### → [Screenshot of `console.help`](https://raw.githubusercontent.com/safebyte/console2/master/media/help.png)\n\n## Features\n\n- Structured output using [ASCII box-draing characters](https://en.wikipedia.org/wiki/Box-drawing_character)\n- Fully compatible to the system `console`\n- Improved object inspection (pretty nice tables)\n- Improved stack traces\n- Improved timer\n- Ability to nest boxes\n- Additional console features\n- Various formatting shortcuts\n- Clean and focused\n- Intelligent use of colors to make contents even more distinguishable\n\n## Install\n\n```\n$ npm install --save console2\n```\n\n### Quick Start\n\nHave a [screenshot](https://raw.githubusercontent.com/safebyte/console2/master/media/help.png) of the output.\n\n```javascript\nconst console2 = require('console2')()\nconsole2.help()\n```\n\n## Usage\n\nConsole2 integrates seamlessly into the node `console`. However, you should make yourself familiar with the additional features, especially `box`, `line`, `over` \u0026 `out`.\n\n```javascript\nconst console2 = require('console2')()\n\n// log a string\nconsole2.log(\"They're minerals! Jesus Christ, Marie.\")\n// as you know and love it, native methods are fully supported\n\n// logs a string \"the new way\"\nconsole2.line(\"You shall not pass (immediately)\")\n// this queues your string until you call \"console.out\"\n// read more on this below\n\n// insert empty line \u0026 start a timer\nconsole2.spacer().time('Timer1')\n\n// build a box - returns a new console instance\nconst box = console2.box('I am a child.')\n\n// add a line to our new box\nbox.line('I am the 2nd line of the sub box!')\n\n// indicate that the box can be printed and there will be no more lines/boxes appended to it\nbox.over()\n\n// insert empty line \u0026 print timer\nconsole2.spacer().time('Timer1')\n\n// make noise\nconsole2.beep()\n\n// print everything, this exists because most actions are async\nconsole2.out()\n```\n\n#### Result\n\n\u003cimg src=\"media/usage.png\" /\u003e\n\n# Managing boxes. **Over** and **Out**.\n\nThe main feature is the generation of *easy-to-read ASCII box-drawing character sections* - short: **boxes**.\n\n```\n// returns a new console instance which acts as a child box\nvar box = console.box()\n```\n\nThese boxes are 2 dimensional (meaning they depend on the previous / following lines), you can no longer *just stdout a line* when building a box. Doing so would result in a big mess of lines without any context to each other, because of the [nature of time](https://en.wikipedia.org/wiki/Asynchronous_operation). Imagine you want to log the process of updating a database inside a single box, whilst complimenting yourself:\n\n```js\nbox.log('Trying database update')\nsetTimeout(function mimicDatabaseUpdate(){\n   box.log('Database updated')\n}, 1)\nconsole.log('You look gorgeous!')\n\n// expected output:\n// ├ You look gorgeous\n// ├─ Starting database update\n// └─ Database updated\n\n// actual output:\n// ├─ Starting database update\n// ├ You look gorgeous\n// └─ Database updated\n```\n\n#### *\"Houston we have a problem.\"*\n\nAs you see, you need to wait until you are done adding new lines before you can print a box. The solution is simple: **We queue stuff**.\nInstead of `console.log`, use `console.line`. It does the same thing, except for calling `stdout` (it's not printing the line).\n\n```js\nbox.line('Trying database update')\nsetTimeout(function mimicDatabaseUpdate(){\n   box.line('Database updated')\n}, 1)\nconsole.log('You look gorgeous!')\n```\n\n*But now there's only the part where I compliment myself?* Right, here's what happened: You've added a line, then printed everything *that's ready* (`console.log` did that) and finally added another line to your box. But you didn't mark the box as **over** / *ready* and therefore console2 thinks you might want to add more lines.\n\n#### \"No you don't. Over and out!\"\n\n```js\n   // ...\n   box.line('Database updated').out()\n   // ..\n```\n\nBy calling `console.out()` (or in this case `box.out()`) **you tell** the parent of all boxes **to print** every child box *that's ready*.\n\n**Pro-Tip:** *`out` can take the same arguments as `line` does. So you could simplify the above to: `box.out('Database updated')`.*\n\n#### *\"And what about over? Over.\"*\n\nYou might run into situations where you want to mark a box as printable but don't want to print everything. For example when you're working on multiple child-boxes at once: you have to wait until every child box is done, before you can output the whole thing. That's what `box.over` is for:\n\n```js\nconst box = console2.box('I am a box with children')\nconst child1 = box.box('I am child #1')\nconst child2 = box.box('I am child #2')\n\nasync.each(arr, (data, callback) =\u003e {\n  child1.line('Processing item #1:', data)\n}, () =\u003e child1.over())\n\n// you don't know if i'm faster or slower than the onEnd above!\nsetTimeout(() =\u003e child2.line('Hello friend').over(), 123)\n\n// out .out() to print queued lines\nfunction print(){\n  console2.out('Additional output')\n}\n```\n\n**Pro-Tip:** *`over` can take the same arguments as `line` does. So you could simplify the above to: `box.over('Hello friend')`.*\n\n# Reference\n\nConsole2 not only improves the native console functions (`log`, `info`, `warn`, `error`, `dir`, `time`, `timeEnd`, `trace`) but also provides additional functions.\n\n***\n\n#### ``console2.help()``\nDisplays a [short tutorial with examples](/media/help.png).\n\n***\n\n#### ``console2.box(content, option)``\nCreate a sub box.\n\n***\n\n#### ``console2.line({...*}[, option])``\nAdd a line.\n\n***\n\n#### ``console2.over({...*}[, option])``\nAdds a line and sets the option `{over:true}`\n\n***\n\n#### ``console2.out({...*}[, option])``\nFlush current buffer (use this to actually **see** something).\n\n***\n\n#### ``console2.spacer()``\nFlush current buffer + adds an empty line.\n\n***\n\n#### ``console2.log({...*}[, option])``\nSame as `console.line` but with an additional call to `console.out` to remain compatible to the native `console`.\n\n***\n\n#### ``console2.title({String} line)``\nCreates a title by adding two lines (above \u0026 below) the text.\n\n***\n\n#### ``console2.beep({String} [label])``\nMakes your terminal beep, outputs `beep: label`.\n\n***\n\n#### ``console2.time({String} [label], {Boolean} [reset])``\nUseful stopwatch that shows the elapsed time in a readable format (ms + years, months, days...).\n**When called twice, the time in between the two calls is also measured \u0026 displayed!**\n\n```javascript\n// Prints time since box was initialized\nconsole2.time()\n\n// (1st call) starts a new timer, outputs 'Timer1: start'\nconsole2.time('Timer1')\n\n// (1st call) same as above, no output\nconsole2.time('Timer1', true)\n\n// (2nd call) outputs 'Timer1: Xms'\nconsole2.time('Timer1')\n\n// (2nd call) outputs 'Timer1: Xms - reset', resets the timer\nconsole2.time('Timer1', true)\n```\n***\n\n#### ``console2.trace({String} [label])``\nBeautified `console.trace`.\n\n***\n\n#### ``console2.build(stripLevels=0, useParent=false)``\nReturns a promise with the output of `console.out()` as a string.\n\n***\n\n#### ``console2.options({Object|String|Number} data)``\n\n| Option         | Type          | Default   | Help                                            |\n| -------------- |:------------- | ---------:|:----------------------------------------------- |\n| color          | String        | grey      | Primary color                                   |\n| colorText      | String        | grey      | Text color                                      |\n| border         | Number        | 1         | Vertical border-width: `1` (`│`) or `2` (`║`)  |\n| console        | Object        | `console` | Object to receive the output of console2.out.\u003cbr\u003eNeeds to have the same properties as the `console`. |\n| map            | Array         | `[['...','…']]` | Simple replace for input strings (e.g. `...` to a single char `…`) |\n| isWorker       | Boolean       | `false`   | Act as a [worker](https://nodejs.org/api/cluster.html#cluster_cluster_isworker) |\n| over           | Boolean       | `false`   | Allow output of box when a parent uses `out()`  |\n| disableAutoOut | Boolean       | `false`   | Console2 tries to detect whether to automatically call\u003cbr\u003e`console.out` after new lines have been added.\n| override       | Boolean       | `false`    | Whether to override the native `console`.\u003cbr\u003e\u003csub\u003eCan only be set when first calling the main function.\u003c/sub\u003e |\n\n**Shortcuts**\n\n- `1`, `2` ⇔ sets `{border:Number}`\n- chalk `color` or `command` (see console.col) ⇔ sets `{color:String,colorText::String}`\n\n***\n\n#### ``console2.col({String} input, {...String} color)``\n\nColorizes the `input`, can take multiple colors / commands  ([see module **chalk**](https://github.com/chalk/chalk)).\n\n- Colors: `cyan`, `green`, `yellow`, `red`, `magenta`, `blue`, `white`, `grey`, `black`\n- Backgrounds: `bgCyan`, `bgGreen`, `bgYellow`, `bgRed`, `bgMagenta`, `bgBlue`, `bgWhite`, `bgGrey`, `bgBlack`\n- Commands: `bold` (bright color), `dim` (dark color), `italic` (bad support), `underline` (bad support), `inverse`, `hidden`, `strikethrough` (bad support)\n- Specials: `rainbow`, `zebra`, `code`\n\nUse to colorize a string before adding it:\n\n```javascript\nconsole2.log(\n    console.col('I am a rainbow!', 'rainbow')\n)\n```\n\n***\n\n#### ``console2.strip({String} input)``\n\nRemoves any ansi codes from the `input` string ([see module **chalk**](https://github.com/chalk/chalk)).\n\n***\n\n#### ``console2.pad({String} padSymbol, {Number} length, {Number} [str], {Boolean} [useLeftSide])``\n\n\u003e Note: `pad` will be deprecated, use `String.padStart` or `String.padEnd` instead.\n\u003e \nUtility to generate a pad string when working with aligned texts.\n\n\n```js\nconsole.pad('-', 5)                 // = '-----'\nconsole.pad('.', 7, 'Hello')        // = 'Hello..'\nconsole.pad(' ', 7, 'Hello', true)  // = '  Hello'\n```\n\n## Aliases\nAlias exist to cover features of the native `console` or to provide shortcuts for lazy people like me.\n\n| Shortcut             | ⇔  | Alias                    |\n|:-------------------- | --:|:------------------------ |\n| console **._**       | ⇔ | console **.line**         |\n| console **.info**    | ⇔ | console **.log** (green)  |\n| console **.warn**    | ⇔ | console **.log** (yellow) |\n| console **.error**   | ⇔ | console **.log** (red)    |\n| console **.dir**     | ⇔ | console **.log**          |\n| console **.timeEnd** | ⇔ | console **.time**          |\n| console **.ok** | ⇔ | console **.time('OK').out()**          |\n\n## Overriding the native console\n\nYou can enable overriding of the native `console` by passing `true` into the main function or by using `console2.options({override: true})`.\n\n```\nvar console2 = require('console2')(false) // \"false\" is a shortcut for the option {override:false}\nconsole2.title('Hello World')\n```\n\n## Thanks to\n\n- [async](https://github.com/caolan/async)\n- [chalk](https://github.com/chalk/chalk)\n- [linewrap](https://github.com/AnAppAMonth/linewrap)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Friennevaplus%2Fconsole2","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Friennevaplus%2Fconsole2","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Friennevaplus%2Fconsole2/lists"}