From a66c48630194c16b06a8714249c8877fe0370588 Mon Sep 17 00:00:00 2001 From: Sindre Sorhus Date: Sun, 8 Dec 2013 00:33:08 +0100 Subject: [PATCH] use `strip-ansi` https://github.com/sindresorhus/strip-ansi --- chalk.js | 10 ++++------ package.json | 3 ++- 2 files changed, 6 insertions(+), 7 deletions(-) diff --git a/chalk.js b/chalk.js index 4aad200..c4d4733 100644 --- a/chalk.js +++ b/chalk.js @@ -1,5 +1,7 @@ 'use strict'; var ansi = require('ansi-styles'); +var stripAnsi = require('strip-ansi'); +var hasColor = require('has-color'); var defineProps = Object.defineProperties; ansi.grey = ansi.gray; @@ -51,12 +53,8 @@ function init() { } chalk.styles = ansi; - -chalk.stripColor = function (str) { - return typeof str === 'string' ? str.replace(/\x1B\[([0-9]{1,2}(;[0-9]{1,2})?)?[m|K]/g, '') : str; -}; - -chalk.supportsColor = require('has-color'); +chalk.stripColor = stripAnsi; +chalk.supportsColor = hasColor; // detect mode if not set manually if (chalk.enabled === undefined) { diff --git a/package.json b/package.json index 4b36db7..d645cab 100644 --- a/package.json +++ b/package.json @@ -44,7 +44,8 @@ }, "dependencies": { "has-color": "~0.1.0", - "ansi-styles": "~0.2.0" + "ansi-styles": "~0.2.0", + "strip-ansi": "~0.1.0" }, "devDependencies": { "mocha": "~1.12.0"