• This repository has been archived on 22/Nov/2021
  • Stars
    star
    870
  • Rank 50,571 (Top 2 %)
  • Language
    JavaScript
  • License
    MIT License
  • Created over 2 years ago
  • Updated over 2 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Use picocolors instead. It is 3 times smaller and 50% faster.

Deprecated

DEPRECATED: Use picocolors instead. It is 3 times smaller and 50% faster.

The space in node_modules including sub-dependencies:

- nanocolors   16 kB
+ picocolors    7 kB

Library loading time:

- nanocolors     0.885 ms
+ picocolors     0.470 ms

Benchmark for complex use cases:

- nanocolors     1,088,193 ops/sec
+ picocolors     1,772,265 ops/sec

Old docs

A tiny and fast Node.js library to ANSI colors to terminal output.

import { green, bold } from 'nanocolors'

console.log(
  green(`Task ${bold('1')} was finished`)
)

Started as a fork of @jorgebucaran’s colorette with hacks from @lukeed’s kleur. See changes between Nano Colors and colorette.

Nano Colors output

Sponsored by Evil Martians

Replacing chalk

  1. Replace import and use named exports:

    - import chalk from 'chalk'
    + import { red, bold } from 'nanocolors'
  2. Unprefix calls:

    - chalk.red(text)
    + red(text)
  3. Replace chains to nested calls:

    - chalk.red.bold(text)
    + red(bold(text))
  4. If you used template tag, then use the nanocolors-template:

    - import chalk from 'chalk'
    + import { colorize } from 'nanocolors-template'
    
    - chalk.yellow.bold`yellow {red ${"text"}}`
    + colorize`{yellow.bold yellow {red ${"text"}}}`

Above changes can be applied automatically using codemod:

npx jscodeshift FILES -t https://gist.githubusercontent.com/gavrix/ff051941ad9a19c8ea3224f38c30bc9a/raw/09d81e93f880ecbc8f52dcf7819816c81e2ba340/chalk_nanocolors_transform.js

API

Individual Colors

Nano Colors exports functions:

Colors Background Colors Modifiers
black bgBlack dim
red bgRed bold
green bgGreen hidden
yellow bgYellow italic
blue bgBlue underline
magenta bgMagenta strikethrough
cyan bgCyan reset
white bgWhite
gray

Functions are not chainable. You need to wrap it inside each other:

import { black, bgYellow } from 'nanocolors'

console.log(bgYellow(black(' WARN ')))

Functions will use colors only if Nano Colors auto-detect that current environment supports colors.

You can get support level in isColorSupported:

import { isColorSupported } from 'nanocolors'

if (isColorSupported) {
  console.log('With colors')
}

Conditional Support

You can manually switch colors on/off and override color support auto-detection:

import { createColors } from 'nanocolors'

const { red } = createColors(options.enableColors)

On undefined argument, createColors will use value from color support auto-detection.

More Repositories

1

nanoid

A tiny (124 bytes), secure, URL-friendly, unique string ID generator for JavaScript
JavaScript
23,467
star
2

easings.net

Easing Functions Cheat Sheet
CSS
7,459
star
3

size-limit

Calculate the real cost to run your JS app or lib to keep good performance. Show error in pull request if the cost exceeds the limit.
JavaScript
6,345
star
4

visibilityjs

Wrapper for the Page Visibility API
JavaScript
1,817
star
5

nanoevents

Simple and tiny (107 bytes) event emitter library for JavaScript
TypeScript
1,420
star
6

autoprefixer-rails

Autoprefixer for Ruby and Ruby on Rails
Ruby
1,214
star
7

audio-recorder-polyfill

MediaRecorder polyfill to record audio in Edge and Safari
JavaScript
572
star
8

webp-in-css

PostCSS plugin and tiny JS script (131 bytes) to use WebP in CSS background
JavaScript
347
star
9

offscreen-canvas

Polyfill for OffscreenCanvas to move Three.js/WebGL/2D canvas to Web Worker
JavaScript
327
star
10

convert-layout

JS library to convert text from one keyboard layout to other
JavaScript
247
star
11

ssdeploy

Netlify replacement to deploy simple websites with better flexibility, speed and without vendor lock-in
JavaScript
193
star
12

nanodelay

A tiny (37 bytes) Promise wrapper around setTimeout
JavaScript
186
star
13

dual-publish

Publish JS project as dual ES modules and CommonJS package to npm
JavaScript
185
star
14

environment

My home config, scripts and installation process
Shell
179
star
15

autoprefixer-core

autoprefixer-core was depreacted, use autoprefixer
JavaScript
136
star
16

