[Pkg-javascript-commits] [node-ansi-styles] 01/03: Imported Upstream version 2.0.1

Sebastiaan Couwenberg sebastic at moszumanska.debian.org
Fri Mar 20 21:09:02 UTC 2015


This is an automated email from the git hooks/post-receive script.

sebastic pushed a commit to branch master
in repository node-ansi-styles.

commit 1e500233599cbbccdf7ac478c3771bb7e6343cd5
Author: Bas Couwenberg <sebastic at xs4all.nl>
Date:   Fri Mar 20 22:04:26 2015 +0100

    Imported Upstream version 2.0.1
---
 .travis.yml  |  3 +++
 index.js     | 82 ++++++++++++++++++++++++++++++++++++------------------------
 package.json |  6 ++++-
 readme.md    | 22 +++++++++++++---
 test.js      | 21 +++++++++++-----
 5 files changed, 91 insertions(+), 43 deletions(-)

diff --git a/.travis.yml b/.travis.yml
index 244b7e8..dedfc07 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -1,3 +1,6 @@
+sudo: false
 language: node_js
 node_js:
+  - 'iojs'
+  - '0.12'
   - '0.10'
diff --git a/index.js b/index.js
index 2d8b472..caf9e11 100644
--- a/index.js
+++ b/index.js
@@ -1,40 +1,56 @@
 'use strict';
-var styles = module.exports;
 
