From bd9e8f107a3fc06f804995fc22553cab0366d27a Mon Sep 17 00:00:00 2001 From: James M Snell Date: Wed, 26 Apr 2017 12:42:18 -0700 Subject: [PATCH 1/2] console: add console.count() and console.clear() Both are simple utility functions defined by the WHATWG console spec (https://console.spec.whatwg.org/). --- doc/api/console.md | 70 +++++++++++++++++++++++++++++ lib/console.js | 39 ++++++++++++++++ test/parallel/test-console-clear.js | 22 +++++++++ test/parallel/test-console-count.js | 60 +++++++++++++++++++++++++ 4 files changed, 191 insertions(+) create mode 100644 test/parallel/test-console-clear.js create mode 100644 test/parallel/test-console-count.js diff --git a/doc/api/console.md b/doc/api/console.md index 4939ed77bef1b8..10f9eba540e6c1 100644 --- a/doc/api/console.md +++ b/doc/api/console.md @@ -167,6 +167,76 @@ console.assert(false, 'this message will print, but no error thrown'); console.log('this will also print'); ``` +### console.clear() + + +When `stdout` is a TTY, calling `console.clear()` will attempt to clear the +TTY. When `stdout` is not a TTY, this method does nothing. + +*Note*: The specific operation of `console.clear()` can vary across operating +systems and terminal types. For most Linux operating systems, `console.clear()` +operates similarly to the `clear` shell command. On Windows, `console.clear()` +will clear only the output in the current terminal viewport for the Node.js +binary. + +### console.count([label]) + + +* `label` {string} The display label for the counter. Defaults to `'default'`. + +Maintains an internal counter specific to `label` and outputs to `stdout` the +number of times `console.count()` has been called with the given `label`. + + +```js +> console.count() +default: 1 +undefined +> console.count('default') +default: 2 +undefined +> console.count('abc') +abc: 1 +undefined +> console.count('xyz') +xyz: 1 +undefined +> console.count('abc') +abc: 2 +undefined +> console.count() +default: 3 +undefined +> +``` + +### console.countReset([label = 'default']) + + +* `label` {string} The display label for the counter. Defaults to `'default'`. + +Resets the internal counter specific to `label`. + + +```js +> console.count('abc'); +abc: 1 +undefined +> console.countReset('abc'); +undefined +> console.count('abc'); +abc: 1 +undefined +> +``` + + ### console.dir(obj[, options])