Skip to content

Commit

Permalink
Merge pull request #1 from jas/chalk
Browse files Browse the repository at this point in the history
Replace cli-color with chalk
  • Loading branch information
shakyShane committed Feb 17, 2014
2 parents 5d31da8 + 11ad45d commit c9dfe83
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 24 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -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)


```
Expand Down
8 changes: 5 additions & 3 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
var clc = require("cli-color");
var chalk = require("chalk");
var _ = require("lodash");

_.templateSettings.interpolate = /{:([\s\S]+?):}/g
Expand All @@ -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);
};

/**
Expand Down Expand Up @@ -63,4 +63,6 @@ module.exports.getCompiler = function (prefix) {
return compile(template, params, prefix);
};
};
module.exports.clc = clc;

module.exports.clc = chalk;
module.exports.chalk = chalk;
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
"grunt-contrib-watch": "~0.5.3"
},
"dependencies": {
"cli-color": "~0.2.3",
"chalk": "~0.4.0",
"lodash": "~2.4.1"
}
}
11 changes: 6 additions & 5 deletions tests/functionsSpec.js
Original file line number Diff line number Diff line change
@@ -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);
});
});
});
29 changes: 15 additions & 14 deletions tests/templateSpec.js
Original file line number Diff line number Diff line change
@@ -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);
});
});

Expand All @@ -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);
});
});
});

0 comments on commit c9dfe83

Please sign in to comment.