Socket
Socket
Sign inDemoInstall

colorts

Package Overview
Dependencies
0
Maintainers
1
Versions
9
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    colorts

Colors in node Js console


Version published
Weekly downloads
1.2K
decreased by-4.39%
Maintainers
1
Install size
17.7 kB
Created
Weekly downloads
 

Readme

Source

Colors.ts Build Status

Get colors and style in your node.js console

Installation

npm install colorts

colors and styles!

text colors

  • black
  • red
  • green
  • yellow
  • blue
  • magenta
  • cyan
  • white
  • gray
  • grey

background colors

  • bgBlack
  • bgRed
  • bgGreen
  • bgYellow
  • bgBlue
  • bgMagenta
  • bgCyan
  • bgWhite

styles

  • reset
  • bold
  • dim
  • italic
  • underline
  • inverse
  • hidden
  • strikethrough

Usage methods

1. TypeScript
i. Normal String extension.
import 'colorts/lib/string';

console.log('hello'.green);                       // outputs green text
console.log('i like cake and pies'.underline.red) // outputs red underlined text
console.log('inverse the color'.inverse);         // inverses the color

ii. Direct color method
import color from 'colorts';
import {echo} from 'colorts';

console.log(colors('hello').green + "");                           // outputs green text
console.log(colors('i like cake and pies').red.underline.toString) // outputs red underlined text
echo(colors('inverse the color').inverse);                         // you can use echo to console.log safe colorts

2. JavaScript
i. Normal String extension.
require('colorts/lib/string');

console.log('hello'.green);                       // outputs green text
console.log('i like cake and pies'.underline.red) // outputs red underlined text
console.log('inverse the color'.inverse);         // inverses the color

ii. Direct color method
let color = require('colorts');
let echo = require('colorts').echo;

console.log(colors('hello').green + "");                           // outputs green text
console.log(colors('i like cake and pies').red.underline.toString) // outputs red underlined text
echo(colors('inverse the color').inverse);                         // you can use echo to console.log safe colorts

I prefer the first way. Some people seem to be afraid of extending String.prototype and prefer the second way.

If you are writing good code you will never have an issue with the first approach. If you really don't want to touch String.prototype, the second usage will not touch String native object.

Disabling Colors

To disable colors you can pass the following arguments in the command line to your application:

node myapp.js --no-color

Bonus String Letter case Methods

  • capitalize
    "james is a nice guy.".capitalize // James is nice guy.
    " no one home.".capitalize       //  No one home.
    "typescript".capitalize         // Typescript
    "1st january 2018".capitalize  // 1st january 2018
  • titleCase
    "james is a nice guy.".titleCase // James Is Nice Guy.
    " no one home.".titleCase       //  No One Home.
    "tYpe scrIpt".titleCase        // Type Script
    "1st january".titleCase       // 1st January 2018
  • camelCase
    "james is a nice guy.".camelCase // jamesIsANiceGuy.
    " no one home.".camelCase       //  nOneHome.
    "type script".camelCase        // typeScript
  • upperCamelCase
    "james is a nice guy.".upperCamelCase // JamesIsANiceGuy.
    " no one home.".upperCamelCase       //  NOneHome.
    "type script".upperCamelCase        // TypeScript
  • lowerCamelCase
    "james is a nice guy.".lowerCamelCase // jamesIsANiceGuy.
    " no one home.".lowerCamelCase       //  nOneHome.
    "type script".lowerCamelCase        // typeScript
  • snakeCase
    "james is a nice guy.".snakeCase // james_is_nice_guy.
    " no one home.".snakeCase //  no_one_home.
    "super type script".snakeCase  // super_type_script
  • kebabCase
    "James is a nice guy.".kebabCase // james-is-nice-guy.
    " no one home.".kebabCase //  no-one-home.
    "super type script".kebabCase  // super-type-script
  • studlyCaps
    "james is a nice guy.".studlyCaps // JaMeSiSnIcEgUy.
    " no one home.".studlyCaps //  NoOnEhOmE.
    "super type script".studlyCaps  // SuPeRtYpEsCrIpT

Keywords

FAQs

Last updated on 08 Nov 2017

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc