Sign Up for Free

RunKit +

Try any Node.js package right in your browser

This is a playground to test code. It runs a full Node.js environment and already has all of npm’s 400,000 packages pre-installed, including @fav/cli.get-color-depth with all npm packages installed. Try it out:

var cliGetColorDepth = require("@fav/cli.get-color-depth")

This service is provided by RunKit and is not affiliated with npm, Inc or the package authors.

@fav/cli.get-color-depth v0.1.1

Determine what colors the terminal supports

@fav/cli.get-color-depth NPM MIT License Build Status Coverage status

Determine what colors the terminal supports.

This module is created referencing tty.WriteStream#getColorDepth of Node.js API.

"fav" is an abbreviation of "favorite" and also the acronym of "for all versions". This package is intended to support all Node.js versions as possible. At least, this package supports Node.js >= v0.10.

Install

To install from npm:

$ npm install --save @fav/cli.get-color-depth

NOTE: npm < 2.7.0 does not support scoped package, but old version Node.js supports it. So when you use such older npm, you should download this package from github.com, and move it in node_modules/@fav/cli.get-color-depth/ directory manually.

Usage

var getColorDepth = require('@fav/cli.get-color-depth');
getColorDepth() // => 1 or 4 or 8 or 24

API

getColorDepth([env]) : number

Detects color depth supported by this terminal or the environment indicated by env.

Parameters:

ParameterTypeDescription
envobjectAn object containing the environment variables to check. Uses process.env if not specified. (Optional)

Returns:

TypeDescription
numberColor depth. (1:2 colors / 4:16 colors / 8:256 colors / 24: 16m colors)

Checked

Node.js (4〜12)

Platform1112
macOS
Windows10
Linux
Platform45678910
macOS
Windows10
Linux

io.js (1〜3)

Platform123
macOS
Windows10
Linux

Node.js (〜0.12)

Platform0.80.90.100.110.12
macOS
Windows10
Linux

License

Copyright (C) 2019 Takayuki Sato

This program is free software under MIT License. See the file LICENSE in this distribution for more details.

RunKit is a free, in-browser JavaScript dev environment for prototyping Node.js code, with every npm package installed. Sign up to share your code.
Sign Up for Free