Skip to content

PrisisForks/node-style-text

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

67 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

node-style-text

Npm Version MIT License Coverage

Chainable util.styleText().

Install

yarn add node-style-text

Usage

import styleText from 'node-style-text'

console.log(styleText.blue.underline('Hello world!'))
console.log(styleText.blue.underline`Hello ${'world'}!`))

Use process.stderr to validate colors.

import {stdout, stderr} from 'node-style-text'

// Validate `process.stderr` if it can be colored instead of `process.stdout`.
console.log(stderr.underline('Hello world!'))

Check options.stream for util.styleText for details.

Motivation

Provide convenience API.

  1. Chainable

    - import {styleText} from 'node:utils'
    + import styleText from 'node-style-text'
    
    console.log(
    -   styleText('blue', 'Hello world!')
    +   styleText.blue('Hello world!')
    )
    
    console.log(
    -   styleText(['blue', 'underline'], 'Hello world!')
    +   styleText.blue.underline('Hello world!')
    )
  2. Support tagged templates

    - import {styleText} from 'node:utils'
    + import styleText from 'node-style-text'
    
    console.log(
    -   styleText(['blue', 'underline'], `Hello ${'world'}!`)
    +   styleText.blue.underline`Hello ${'world'}!`
    )

API

styleText.<format>[.<format>...](string)

Example: styleText.red.bold.underline('Hello, world!');

Available formats: util.inspect.colors

Style

This module also provide an ESLint config to enforce use tagged templates when possible

// ✅
styleText.red(`foo`)

// ❌
styleText.red`foo`

Add this to you eslint.config.js

import eslintConfigNodeStyleText from 'node-style-text/eslint-config'

export default [
  // ... Your other eslint configs
  eslintConfigNodeStyleText,
]

About

Chainable `util.styleText()`.

Resources

License

Code of conduct

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • JavaScript 96.1%
  • TypeScript 3.4%
  • Shell 0.5%