Coder Social home page Coder Social logo

oze4 / chalky Goto Github PK

View Code? Open in Web Editor NEW
12.0 2.0 0.0 103 KB

Like chalk.js, but smaller and with fewer features. Meant for rapid prototyping without worrying about node_modules bloat

License: MIT License

JavaScript 100.00%
chalkjs chalk nodejs console colors log expressjs express node chalky

chalky's Introduction

npm version

npm i chalky / yarn add chalky

chalky

Table of Contents


About

Like chalk with fewer features, smaller in size (905 bytes), and self-contained (zero dependencies). Think of chalky like a 'stripped down', basic version of chalk..

chalky aims to provide a chalk-like experience, but for the most basic of console color features. Simple and small. 'Cheaply' add color to your console without worrying about the size of node_modules.

We're not quite hardened chalk, but we're still chalky ๐Ÿ˜


Demos

Chaining

  • Like chalk, chain methods together to change the foreground color, background color, add formatting (italic, bold, underline, etc..), for unique color/formatting combinations.
const chalky = require('chalky');

console.log(
  chalky.italic.bgBlack.red.bold("Lorem ipsum dolor sit amet")
);
  • Output:

demo

Color priority in chain

  • The last color in the chain is what gets used:
const chalky = require('chalky');

// This line..
const a = chalky.red.green.blue.bgRed.bgBlack.bgYellow("Lorem ipsum dolor sit amet");
// ...is equivalent to this line
const b = chalky.blue.bgYellow("Lorem ipsum dolor sit amet");

console.log(`This:         ${a}`);
console.log(`Should equal: ${b}`);
  • Output:

demo


const chalky = require('chalky');

// This line..
const a = chalky.red.blue("Lorem ipsum dolor sit amet");
// ...is equivalent to this line
const b = chalky.blue("Lorem ipsum dolor sit amet");

console.log(`This:         ${a}`);
console.log(`Should equal: ${b}`);
  • Output:

demo

Rainbow

  • Use chalky.rainbow('Some string') to 'rainbowify' a string
const chalky = require('chalky');

console.log(
  chalky.rainbow("Lorem ipsum dolor sit amet")
);
  • Output:

demo


Properties

  • Foreground Colors:

    • black
    • red
    • green
    • yellow
    • blue
    • magenta
    • cyan
    • white
  • Background Colors:

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

    • bold
    • light
    • italic
    • underline
    • blink
    • inverse
    • hidden

Why?

Two reasons...

I wanted to understand:

  • How chalk was able to use properties with the same name as both a getter and method on the same object
    • For example, you can do chalk.blue('foo'); and chalk.blue.bold('foo'); (.blue is being used as both a method and getter)
  • How chalk was able to chain these properties/methods/getters

While modified, some of the code in this repo may resemble chalk as I followed the same logic.

chalky's People

Contributors

oze4 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.