Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
240 changes: 199 additions & 41 deletions src/js/node/console/Console.hx
Original file line number Diff line number Diff line change
Expand Up @@ -23,82 +23,240 @@
package js.node.console;

import js.node.stream.Writable;
import haxe.extern.Rest;
import haxe.extern.EitherType;

/**
For printing to stdout and stderr.
The `Console` class can be used to create a simple logger with configurable output streams
and can be accessed using either `require('console').Console` or `console.Console` (or their destructured counterparts):

Similar to the console object functions provided by most web browsers, here the output is sent to stdout or stderr.

The console functions are synchronous when the destination is a terminal or a file (to avoid lost messages in case of premature exit
and asynchronous when it's a pipe (to avoid blocking for long periods of time).
@see https://nodejs.org/api/console.html#console_class_console
**/
@:jsRequire("console", "Console")
extern class Console {
/**
Create a new `Console` by passing one or two writable stream instances.
`stdout` is a writable stream to print log or info output.
`stderr` is used for warning or error output. If `stderr` isn't passed,
the warning and error output will be sent to the `stdout`.
Creates a new `Console` with one or two writable stream instances. `stdout` is a writable stream to print log or info output.
`stderr` is used for warning or error output. If `stderr` is not provided, `stdout` is used for stderr.

@see https://nodejs.org/api/console.html#console_new_console_stdout_stderr_ignoreerrors
**/
@:overload(function(options:ConsoleOptions):Void {})
function new(stdout:IWritable, ?stderr:IWritable, ?ignoreerrors:Bool):Void;

/**
A simple assertion test that verifies whether `value` is truthy. If it is not, `Assertion` failed is logged.
If provided, the error `message` is formatted using `util.format()` by passing along all message arguments. The output is used as the error message.

@see https://nodejs.org/api/console.html#console_console_assert_value_message
**/
function new(stdout:IWritable, ?stderr:IWritable);
function assert(value:Dynamic, message:Rest<Dynamic>):Void;

/**
Prints to stdout with newline. This function can take multiple arguments in a printf()-like way.
Example: console.log('count: %d', count);
If formatting elements are not found in the first string then `Util.inspect` is used on each argument.
See `Util.format` for more information.
When `stdout` is a TTY, calling `console.clear()` will attempt to clear the TTY. When `stdout` is not a TTY, this method does nothing.

@see https://nodejs.org/api/console.html#console_console_clear
**/
@:overload(function(args:haxe.extern.Rest<Dynamic>):Void {})
function log(data:String, args:haxe.extern.Rest<Dynamic>):Void;
function clear():Void;

/**
Same as `log`.
Maintains an internal counter specific to `label` and outputs to `stdout` the number of times `console.count()` has been called with the given `label`.

@see https://nodejs.org/api/console.html#console_console_count_label
**/
@:overload(function(args:haxe.extern.Rest<Dynamic>):Void {})
function info(data:String, args:haxe.extern.Rest<Dynamic>):Void;
function count(?label:String):Void;

/**
Same as `log` but prints to stderr.
Resets the internal counter specific to `label`.

@see https://nodejs.org/api/console.html#console_console_countreset_label
**/
@:overload(function(args:haxe.extern.Rest<Dynamic>):Void {})
function error(data:String, args:haxe.extern.Rest<Dynamic>):Void;
function countReset(?label:String):Void;

/**
Same as `error`.
The `console.debug()` function is an alias for `console.log()`.

@see https://nodejs.org/api/console.html#console_console_debug_data_args
**/
@:overload(function(args:haxe.extern.Rest<Dynamic>):Void {})
function warn(data:String, args:haxe.extern.Rest<Dynamic>):Void;
function debug(data:Dynamic, args:Rest<Dynamic>):Void;

/**
Uses util.inspect on obj and prints resulting string to stdout.
Uses util.inspect() on `obj` and prints the resulting string to `stdout`. This function bypasses any custom `inspect()` function defined on `obj`.

This function bypasses any custom inspect() function on obj.
An optional options object may be passed that alters certain aspects
of the formatted string.
@see https://nodejs.org/api/console.html#console_console_dir_obj_options
**/
function dir(obj:Dynamic, ?options:Util.InspectOptionsBase):Void;

/**
Mark a time with `label`.
Finish with `timeEnd`
This method calls `console.log()` passing it the arguments received. This method does not produce any XML formatting.

@see https://nodejs.org/api/console.html#console_console_dirxml_data
**/
function dirxml(data:Rest<Dynamic>):Void;

/**
Prints to `stderr` with newline. Multiple arguments can be passed,
with the first used as the primary message and all additional used as substitution values similar to printf(3)
(the arguments are all passed to util.format()).

@see https://nodejs.org/api/console.html#console_console_error_data_args
**/
function error(data:Dynamic, args:Rest<Dynamic>):Void;

/**
If one or more `label`s are provided, those are printed first without the additional indentation.

@see https://nodejs.org/api/console.html#console_console_group_label
**/
function group(label:Rest<Dynamic>):Void;

/**
An alias for console.group().

@see https://nodejs.org/api/console.html#console_console_groupcollapsed
**/
function groupCollapsed():Void;

/**
Decreases indentation of subsequent lines by two spaces.

@see https://nodejs.org/api/console.html#console_console_groupend
**/
function groupEnd():Void;

/**
The `console.info()` function is an alias for console.log().

@see https://nodejs.org/api/console.html#console_console_info_data_args
**/
function info(data:Dynamic, args:Rest<Dynamic>):Void;

/**
Prints to `stdout` with newline. Multiple arguments can be passed,
with the first used as the primary message and all additional used as substitution values similar to printf(3)
(the arguments are all passed to util.format()).

@see https://nodejs.org/api/console.html#console_console_log_data_args
**/
function log(data:Dynamic, args:Rest<Dynamic>):Void;

/**
Try to construct a table with the columns of the properties of `tabularData` (or use `properties`)
and rows of `tabularData` and log it. Falls back to just logging the argument if it can’t be parsed as tabular.

@see https://nodejs.org/api/console.html#console_console_table_tabulardata_properties
**/
function table(tabularData:Dynamic, ?properties:Array<String>):Void;

/**
Starts a timer that can be used to compute the duration of an operation. Timers are identified by a unique `label`.
Use the same `label` when calling console.timeEnd() to stop the timer and output the elapsed time in milliseconds to `stdout`.
Timer durations are accurate to the sub-millisecond.

@see https://nodejs.org/api/console.html#console_console_time_label
**/
function time(?label:String):Void;

/**
Stops a timer that was previously started by calling console.time() and prints the result to `stdout`:

@see https://nodejs.org/api/console.html#console_console_timeend_label
**/
function timeEnd(?label:String):Void;

/**
For a timer that was previously started by calling console.time(), prints the elapsed time and other `data` arguments to `stdout`:

@see https://nodejs.org/api/console.html#console_console_timelog_label_data
**/
function timeLog(?label:String, data:Rest<Dynamic>):Void;

/**
Prints to `stderr` the string `'Trace: '`, followed by the util.format() formatted message and stack trace to the current position in the code.

@see https://nodejs.org/api/console.html#console_console_trace_message_args
**/
function trace(message:Dynamic, args:Rest<Dynamic>):Void;

/**
The `console.warn()` function is an alias for console.error().

@see https://nodejs.org/api/console.html#console_console_warn_data_args
**/
function warn(data:Dynamic, args:Rest<Dynamic>):Void;

/**
This method does not display anything unless used in the inspector. The `console.markTimeline()` method is the deprecated form of console.timeStamp().

@see https://nodejs.org/api/console.html#console_console_marktimeline_label
**/
function markTimeline(?label:String):Void;

/**
This method does not display anything unless used in the inspector.
The `console.profile()` method starts a JavaScript CPU profile with an optional label until console.profileEnd() is called.
The profile is then added to the Profile panel of the inspector.

@see https://nodejs.org/api/console.html#console_console_profile_label
**/
function profile(?label:String):Void;

/**
This method does not display anything unless used in the inspector.
Stops the current JavaScript CPU profiling session if one has been started and prints the report to the Profiles panel of the inspector.
See console.profile() for an example.

@see https://nodejs.org/api/console.html#console_console_profileend_label
**/
function profileEnd(?label:String):Void;

/**
This method does not display anything unless used in the inspector.
The `console.timeStamp()` method adds an event with the label `'label'` to the Timeline panel of the inspector.

@see https://nodejs.org/api/console.html#console_console_timestamp_label
**/
function timeStamp(?label:String):Void;

/**
This method does not display anything unless used in the inspector. The `console.timeline()` method is the deprecated form of console.time().

@see https://nodejs.org/api/console.html#console_console_timeline_label
**/
function timeline(?label:String):Void;

/**
This method does not display anything unless used in the inspector. The `console.timelineEnd()` method is the deprecated form of console.timeEnd().

@see https://nodejs.org/api/console.html#console_console_timelineend_label
**/
function timelineEnd(?label:String):Void;
}

