Skip to content

Latest commit

 

History

History
270 lines (190 loc) · 10.4 KB

README.md

File metadata and controls

270 lines (190 loc) · 10.4 KB

← Home | css-in-console

css-in-console

Table of contents

Public Functions

Type Aliases

Namespaces

Interfaces

Public Functions

format

format(message?, ...optionalParams): string

This is extended version of format whith CSS-like styling support. So all format features supported, e. g.:

format('%s:%s', 'foo', 'bar', 'baz');
// Returns: 'foo:bar baz'

In additional you can use Styling console output:

format("%cRed", "color:red");

…supported rules: css_rules.

Parameters

Name Type Description
message? any The text to print.
...optionalParams any[] -

Returns

string


formatWithOptions

formatWithOptions(inspectOptions, format?, ...param): string

This is extended version of formatWithOptions whith CSS-like styling support. So, it is similar to format.

formatWithOptions({ colors: true }, "%cRed", "color:red");

Parameters

Name Type Description
inspectOptions InspectOptions Argument which specifies options that are passed along to inspect.
format? any -
...param any[] -

Returns

string


style

style(...styles): Record<string, string>

This is helper function to predefine CSS-like rules for being used with log/formatWithOptions/format/….

const css= style(".red { color: red; }", ".blue { color: blue; }");
log("%cRed text", css.red);
log("%cBlue text", css.blue);

…there is special style name * which applies to all defined classes:

const css= style("* { font-weight: bold; }", ".red { color: red; }", ".blue { color: blue; }");
log("%cRed and bold text", css.red);
log("%cBlue and bold text", css.blue);

…you can also import css file:

const css= style("@import './file.css'");

Parameters

Name Type
...styles (`.${string}{ @import "${string}" }` | `.${string}{ display: none; }` | `.${string}{ display: list-item; }` | `.${string}{ color: black; }` | `.${string}{ color: red; }` | `.${string}{ color: green; }` | `.${string}{ color: yellow; }` | `.${string}{ color: blue; }` | `.${string}{ color: magenta; }` | `.${string}{ color: cyan; }` | `.${string}{ color: white; }` | `.${string}{ color: gray; }` | `.${string}{ color: lightred; }` | `.${string}{ color: lightgreen; }` | `.${string}{ color: lightyellow; }` | `.${string}{ color: lightblue; }` | `.${string}{ color: lightmagenta; }` | `.${string}{ color: lightcyan; }` | `.${string}{ color: whitesmoke; }` | `.${string}{ background: black; }` | `.${string}{ background: red; }` | `.${string}{ background: green; }` | `.${string}{ background: yellow; }` | `.${string}{ background: blue; }` | `.${string}{ background: magenta; }` | `.${string}{ background: cyan; }` | `.${string}{ background: white; }` | `.${string}{ background: gray; }` | `.${string}{ background: lightred; }` | `.${string}{ background: lightgreen; }` | `.${string}{ background: lightyellow; }` | `.${string}{ background: lightblue; }` | `.${string}{ background: lightmagenta; }` | `.${string}{ background: lightcyan; }` | `.${string}{ background: whitesmoke; }` | `.${string}{ margin-left: ${number}; }` | `.${string}{ margin-right: ${number}; }` | `.${string}{ text-decoration: underline }` | `.${string}{ text-decoration: line-through }` | `.${string}{ list-style-type: ${string} }` | `.${string}{ unset: all; }` | `.${string}{ font-style: italic; }` | `.${string}{ font-weight: bold; }` | `.${string}{ animation: blink; }`)[]

Returns

Record<string, string>

style(...styles): Record<string, string>

You can use it aslo as template function:

const css= style`
	@import "./file.css";
	.red{ color: red; }
`;

Parameters

Name Type
...styles cssTemplate

Returns

Record<string, string>


log

log(message?, ...optionalParams): void

This is extended version of log whith CSS-like styling support. 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()).

