From 11ad45df1ac35d973a948f48f3d093726bb834de Mon Sep 17 00:00:00 2001 From: Jason Sandmeyer Date: Mon, 17 Feb 2014 13:31:30 -0500 Subject: [PATCH] Replace cli-color with chalk --- README.md | 2 +- index.js | 8 +++++--- package.json | 2 +- tests/functionsSpec.js | 11 ++++++----- tests/templateSpec.js | 29 +++++++++++++++-------------- 5 files changed, 28 insertions(+), 24 deletions(-) diff --git a/README.md b/README.md index a62fc6a..e0e6376 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,7 @@ #cl-strings [![Build Status](https://travis-ci.org/shakyShane/cl-strings.png?branch=master)](https://travis-ci.org/shakyShane/cl-strings) > String template system for multi-colour console output with interpolation. -Basically a wrapper around [cli-color](https://npmjs.org/package/cli-color) & [lodash templates](http://lodash.com/docs#template) +Basically a wrapper around [chalk](https://www.npmjs.org/package/chalk) & [lodash templates](http://lodash.com/docs#template) ``` diff --git a/index.js b/index.js index b8bf8ba..52fe126 100644 --- a/index.js +++ b/index.js @@ -1,4 +1,4 @@ -var clc = require("cli-color"); +var chalk = require("chalk"); var _ = require("lodash"); _.templateSettings.interpolate = /{:([\s\S]+?):}/g @@ -16,7 +16,7 @@ var compile = function (template, params, prefix) { var color = split[1]; var content = split[2]; - return clc[color](content); + return chalk[color](content); }; /** @@ -63,4 +63,6 @@ module.exports.getCompiler = function (prefix) { return compile(template, params, prefix); }; }; -module.exports.clc = clc; \ No newline at end of file + +module.exports.clc = chalk; +module.exports.chalk = chalk; diff --git a/package.json b/package.json index 3f2a3f8..77678c7 100644 --- a/package.json +++ b/package.json @@ -27,7 +27,7 @@ "grunt-contrib-watch": "~0.5.3" }, "dependencies": { - "cli-color": "~0.2.3", + "chalk": "~0.4.0", "lodash": "~2.4.1" } } diff --git a/tests/functionsSpec.js b/tests/functionsSpec.js index 3c5241c..e87ca74 100644 --- a/tests/functionsSpec.js +++ b/tests/functionsSpec.js @@ -1,24 +1,25 @@ var strings = require("../index.js"); var compile = strings.getCompiler("{green:[BS]}"); -var ansiTrim = require('cli-color/lib/trim'); +var chalk = require('chalk'); +var stripColor = chalk.stripColor; describe("Returning the compile function", function () { it("can use a prefix", function () { expect(typeof compile === "function").toBe(true); }); it("can compile with a prefix", function () { - var actual = ansiTrim(compile("kittie")); + var actual = stripColor(compile("kittie")); var expected = "[BS] kittie"; expect(actual).toBe(expected); }); it("can compile multiple lines with prefix (1)", function () { - var actual = ansiTrim(compile(["kittie", "shane"])); + var actual = stripColor(compile(["kittie", "shane"])); var expected = "[BS] kittie\n[BS] shane"; expect(actual).toBe(expected); }); it("can compile multiple lines with prefix (2)", function () { - var actual = ansiTrim(compile(["{green:kittie}", "shane"])); + var actual = stripColor(compile(["{green:kittie}", "shane"])); var expected = "[BS] kittie\n[BS] shane"; expect(actual).toBe(expected); }); -}); \ No newline at end of file +}); diff --git a/tests/templateSpec.js b/tests/templateSpec.js index 91e6816..12d1c61 100644 --- a/tests/templateSpec.js +++ b/tests/templateSpec.js @@ -1,47 +1,48 @@ var compile = require("../index.js").compile; -var ansiTrim = require('cli-color/lib/trim'); +var chalk = require('chalk'); +var stripColor = chalk.stripColor; describe("Compiling strings", function () { it("Can replace a single occurrence", function () { var string = "{green:Hi there}"; var expected = "Hi there"; - expect(ansiTrim(compile(string))).toBe(expected); + expect(stripColor(compile(string))).toBe(expected); }); it("Can replace a single occurrence", function () { var string = "{green:Hi :there}"; var expected = "Hi :there"; - expect(ansiTrim(compile(string))).toBe(expected); + expect(stripColor(compile(string))).toBe(expected); }); it("Can replace a multiple occurrences", function () { var string = "{green:Hi there} {red:Shane}"; var expected = "Hi there Shane"; - expect(ansiTrim(compile(string))).toBe(expected); + expect(stripColor(compile(string))).toBe(expected); }); it("Can replace a multiple occurrences with content between", function () { var string = "{green:Hi there} and then {red:Goodbye}"; var expected = "Hi there and then Goodbye"; - expect(ansiTrim(compile(string))).toBe(expected); + expect(stripColor(compile(string))).toBe(expected); }); it("can replace with regular content at the end", function () { var string = "{green:bet you can't compile} this"; var expected = "bet you can't compile this"; - expect(ansiTrim(compile(string))).toBe(expected); + expect(stripColor(compile(string))).toBe(expected); }); it("can replace with regular content at the begining", function () { var string = "bet you can't compile {green:this}"; var expected = "bet you can't compile this"; - expect(ansiTrim(compile(string))).toBe(expected); + expect(stripColor(compile(string))).toBe(expected); }); it("can replace with line breaks", function () { var string = "bet you can't \ncompile {green:this}"; var expected = "bet you can't \ncompile this"; - expect(ansiTrim(compile(string))).toBe(expected); + expect(stripColor(compile(string))).toBe(expected); }); it("can replace with random curlies", function () { var string = "bet you {can't}} \ncompile {green:this}"; var expected = "bet you {can't}} \ncompile this"; - expect(ansiTrim(compile(string))).toBe(expected); + expect(stripColor(compile(string))).toBe(expected); }); }); @@ -50,24 +51,24 @@ describe("Accepting variables to be interpolated", function () { var expected = "Hi there Shane"; var template = "{red:Hi there} {:name:}"; var params = {name: "Shane"}; - expect(ansiTrim(compile(template, params))).toBe(expected); + expect(stripColor(compile(template, params))).toBe(expected); }); it("can run through lodash templates (2)", function () { var expected = "Hi there Shane"; var template = "{red:Hi there {:name:}}"; var params = {name: "Shane"}; - expect(ansiTrim(compile(template, params))).toBe(expected); + expect(stripColor(compile(template, params))).toBe(expected); }); it("can run through lodash templates (3)", function () { var expected = "Hi there Shane\n"; var template = "{red:Hi there {:name:}}\n"; var params = {name: "Shane"}; - expect(ansiTrim(compile(template, params))).toBe(expected); + expect(stripColor(compile(template, params))).toBe(expected); }); it("can run through lodash templates (4)", function () { var expected = "Hi there\nShane\n"; var template = "Hi there\n{red:Shane}\n"; var params = {name: "Shane"}; - expect(ansiTrim(compile(template, params))).toBe(expected); + expect(stripColor(compile(template, params))).toBe(expected); }); -}); \ No newline at end of file +});