typedef ConsoleOptions = {
/**
`stdout` is a writable stream to print log or info output.
**/
var stdout:IWritable;

/**
`stderr` is used for warning or error output. If stderr is not provided, stdout is used for stderr.
**/
function time(label:String):Void;
@optional var stderr:IWritable;

/**
Finish timer marked with `label`, record output.
Ignore errors when writing to the underlying streams. Default: `true`.
**/
function timeEnd(label:String):Void;
@optional var ignoreErrors:Bool;

/**
Print to stderr 'Trace :', followed by the formatted message and stack trace to the current position.
Set color support for this `Console` instance. Setting to `true` enables coloring while inspecting values,
setting to `'auto'` will make color support depend on the value of the `isTTY` property and the value returned by `getColorDepth()` on the respective stream.
This option can not be used, if `inspectOptions.colors` is set as well. Default: `'auto'`.
**/
@:overload(function(args:haxe.extern.Rest<Dynamic>):Void {})
function trace(message:String, args:haxe.extern.Rest<Dynamic>):Void;
@optional var colorMode:EitherType<Bool, String>;

/**
Similar to `Assert.ok`, but the error message is formatted as `Util.format(message...)`.
Specifies options that are passed along to util.inspect().
**/
@:overload(function(value:Bool, args:haxe.extern.Rest<Dynamic>):Void {})
@:overload(function(value:Bool, message:String, args:haxe.extern.Rest<Dynamic>):Void {})
function assert(value:Bool):Void;
@optional var inspectOptions:Util.InspectOptions;
}