log('%s:%s', 'foo', 'bar', 'baz');
log('count: %d', 5);

In additional you can use Styling console output:

log("%cRed", "color:red");

…supported rules: css_rules. Also (see Log):

log.css`*{ color: red; }`

Parameters

Name Type
message? any
...optionalParams any[]

Returns

void


error

error(message?, ...optionalParams): void

This is extended version of error whith CSS-like styling support. 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()).

log('%s:%s', 'foo', 'bar', 'baz');
log('count: %d', 5);

In additional you can use Styling console output:

log("%cRed", "color:red");

…supported rules: css_rules. Also (see Log):

error.css`*{ color: red; }`

Parameters

Name Type
message? any
...optionalParams any[]

Returns

void


css

css(...styles): Record<string, string>

An alias for style. It can be helpful for your editor to detect css syntaxt in "css`…`", see:

const c= css`
	@import "./file.css";
	.red{ color: red; }
`;

Parameters

Name Type
...styles (`.${string}{ @import "${string}" }` | `.${string}{ display: none; }` | `.${string}{ display: list-item; }` | `.${string}{ color: black; }` | `.${string}{ color: red; }` | `.${string}{ color: green; }` | `.${string}{ color: yellow; }` | `.${string}{ color: blue; }` | `.${string}{ color: magenta; }` | `.${string}{ color: cyan; }` | `.${string}{ color: white; }` | `.${string}{ color: gray; }` | `.${string}{ color: lightred; }` | `.${string}{ color: lightgreen; }` | `.${string}{ color: lightyellow; }` | `.${string}{ color: lightblue; }` | `.${string}{ color: lightmagenta; }` | `.${string}{ color: lightcyan; }` | `.${string}{ color: whitesmoke; }` | `.${string}{ background: black; }` | `.${string}{ background: red; }` | `.${string}{ background: green; }` | `.${string}{ background: yellow; }` | `.${string}{ background: blue; }` | `.${string}{ background: magenta; }` | `.${string}{ background: cyan; }` | `.${string}{ background: white; }` | `.${string}{ background: gray; }` | `.${string}{ background: lightred; }` | `.${string}{ background: lightgreen; }` | `.${string}{ background: lightyellow; }` | `.${string}{ background: lightblue; }` | `.${string}{ background: lightmagenta; }` | `.${string}{ background: lightcyan; }` | `.${string}{ background: whitesmoke; }` | `.${string}{ margin-left: ${number}; }` | `.${string}{ margin-right: ${number}; }` | `.${string}{ text-decoration: underline }` | `.${string}{ text-decoration: line-through }` | `.${string}{ list-style-type: ${string} }` | `.${string}{ unset: all; }` | `.${string}{ font-style: italic; }` | `.${string}{ font-weight: bold; }` | `.${string}{ animation: blink; }`)[]

Returns

Record<string, string>

css(...styles): Record<string, string>

An alias for style. It can be helpful for your editor to detect css syntaxt in "css`…`", see:

const c= css`
	@import "./file.css";
	.red{ color: red; }
`;

Parameters

Name Type
...styles cssTemplate

Returns

Record<string, string>

Type Aliases

css_colors

Ƭ css_colors: "black" | "red" | "green" | "yellow" | "blue" | "magenta" | "cyan" | "white" | "gray" | "lightred" | "lightgreen" | "lightyellow" | "lightblue" | "lightmagenta" | "lightcyan" | "whitesmoke"


css_rules

Ƭ css_rules: `@import "${string}"` | "unset: all;" | `display: ${"none" | "list-item"};` | `color: ${css_colors};` | `background: ${css_colors};` | `margin-${"left" | "right"}: ${number};` | "font-style: italic;" | "font-weight: bold;" | `text-decoration: ${"underline" | "line-through"}` | `list-style-type: ${string}` | "animation: blink;"


cssTemplate

Ƭ cssTemplate: [css_text: TemplateStringsArray, css_vars: string[]]

See css_rules