nanospy

Spy and mock methods in tests with great TypeScript support
TypeScript
135
star
17

check-dts

Unit tests for TypeScript definitions in your JS open source library
JavaScript
135
star
18

transition-events

jQuery plugin to set listeners to CSS Transition animation end or specific part
JavaScript
133
star
19

evil-blocks

Tiny framework for web pages to split your app to separated blocks
JavaScript
127
star
20

rails-sass-images

Sass functions and mixins to inline images and get images size
Ruby
115
star
21

compass.js

Compass.js allow you to get compass heading in JavaScript by PhoneGap, iOS API or GPS hack.
CoffeeScript
112
star
22

evil-front

Helpers for frontend from Evil Martians
Ruby
101
star
23

rake-completion

Bash completion support for Rake
Shell
63
star
24

yaspeller-ci

Fast spelling check for Travis CI
JavaScript
61
star
25

jquery-cdn

Best way to use latest jQuery in Ruby app
Ruby
59
star
26

sitnik.ru

My homepage content and scripts
JavaScript
57
star
27

pages.js

CoffeeScript
44
star
28

fotoramajs

Fotorama for Ruby on Rails
Ruby
44
star
29

keyux

JS library to improve keyboard UI of web apps
TypeScript
41
star
30

about-postcss

Keynotes about PostCSS
Ruby
29
star
31

autohide-battery

GNOME Shell extension to hide battery icon in top panel, if battery is fully charged and AC is connected.
JavaScript
27
star
32

darian

Darian Mars calendar converter
Ruby
25
star
33

better-node-test

The CLI shortcut for node --test runner with TypeScript
JavaScript
25
star
34

plain_record

Data persistence with human readable and editable storage.
Ruby
24
star
35

evolu-lang

Programming language to automatically generate programs by evolution (genetic programming).
JavaScript
22
star
36

martian-logux-demo

TypeScript
17
star
37

twitter2vk

Script to automatically repost statuses from Twitter to VK (В Контакте)
Ruby
16
star
38

ci-job-number

Return CI job number to run huge tests only on first job
JavaScript
15
star
39

load-resources

Load all JS/CSS files from site website
JavaScript
15
star
40

hide-keyboard-layout

GNOME Shell extension to hide keyboard layout indicator in status bar
JavaScript
15
star
41

print-snapshots

Print Jest snapshots to check CLI output of your tool
JavaScript
15
star
42

susedko

Fedora CoreOS ignition config for my home server
JavaScript
14
star
43

file-container

Store different languages in one source file
JavaScript
14
star
44

autoprefixer-cli

CLI for Autoprefixer
JavaScript
14
star
45

postcss-isolation

Fix global CSS with PostCSS
14
star
46

asdf-cache-action

A Github Action to install runtimes by asdf CLI with a cache
13
star
47

showbox

Keynote generator
JavaScript
11
star
48

d2na

D²NA language for genetic programming
Ruby
10
star
49

postcss-way

Keynotes about PostCSS way
9
star
50

boilerplates

Boilerplate for my open source projects
JavaScript
9
star
51

gulp-bench-summary

Display gulp-bench results in nice table view
JavaScript
8
star
52

anim2012

Доклад «Анимации по-новому — лень, гордыня и нетерпимость»
CSS
8
star
53

nanopurify

A tiny (from 337 bytes) HTML sanitizer
JavaScript
7
star
54

universal-layout

Универсальная раскладка Ситника
7
star
55

ai

6
star
56

rit3d

Доклад «Веб, теперь в 3D: Практика»
CSS
6
star
57

dis.spbstu.ru

Department homepage
Ruby
5
star
58

evolu-steam

Evolu Steam – evolutionary computation for JavaScript
JavaScript
5
star
59

jstransformer-lowlight

Lowlight support for JSTransformers
JavaScript
5
star
60

jest-ci

CLI for Jest test framework, but coverage only on first CI job
JavaScript
5
star
61

insomnis

Текст блогокниги «Инсомнис»
4
star
62

wsd2013

Презентация «Автопрефиксер: мир без CSS-префиксов»
Ruby
4
star
63

showbox-ai

Sitnik’s theme for ShowBox
CSS
3
star
64

ruby2jar

Ruby2Jar builds JAR from a Ruby script
Ruby
3
star
65

plague

Blog/book Plague engine
Ruby
3
star
66

showbox-bright

Shower Bright theme for Showbox
JavaScript
3
star
67

showbox-shower

Shower for ShowBox
JavaScript
2
star
68

on_the_islands

Ruby
2
star