From b674514f1b7cebedd978673dfb3b2379871e464d Mon Sep 17 00:00:00 2001 From: Bastien Caudan Date: Mon, 9 Apr 2018 08:16:20 +0200 Subject: [PATCH] Expose enable/disable methods closes #221 --- index.d.ts | 2 ++ lib/colors.js | 10 +++++++++- safe.d.ts | 2 ++ 3 files changed, 13 insertions(+), 1 deletion(-) diff --git a/index.d.ts b/index.d.ts index db72fab..faa9ab6 100644 --- a/index.d.ts +++ b/index.d.ts @@ -46,6 +46,8 @@ export interface Color { zalgo: Color; } +export function enable(): void; +export function disable(): void; export function setTheme(theme: any): void; export let enabled: boolean; diff --git a/lib/colors.js b/lib/colors.js index 1fb08b5..335517d 100644 --- a/lib/colors.js +++ b/lib/colors.js @@ -2,7 +2,7 @@ The MIT License (MIT) -Original Library +Original Library - Copyright (c) Marak Squires Additional functionality @@ -42,6 +42,14 @@ if (typeof colors.enabled === "undefined") { colors.enabled = colors.supportsColor() !== false; } +colors.enable = function () { + colors.enabled = true; +}; + +colors.disable = function () { + colors.enabled = false; +}; + colors.stripColors = colors.strip = function(str){ return ("" + str).replace(/\x1B\[\d+m/g, ''); }; diff --git a/safe.d.ts b/safe.d.ts index 87f5ef2..9c81946 100644 --- a/safe.d.ts +++ b/safe.d.ts @@ -4,6 +4,8 @@ // Definitions: https://github.com/Marak/colors.js export const enabled: boolean; +export function enable(): void; +export function disable(): void; export function strip(str: string): string; export function stripColors(str: string): string;