From cc43c8fb54c872fbce2a795d089aa111eccdfb89 Mon Sep 17 00:00:00 2001 From: James M Snell Date: Wed, 26 Apr 2017 12:42:18 -0700 Subject: [PATCH] console: add console.count() and console.clear() MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Both are simple utility functions defined by the WHATWG console spec (https://console.spec.whatwg.org/). PR-URL: https://github.com/nodejs/node/pull/12678 Ref: https://github.com/nodejs/node/issues/12675 Reviewed-By: Anna Henningsen Reviewed-By: Benjamin Gruenbaum Reviewed-By: Colin Ihrig Reviewed-By: Luigi Pinca Reviewed-By: Daijiro Wachi Reviewed-By: Timothy Gu Reviewed-By: Tobias Nießen --- doc/api/console.md | 70 +++++++++++++++++++++++++++++ lib/console.js | 39 ++++++++++++++++ test/parallel/test-console-clear.js | 22 +++++++++ test/parallel/test-console-count.js | 63 ++++++++++++++++++++++++++ 4 files changed, 194 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])