-var codes = {
-	reset: [0, 0],
+var styles = module.exports = {
+	modifiers: {
+		reset: [0, 0],
+		bold: [1, 22], // 21 isn't widely supported and 22 does the same thing
+		dim: [2, 22],
+		italic: [3, 23],
+		underline: [4, 24],
+		inverse: [7, 27],
+		hidden: [8, 28],
+		strikethrough: [9, 29]
+	},
+	colors: {
+		black: [30, 39],
+		red: [31, 39],
+		green: [32, 39],
+		yellow: [33, 39],
+		blue: [34, 39],
+		magenta: [35, 39],
+		cyan: [36, 39],
+		white: [37, 39],
+		gray: [90, 39]
+	},
+	bgColors: {
+		bgBlack: [40, 49],
+		bgRed: [41, 49],
+		bgGreen: [42, 49],
+		bgYellow: [43, 49],
+		bgBlue: [44, 49],
+		bgMagenta: [45, 49],
+		bgCyan: [46, 49],
+		bgWhite: [47, 49]
+	}
+};
 
-	bold: [1, 22], // 21 isn't widely supported and 22 does the same thing
-	dim: [2, 22],
-	italic: [3, 23],
-	underline: [4, 24],
-	inverse: [7, 27],
-	hidden: [8, 28],
-	strikethrough: [9, 29],
+// fix humans
+styles.colors.grey = styles.colors.gray;
 
-	black: [30, 39],
-	red: [31, 39],
-	green: [32, 39],
-	yellow: [33, 39],
-	blue: [34, 39],
-	magenta: [35, 39],
-	cyan: [36, 39],
-	white: [37, 39],
-	gray: [90, 39],
+Object.keys(styles).forEach(function (groupName) {
+	var group = styles[groupName];
 
-	bgBlack: [40, 49],
-	bgRed: [41, 49],
-	bgGreen: [42, 49],
-	bgYellow: [43, 49],
-	bgBlue: [44, 49],
-	bgMagenta: [45, 49],
-	bgCyan: [46, 49],
-	bgWhite: [47, 49]
-};
+	Object.keys(group).forEach(function (styleName) {
+		var style = group[styleName];
+
+		styles[styleName] = group[styleName] = {
+			open: '\u001b[' + style[0] + 'm',
+			close: '\u001b[' + style[1] + 'm'
+		};
+	});
 
-Object.keys(codes).forEach(function (key) {
-	var val = codes[key];
-	var style = styles[key] = {};
-	style.open = '\u001b[' + val[0] + 'm';
-	style.close = '\u001b[' + val[1] + 'm';
+	Object.defineProperty(styles, groupName, {
+		value: group,
+		enumerable: false
+	});
 });
diff --git a/package.json b/package.json
index a9ba607..5014fd5 100644
--- a/package.json
+++ b/package.json
@@ -1,6 +1,6 @@
 {
   "name": "ansi-styles",
-  "version": "1.1.0",
+  "version": "2.0.1",
   "description": "ANSI escape codes for styling strings in the terminal",
   "license": "MIT",
   "repository": "sindresorhus/ansi-styles",
@@ -9,6 +9,10 @@
     "email": "sindresorhus at gmail.com",
     "url": "http://sindresorhus.com"
   },
+  "maintainers": [
+    "Sindre Sorhus <sindresorhus at gmail.com> (http://sindresorhus.com)",
+    "Joshua Appelman <jappelman at xebia.com> (http://jbnicolai.com)"
+  ],
   "engines": {
     "node": ">=0.10.0"
   },
diff --git a/readme.md b/readme.md
index 73584cc..89ec6a7 100644
--- a/readme.md
+++ b/readme.md
@@ -4,7 +4,7 @@
 
 You probably want the higher-level [chalk](https://github.com/sindresorhus/chalk) module for styling your strings.
 
-![screenshot](screenshot.png)
+![](screenshot.png)
 
 
 ## Install
@@ -30,7 +30,7 @@ Each style has an `open` and `close` property.
 
 ## Styles
 
-### General
+### Modifiers
 
 - `reset`
 - `bold`
@@ -41,7 +41,7 @@ Each style has an `open` and `close` property.
 - `hidden`
 - `strikethrough` *(not widely supported)*
 
-### Text colors
+### Colors
 
 - `black`
 - `red`
@@ -65,6 +65,22 @@ Each style has an `open` and `close` property.
 - `bgWhite`
 
 
+## Advanced usage
+
+By default you get a map of styles, but the styles are also available as groups. They are non-enumerable so they don't show up unless you access them explicitly. This makes it easier to expose only a subset in a higher-level module.
+
+- `ansi.modifiers`
+- `ansi.colors`
+- `ansi.bgColors`
+
+
+###### Example
+
+```js
+console.log(ansi.colors.green.open);
+```
+
+
 ## License
 
 MIT © [Sindre Sorhus](http://sindresorhus.com)
diff --git a/test.js b/test.js
index f030ca7..185a8cc 100644
--- a/test.js
+++ b/test.js
@@ -17,10 +17,19 @@ Object.keys(ansi).forEach(function (el) {
 	process.stdout.write(style + el + ansi.reset.open + ansi.reset.close + ' ');
 });
 
-describe('ansiStyles()', function () {
-	it('should return ANSI escape codes', function () {
-		assert.equal(ansi.green.open, '\x1b[32m');
-		assert.equal(ansi.bgGreen.open, '\x1b[42m');
-		assert.equal(ansi.green.close, '\x1b[39m');
-	});
+it('should return ANSI escape codes', function () {
+	assert.equal(ansi.green.open, '\u001b[32m');
+	assert.equal(ansi.bgGreen.open, '\u001b[42m');
+	assert.equal(ansi.green.close, '\u001b[39m');
+	assert.equal(ansi.gray.open, ansi.grey.open);
+});
+
+it('should group related codes into categories', function () {
+	assert.equal(ansi.colors.magenta, ansi.magenta);
+	assert.equal(ansi.bgColors.bgYellow, ansi.bgYellow);
+	assert.equal(ansi.modifiers.bold, ansi.bold);
+});
+
+it('groups should not be enumerable', function () {
+	assert.equal(Object.keys(ansi).indexOf('modifiers'), -1);
 });

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-javascript/node-ansi-styles.git



More information about the Pkg-javascript-commits mailing list