sparkline — 6.0.0

Render one compact Unicode trend glyph per value with gaps, colors, thresholds, and custom levels.

Signature

Signature
sparkline(values, options?: SparklineOptions): string

Executable examples

Sparkline options

Source
sparkline([1, 3, null, 2], {
  threshold: { value: 3, belowColor: 'ansiBlue', aboveColor: 'ansiRed' },
  symbols: { empty: '_' },
});
Terminal output
▁█_▅

SparklineOptions

Visual options for compact sparkline output.

type SparklineOptions = Readonly<{
  /** Per-call level and empty-cell glyph overrides. */
  symbols?: SparklineSymbols;
}> & ({
  /** ANSI color applied globally or mapped one-to-one with input values. */
  color?: SparklineColor;
  threshold?: never;
} | {
  color?: never;
  /** ANSI colors selected from each finite value's threshold relation. */
  threshold: SparklineThreshold;
});

symbols

SparklineSymbolsOptional

Per-call level and empty-cell glyph overrides.

Related executable examples: Sparkline options

color

SparklineColor | neverOptional

ANSI color applied globally or mapped one-to-one with input values.

Related executable examples: Sparkline options

threshold

never | SparklineThresholdOptional

ANSI colors selected from each finite value's threshold relation.

Related executable examples: Sparkline options

SparklineThreshold

Colors selected by comparing each finite value with one numeric threshold.

type SparklineThreshold = Readonly<{
  /** Finite comparison value. */
  value: number;
  /** ANSI color used for values below the threshold. */
  belowColor: Color;
  /** Color used when a value equals or exceeds the threshold. */
  aboveColor: Color;
}>;

value

numberRequired

Finite comparison value.

Related executable examples: Sparkline options

belowColor

ColorRequired

ANSI color used for values below the threshold.

Related executable examples: Sparkline options

aboveColor

ColorRequired

Color used when a value equals or exceeds the threshold.

Related executable examples: Sparkline options

SparklineSymbols

Per-call sparkline glyph overrides.

type SparklineSymbols = Readonly<{
  /** Exactly eight one-column glyphs ordered from lowest to highest. */
  levels?: readonly [string, string, string, string, string, string, string, string];
  /** One-column glyph used for `null`. */
  empty?: string;
}>;

levels

readonly [string, string, string, string, string, string, string, string]Optional

Exactly eight one-column glyphs ordered from lowest to highest.

Related executable examples: Sparkline options

empty

stringOptional

One-column glyph used for null.

Related executable examples: Sparkline options