New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details →
Socket
Book a DemoSign in
Socket

termark

Package Overview
Dependencies
Maintainers
1
Versions
4
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

termark

A basic library to format console output to the standard non-browser terminal.

latest
npmnpm
Version
2.1.0
Version published
Maintainers
1
Created
Source

Termark

Termark is a basic library to format console output to the standard non-browser terminal.

Features & Highlights

  • Zero dependencies
  • ESM & CJS compatible
  • NO_COLOR-friendly
  • Default and named imports
  • Basic ANSI styling (dim, bold, italic, …)
  • 4-bit ($2^4 = 16$) colours (red, cyan, blueBright, …)
  • 8-bit ($2^8 = 256$) colours (ansi256())
  • 24-bit ($2^{24} = 16777216$; truecolor) colours (rgb())
  • Gradients (gradient())
  • Built-in terminal logging methods (success(), info(), warn(), error())
  • Template strings & nested styles (green`Success: File ${cyan`plans.txt`} created successfully!`)
  • Colour-detection utilities (areColorsEnabled, is8bitEnabled, is24bitEnabled)
  • Usage as an object or as a class
  • Custom themes & loggers

Installation

npm install termark

ESM & CJS compatibility

Termark is compatible with both ECMAScript modules (import/export syntax), and CommonJS:

// CJS:
const termark = require('termark');

// ESM:
import termark from 'termark';

Default & named imports

Termark offers both a default import that has access to all properties and methods, or you can import each one individually:

// Default import:
import termark from 'termark';

termark.info('This is the default import, where all properties and methods are accessible.');

// Named imports:
import { success, inverse } from 'termark';

success(
    inverse('This text with a green background is achieved with named imports!')
)

Usage

Here's a quick reference for every feature Termark provides:

import termark from 'termark';

console.log(
    termark.red('This is red text.'),
    termark.bgGreen('This text has a green background.'),
    termark.cyan`There's support for template strings as well`,
    termark.ansi256('text', 33)('This single function handles text and background colour!'),
    termark.rgb('background', 42, 122, 255)('This is some dark blue text'),
    termark.gradient('text', [[53, 72, 172], [200, 230, 121]])('Gradients are also possible.'),
    termark.areColorsEnabled,
    termark.is8bitEnabled,
    termark.is24bitEnabled
);

Basic ANSI styling

import termark from 'termark';

termark.reset('...');
termark.bold('...');
termark.dim('...');
termark.italic('...');
termark.underline('...');
termark.blink('...');
termark.inverse('...');
termark.overline('...');
termark.hidden('...');
termark.strike('...');

4-bit colours

import termark from 'termark';

termark.black('...');
termark.red('...');
termark.green('...');
termark.yellow('...');
termark.blue('...');
termark.magenta('...');
termark.white('...');

termark.blackBright('...');
termark.redBright('...');
termark.greenBright('...');
termark.yellowBright('...');
termark.blueBright('...');
termark.magentaBright('...');
termark.whiteBright('...');

termark.bgBlack('...');
termark.bgRed('...');
termark.bgGreen('...');
termark.bgYellow('...');
termark.bgBlue('...');
termark.bgMagenta('...');
termark.bgWhite('...');

termark.bgBlackBright('...');
termark.bgRedBright('...');
termark.bgGreenBright('...');
termark.bgYellowBright('...');
termark.bgBlueBright('...');
termark.bgMagentaBright('...');
termark.bgWhiteBright('...');

8-bit colours

import termark from 'termark';

termark.ansi256('text', 33)('...');
termark.ansi256('background', 200)('...');

24-bit colours

import termark from 'termark';

// You can specify your RGB values as an array:
termark.rgb('text', [182, 22, 234])('...');
termark.rgb('background', [200, 0, 184])('...');

// ...or as a simple list of three values:
termark.rgb('text', 182, 22, 234)('...');
termark.rgb('background', 200, 0, 184)('...');


// This method is compatible with `color-convert`:
import convert from 'color-convert';

termark.rgb('text', convert.hex.rgb('008330'))('...');

Gradients

Please note that gradients do not support nested styling.

import termark from 'termark';

termark.gradient('text', [[200, 123, 0], [0, 255, 255], [177, 209, 10]])('...');
termark.gradient('background', [[123, 75, 204], [255, 255, 255], [0, 44, 55]])('...');

Built-in terminal logging methods

import termark from 'termark';

termark.success('...'); // Logs some message in green as an info message.
termark.info('...'); // Logs some message in blue as an info message.
termark.warning('...'); // Logs some message in yellow as a warning.
termark.error('...'); // Logs some message in red as an error.

// These also support prefixes for branding purposes:

const brandPrefix = termark.blue('Example') + termark.blackBright(' - ');

termark.error('File not found', brandPrefix);

Template strings

import termark from 'termark';

// Instead of using this:
termark.blue('...');

// ...you can use this:
termark.blue`...`;

Nested styles

import termark from 'termark';

termark.blue(
    'This is some blue text ' +
    termark.yellow('That becomes yellow,') +
    ' that becomes blue again.'
);

Colour-detection utilities

import termark from 'termark';

termark.areColorsEnabled; // Check whether terminal colours are enabled.
termark.is8bitEnabled; // Check whether 8-bit (256) colours are enabled.
termark.is24bitEnabled; // Check whether 24-bit (truecolor) colours are enabled.

Class v. Object

You can use Termark by importing the object, or you can import the class:

import { Termark } from 'termark';

const termark = new Termark(); // This is the same as importing the `termark` object.
termark.success('Termark is working!');

// Alternatively, you could do this:
Termark.init.success('This work, too!');

Termark.init enables using the Termark class as the default termark object.

Custom themes and loggers

You can create custom themes (a collection of multiple styles) and loggers:

import termark, { Termark } from 'termark';

const myTheme = Termark.createTheme(
    termark.blue, // <- Notice that we specify a built-in function *without calling it*!
    termark.bold // Same goes for this one.
);

console.log(
    myTheme('This text is bold and blue!')
);

// ------

// All properties but `default` are completely optional.
// If omitted, default ones are used
const myLogger = Termark.createLogger({
    default: [
        termark.cyan,
        termark.italic
    ],
    success: {
        prefix: false, // Disable built-in prefix
        styles: [
            termark.greenBright,
            termark.bold
        ]
    },
    info: {
        prefix: 'Info' // Custom prefix to override the default
        // No custom styles--use default ones.
    },
    // leave `warn` as-is
    error: {
        // Use default prefix; omitting or setting to an empty string have the same result.
        styles: [
            termark.bgRedBright,
            termark.dim
        ]
    },
});

myLogger.log('...'); // Uses the `default` property's options.
myLogger.success('...'); // Omitted prefix, uses custom styles.
myLogger.info('...'); // Uses custom prefix, default styles.
myLogger.warn('...'); // Left as-is.
myLogger.error('...'); // Uses default prefix, with custom styles.

Licence

Termark's code is licenced under the Apache licence version 2.
The full licence text is present in these source files. In addition, this snippet of text is present at the top of all files:

Copyright 2025 Q

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

    http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

Keywords

utility

FAQs

Package last updated on 11 Oct 2025

Did you know?

Socket

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