温馨提示:本站仅提供公开网络链接索引服务,不存储、不篡改任何第三方内容,所有内容版权归原作者所有
AI智能索引来源:http://www.bun.com/reference/node/util/styleText
点击访问原文链接

Node util.styleText function | API Reference | Bun

Node util.styleText function | API Reference | BunBuildDocsReferenceGuidesBlogDiscord/node:util/styleTextFstyleText

Search the reference...

/

BuildDocsReferenceGuidesBlogDiscord/node:util/styleTextFstyleText

function

util.styleTextfunction styleText(format: InspectColor | readonly InspectColor[],text: string,options?: StyleTextOptions): string;

This function returns a formatted text considering the format passed for printing in a terminal. It is aware of the terminal's capabilities and acts according to the configuration set via NO_COLOR, NODE_DISABLE_COLORS and FORCE_COLOR environment variables.

import { styleText } from 'node:util';
import { stderr } from 'node:process';

const successMessage = styleText('green', 'Success!');
console.log(successMessage);

const errorMessage = styleText(
'red',
'Error! Error!',
// Validate if process.stderr has TTY
{ stream: stderr },
);
console.error(errorMessage);

util.inspect.colors also provides text formats such as italic, and underline and you can combine both:

console.log(
util.styleText(['underline', 'italic'], 'My italic underlined message'),
);

When passing an array of formats, the order of the format applied is left to right so the following style might overwrite the previous one.

console.log(
util.styleText(['red', 'green'], 'text'), // green
);

The special format value none applies no additional styling to the text.

The full list of formats can be found in modifiers.

@param format

A text format or an Array of text formats defined in util.inspect.colors.

@param text

The text to to be formatted.

Referenced typestype InspectColor = InspectColorModifier | InspectColorForeground | InspectColorBackgroundinterface StyleTextOptionsstream?: WritableStream

A stream that will be validated if it can be colored.

validateStream?: boolean

When true, stream is checked to see if it can handle colors.

Resources

ReferenceDocsGuidesDiscordMerch StoreGitHubBlog 

Toolkit

RuntimePackage managerTest runnerBundlerPackage runner

Project

Bun 1.0Bun 1.1Bun 1.2Bun 1.3RoadmapContributingLicense

Baked with ❤️ in San Francisco

We're hiring →

Node util.styleText function | API Reference | Bun,AI智能索引,全网链接索引,智能导航,网页索引

    API documentation for function node:util.styleText | Bun