1
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2024-11-26 16:09:27 -05:00

docs(std): add some missing JSDoc (#7765)

Refs #7487
This commit is contained in:
Fukuda Naoto 2020-11-06 11:33:59 +09:00 committed by GitHub
parent bfa00bef22
commit fd9b6e03af
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 70 additions and 0 deletions

View file

@ -29,6 +29,7 @@ interface Rgb {
let enabled = !noColor; let enabled = !noColor;
/** Set changing text color to enabled or disabled */
export function setColorEnabled(value: boolean): void { export function setColorEnabled(value: boolean): void {
if (noColor) { if (noColor) {
return; return;
@ -37,6 +38,7 @@ export function setColorEnabled(value: boolean): void {
enabled = value; enabled = value;
} }
/** Get wheather text color change is enabled or disabled. */
export function getColorEnabled(): boolean { export function getColorEnabled(): boolean {
return enabled; return enabled;
} }
@ -55,166 +57,207 @@ function run(str: string, code: Code): string {
: str; : str;
} }
/** Reset the text modified */
export function reset(str: string): string { export function reset(str: string): string {
return run(str, code([0], 0)); return run(str, code([0], 0));
} }
/** Make the text bold. */
export function bold(str: string): string { export function bold(str: string): string {
return run(str, code([1], 22)); return run(str, code([1], 22));
} }
/** The text emits only a small amount of light. */
export function dim(str: string): string { export function dim(str: string): string {
return run(str, code([2], 22)); return run(str, code([2], 22));
} }
/** Make the text italic. */
export function italic(str: string): string { export function italic(str: string): string {
return run(str, code([3], 23)); return run(str, code([3], 23));
} }
/** Make the text underline. */
export function underline(str: string): string { export function underline(str: string): string {
return run(str, code([4], 24)); return run(str, code([4], 24));
} }
/** Invert background color and text color. */
export function inverse(str: string): string { export function inverse(str: string): string {
return run(str, code([7], 27)); return run(str, code([7], 27));
} }
/** Make the text hidden. */
export function hidden(str: string): string { export function hidden(str: string): string {
return run(str, code([8], 28)); return run(str, code([8], 28));
} }
/** Put horizontal line throught the center of the text. */
export function strikethrough(str: string): string { export function strikethrough(str: string): string {
return run(str, code([9], 29)); return run(str, code([9], 29));
} }
/** Set text color to black. */
export function black(str: string): string { export function black(str: string): string {
return run(str, code([30], 39)); return run(str, code([30], 39));
} }
/** Set text color to red. */
export function red(str: string): string { export function red(str: string): string {
return run(str, code([31], 39)); return run(str, code([31], 39));
} }
/** Set text color to green. */
export function green(str: string): string { export function green(str: string): string {
return run(str, code([32], 39)); return run(str, code([32], 39));
} }
/** Set text color to yellow. */
export function yellow(str: string): string { export function yellow(str: string): string {
return run(str, code([33], 39)); return run(str, code([33], 39));
} }
/** Set text color to blue. */
export function blue(str: string): string { export function blue(str: string): string {
return run(str, code([34], 39)); return run(str, code([34], 39));
} }
/** Set text color to magenta. */
export function magenta(str: string): string { export function magenta(str: string): string {
return run(str, code([35], 39)); return run(str, code([35], 39));
} }
/** Set text color to cyan. */
export function cyan(str: string): string { export function cyan(str: string): string {
return run(str, code([36], 39)); return run(str, code([36], 39));
} }
/** Set text color to white. */
export function white(str: string): string { export function white(str: string): string {
return run(str, code([37], 39)); return run(str, code([37], 39));
} }
/** Set text color to gray. */
export function gray(str: string): string { export function gray(str: string): string {
return brightBlack(str); return brightBlack(str);
} }
/** Set text color to bright black. */
export function brightBlack(str: string): string { export function brightBlack(str: string): string {
return run(str, code([90], 39)); return run(str, code([90], 39));
} }
/** Set text color to bright red. */
export function brightRed(str: string): string { export function brightRed(str: string): string {
return run(str, code([91], 39)); return run(str, code([91], 39));
} }
/** Set text color to bright green. */
export function brightGreen(str: string): string { export function brightGreen(str: string): string {
return run(str, code([92], 39)); return run(str, code([92], 39));
} }
/** Set text color to bright yellow. */
export function brightYellow(str: string): string { export function brightYellow(str: string): string {
return run(str, code([93], 39)); return run(str, code([93], 39));
} }
/** Set text color to bright blue. */
export function brightBlue(str: string): string { export function brightBlue(str: string): string {
return run(str, code([94], 39)); return run(str, code([94], 39));
} }
/** Set text color to bright magenta. */
export function brightMagenta(str: string): string { export function brightMagenta(str: string): string {
return run(str, code([95], 39)); return run(str, code([95], 39));
} }
/** Set text color to bright cyan. */
export function brightCyan(str: string): string { export function brightCyan(str: string): string {
return run(str, code([96], 39)); return run(str, code([96], 39));
} }
/** Set text color to bright white. */
export function brightWhite(str: string): string { export function brightWhite(str: string): string {
return run(str, code([97], 39)); return run(str, code([97], 39));
} }
/** Set background color to black. */
export function bgBlack(str: string): string { export function bgBlack(str: string): string {
return run(str, code([40], 49)); return run(str, code([40], 49));
} }
/** Set background color to red. */
export function bgRed(str: string): string { export function bgRed(str: string): string {
return run(str, code([41], 49)); return run(str, code([41], 49));
} }
/** Set background color to green. */
export function bgGreen(str: string): string { export function bgGreen(str: string): string {
return run(str, code([42], 49)); return run(str, code([42], 49));
} }
/** Set background color to yellow. */
export function bgYellow(str: string): string { export function bgYellow(str: string): string {
return run(str, code([43], 49)); return run(str, code([43], 49));
} }
/** Set background color to blue. */
export function bgBlue(str: string): string { export function bgBlue(str: string): string {
return run(str, code([44], 49)); return run(str, code([44], 49));
} }
/** Set background color to magenta. */
export function bgMagenta(str: string): string { export function bgMagenta(str: string): string {
return run(str, code([45], 49)); return run(str, code([45], 49));
} }
/** Set background color to cyan. */
export function bgCyan(str: string): string { export function bgCyan(str: string): string {
return run(str, code([46], 49)); return run(str, code([46], 49));
} }
/** Set background color to white. */
export function bgWhite(str: string): string { export function bgWhite(str: string): string {
return run(str, code([47], 49)); return run(str, code([47], 49));
} }
/** Set background color to bright black. */
export function bgBrightBlack(str: string): string { export function bgBrightBlack(str: string): string {
return run(str, code([100], 49)); return run(str, code([100], 49));
} }
/** Set background color to bright red. */
export function bgBrightRed(str: string): string { export function bgBrightRed(str: string): string {
return run(str, code([101], 49)); return run(str, code([101], 49));
} }
/** Set background color to bright green. */
export function bgBrightGreen(str: string): string { export function bgBrightGreen(str: string): string {
return run(str, code([102], 49)); return run(str, code([102], 49));
} }
/** Set background color to bright yellow. */
export function bgBrightYellow(str: string): string { export function bgBrightYellow(str: string): string {
return run(str, code([103], 49)); return run(str, code([103], 49));
} }
/** Set background color to bright blue. */
export function bgBrightBlue(str: string): string { export function bgBrightBlue(str: string): string {
return run(str, code([104], 49)); return run(str, code([104], 49));
} }
/** Set background color to bright magenta. */
export function bgBrightMagenta(str: string): string { export function bgBrightMagenta(str: string): string {
return run(str, code([105], 49)); return run(str, code([105], 49));
} }
/** Set background color to bright cyan. */
export function bgBrightCyan(str: string): string { export function bgBrightCyan(str: string): string {
return run(str, code([106], 49)); return run(str, code([106], 49));
} }
/** Set background color to bright white. */
export function bgBrightWhite(str: string): string { export function bgBrightWhite(str: string): string {
return run(str, code([107], 49)); return run(str, code([107], 49));
} }
@ -314,6 +357,7 @@ const ANSI_PATTERN = new RegExp(
"g", "g",
); );
/** Remove ANSI escape codes from the string. */
export function stripColor(string: string): string { export function stripColor(string: string): string {
return string.replace(ANSI_PATTERN, ""); return string.replace(ANSI_PATTERN, "");
} }

View file

@ -661,11 +661,19 @@ class Printf {
} }
} }
/**
* Converts and format a variable number of `args` as is specified by `format`.
* `sprintf` returns the formatted string.
*/
export function sprintf(format: string, ...args: unknown[]): string { export function sprintf(format: string, ...args: unknown[]): string {
const printf = new Printf(format, ...args); const printf = new Printf(format, ...args);
return printf.doPrintf(); return printf.doPrintf();
} }
/**
* Converts and format a variable number of `args` as is specified by `format`.
* `printf` writes the formatted string to standard output.
*/
export function printf(format: string, ...args: unknown[]): void { export function printf(format: string, ...args: unknown[]): void {
const s = sprintf(format, ...args); const s = sprintf(format, ...args);
Deno.stdout.writeSync(new TextEncoder().encode(s)); Deno.stdout.writeSync(new TextEncoder().encode(s));

View file

@ -1,5 +1,6 @@
// Copyright 2018-2020 the Deno authors. All rights reserved. MIT license. // Copyright 2018-2020 the Deno authors. All rights reserved. MIT license.
/** Create a `Writer` from a `WritablseStreamDefaultReader`. */
export function fromStreamWriter( export function fromStreamWriter(
streamWriter: WritableStreamDefaultWriter<Uint8Array>, streamWriter: WritableStreamDefaultWriter<Uint8Array>,
): Deno.Writer { ): Deno.Writer {
@ -12,6 +13,7 @@ export function fromStreamWriter(
}; };
} }
/** Create a `Reader` from a `ReadableSteramDefaultReader`. */
export function fromStreamReader( export function fromStreamReader(
streamReader: ReadableStreamDefaultReader<Uint8Array>, streamReader: ReadableStreamDefaultReader<Uint8Array>,
): Deno.Reader { ): Deno.Reader {

View file

@ -57,6 +57,7 @@ export const handlers = {
RotatingFileHandler, RotatingFileHandler,
}; };
/** Get a logger instance. If not specified `name`, get the default logger. */
export function getLogger(name?: string): Logger { export function getLogger(name?: string): Logger {
if (!name) { if (!name) {
const d = state.loggers.get("default"); const d = state.loggers.get("default");
@ -75,6 +76,7 @@ export function getLogger(name?: string): Logger {
return result; return result;
} }
/** Log with debug level, using default logger. */
export function debug<T>(msg: () => T, ...args: unknown[]): T | undefined; export function debug<T>(msg: () => T, ...args: unknown[]): T | undefined;
export function debug<T>( export function debug<T>(
msg: T extends GenericFunction ? never : T, msg: T extends GenericFunction ? never : T,
@ -91,6 +93,7 @@ export function debug<T>(
return getLogger("default").debug(msg, ...args); return getLogger("default").debug(msg, ...args);
} }
/** Log with info level, using default logger. */
export function info<T>(msg: () => T, ...args: unknown[]): T | undefined; export function info<T>(msg: () => T, ...args: unknown[]): T | undefined;
export function info<T>( export function info<T>(
msg: T extends GenericFunction ? never : T, msg: T extends GenericFunction ? never : T,
@ -107,6 +110,7 @@ export function info<T>(
return getLogger("default").info(msg, ...args); return getLogger("default").info(msg, ...args);
} }
/** Log with warning level, using default logger. */
export function warning<T>(msg: () => T, ...args: unknown[]): T | undefined; export function warning<T>(msg: () => T, ...args: unknown[]): T | undefined;
export function warning<T>( export function warning<T>(
msg: T extends GenericFunction ? never : T, msg: T extends GenericFunction ? never : T,
@ -123,6 +127,7 @@ export function warning<T>(
return getLogger("default").warning(msg, ...args); return getLogger("default").warning(msg, ...args);
} }
/** Log with error level, using default logger. */
export function error<T>(msg: () => T, ...args: unknown[]): T | undefined; export function error<T>(msg: () => T, ...args: unknown[]): T | undefined;
export function error<T>( export function error<T>(
msg: T extends GenericFunction ? never : T, msg: T extends GenericFunction ? never : T,
@ -139,6 +144,7 @@ export function error<T>(
return getLogger("default").error(msg, ...args); return getLogger("default").error(msg, ...args);
} }
/** Log with critical level, using default logger. */
export function critical<T>(msg: () => T, ...args: unknown[]): T | undefined; export function critical<T>(msg: () => T, ...args: unknown[]): T | undefined;
export function critical<T>( export function critical<T>(
msg: T extends GenericFunction ? never : T, msg: T extends GenericFunction ? never : T,
@ -155,6 +161,7 @@ export function critical<T>(
return getLogger("default").critical(msg, ...args); return getLogger("default").critical(msg, ...args);
} }
/** Setup logger config. */
export async function setup(config: LogConfig): Promise<void> { export async function setup(config: LogConfig): Promise<void> {
state.config = { state.config = {
handlers: { ...DEFAULT_CONFIG.handlers, ...config.handlers }, handlers: { ...DEFAULT_CONFIG.handlers, ...config.handlers },

View file

@ -16,6 +16,7 @@ export const sep = "/";
export const delimiter = ":"; export const delimiter = ":";
// path.resolve([from ...], to) // path.resolve([from ...], to)
/** resolves `pathSegments` into an absolute path. */
export function resolve(...pathSegments: string[]): string { export function resolve(...pathSegments: string[]): string {
let resolvedPath = ""; let resolvedPath = "";
let resolvedAbsolute = false; let resolvedAbsolute = false;
@ -60,6 +61,7 @@ export function resolve(...pathSegments: string[]): string {
else return "."; else return ".";
} }
/** Notmalize the `path`, resolving `'..'` and `'.'` segments. */
export function normalize(path: string): string { export function normalize(path: string): string {
assertPath(path); assertPath(path);
@ -84,6 +86,7 @@ export function isAbsolute(path: string): boolean {
return path.length > 0 && path.charCodeAt(0) === CHAR_FORWARD_SLASH; return path.length > 0 && path.charCodeAt(0) === CHAR_FORWARD_SLASH;
} }
/** Join all given a sequence of `paths`,then normalizes the resulting path. */
export function join(...paths: string[]): string { export function join(...paths: string[]): string {
if (paths.length === 0) return "."; if (paths.length === 0) return ".";
let joined: string | undefined; let joined: string | undefined;
@ -99,6 +102,7 @@ export function join(...paths: string[]): string {
return normalize(joined); return normalize(joined);
} }
/** Return the relative path from `from` to `to` based on current working directory. */
export function relative(from: string, to: string): string { export function relative(from: string, to: string): string {
assertPath(from); assertPath(from);
assertPath(to); assertPath(to);
@ -186,6 +190,7 @@ export function toNamespacedPath(path: string): string {
return path; return path;
} }
/** Return the directory name of a `path`. */
export function dirname(path: string): string { export function dirname(path: string): string {
assertPath(path); assertPath(path);
if (path.length === 0) return "."; if (path.length === 0) return ".";
@ -209,6 +214,7 @@ export function dirname(path: string): string {
return path.slice(0, end); return path.slice(0, end);
} }
/** Return the last portion of a `path`. Trailing directory separators are ignored. */
export function basename(path: string, ext = ""): string { export function basename(path: string, ext = ""): string {
if (ext !== undefined && typeof ext !== "string") { if (ext !== undefined && typeof ext !== "string") {
throw new TypeError('"ext" argument must be a string'); throw new TypeError('"ext" argument must be a string');
@ -283,6 +289,7 @@ export function basename(path: string, ext = ""): string {
} }
} }
/** Return the extention of the `path`. */
export function extname(path: string): string { export function extname(path: string): string {
assertPath(path); assertPath(path);
let startDot = -1; let startDot = -1;
@ -333,6 +340,7 @@ export function extname(path: string): string {
return path.slice(startDot, end); return path.slice(startDot, end);
} }
/** Generate a path from `FormatInputPathObject` object. */
export function format(pathObject: FormatInputPathObject): string { export function format(pathObject: FormatInputPathObject): string {
if (pathObject === null || typeof pathObject !== "object") { if (pathObject === null || typeof pathObject !== "object") {
throw new TypeError( throw new TypeError(
@ -342,6 +350,7 @@ export function format(pathObject: FormatInputPathObject): string {
return _format("/", pathObject); return _format("/", pathObject);
} }
/** Return a `ParsedPath` object of the `path`. */
export function parse(path: string): ParsedPath { export function parse(path: string): ParsedPath {
assertPath(path); assertPath(path);