Sitelet https://github.com/nodejs/node/issues/52035
Skip to content

util.styleText(): Combining multiple styles in a single string? #52035

Description

@rauschma

What is the problem this feature will solve?

Currently, using multiple styles with util.styleText() is slightly verbose:

console.log(
  util.styleText('bold', util.styleText('red', 'Bold and red!')),
); 

What is the feature you are proposing to solve the problem?

Maybe multiple styles per format string could be supported – e.g.:

console.log(
  util.styleText('bold+red', 'Bold and red!'),
); 

Downside: It would make autocomplete in IDEs less straightforward if not impossible.

Activity

  1. marco-ippolito commented on Mar 11, 2024

    @marco-ippolito
    Member

    what about passing an array?

    util.styleText(['bold', 'red'], 'Bold and red!')
  2. rauschma commented on Mar 11, 2024

    @rauschma
    Author

    Good idea! Same pros and autocomplete works.

  3. added
    utilIssues and PRs related to the built-in util module.
    on Mar 11, 2024
  4. ai commented on Apr 3, 2024

    @ai

    Seems like we need also to add types to @types/node

  5. steffen-4s1 commented on Apr 4, 2024

    @steffen-4s1

    Seems like we need also to add types to @types/node

    Work is in progress -> #69212

  6. moved this from Awaiting Triage to Done in Node.js feature requestson Jun 27, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    feature requestIssues requesting new Node.js features.utilIssues and PRs related to the built-in util module.

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions