Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

add cli-table to package.json

  • Loading branch information...
commit 3a342875cd42026ca87c71a30d842fa9500156e3 1 parent 30dbe0d
Aaron Heckmann aheckmann authored
1  package.json
View
@@ -11,6 +11,7 @@
, "devDependencies": {
"should": "0.2.1"
, "gleak": "0.2.1"
+ , "cli-table": "0.0.1"
}
, "directories": { "lib": "./lib/mongoose" }
, "scripts": { "test": "make test" }
1  support/cli-table/.gitignore
View
@@ -1 +0,0 @@
-lib-cov
5 support/cli-table/History.md
View
@@ -1,5 +0,0 @@
-
-0.0.1 / 2011-01-03
-==================
-
-Initial release
14 support/cli-table/Makefile
View
@@ -1,14 +0,0 @@
-
-test:
- @NODE_ENV=test ./support/expresso/bin/expresso \
- -I lib \
- -I support \
- -I support/should.js/lib \
- -I support/colors.js \
- $(TESTFLAGS) \
- test/*.test.js
-
-test-cov:
- @TESTFLAGS=--cov $(MAKE) test
-
-.PHONY: test test-cov
77 support/cli-table/README.md
View
@@ -1,77 +0,0 @@
-
-CLI Table
-=========
-
-This utility allows you to render unicode-aided tables on the command line from
-your node.js scripts.
-
-![Screenshot](http://i.imgur.com/sYq4T.png)
-
-## Features
-
-- Customizable characters that constitute the table.
-- Color/background styling in the header through
- [colors.js](http://github.com/marak/colors.js)
-- Column width customization
-- Text truncation based on predefined widths
-- Text alignment (left, right, center)
-- Padding (left, right)
-- Easy-to-use API
-
-## Installation
-
- npm install cli-table
-
-## How to use
-
- var Table = require('cli-table');
-
- // instantiate
- var table = new Table({
- head: ['TH 1 label', 'TH 2 label']
- , colWidths: [100, 200]
- });
-
- // table is an Array, so you can `push`, `unshift`, `splice` and friends
- table.push(
- ['First value', 'Second value']
- , ['First value', 'Second value']
- );
-
- // render
- console.log(table.toString());
-
-## Running tests
-
-Clone the repository with all its submodules and run:
-
- $ make test
-
-## Credits
-
-- Guillermo Rauch <guillermo@learnboost.com> ([Guille](http://github.com/guille))
-
-## License
-
-(The MIT License)
-
-Copyright (c) 2010 LearnBoost <dev@learnboost.com>
-
-Permission is hereby granted, free of charge, to any person obtaining
-a copy of this software and associated documentation files (the
-'Software'), to deal in the Software without restriction, including
-without limitation the rights to use, copy, modify, merge, publish,
-distribute, sublicense, and/or sell copies of the Software, and to
-permit persons to whom the Software is furnished to do so, subject to
-the following conditions:
-
-The above copyright notice and this permission notice shall be
-included in all copies or substantial portions of the Software.
-
-THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
-EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
-MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
-IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
-CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
-TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
-SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
25 support/cli-table/examples/revs.js
View
@@ -1,25 +0,0 @@
-
-/**
- * Module requirements.
- */
-
-// this line is only needed if you refuse to use npm
-require.paths.unshift(__dirname + '/../support/colors');
-
-var Table = require('../lib/cli-table');
-
-/**
- * Example.
- */
-
-var table = new Table({
- head: ['Rel', 'Change', 'By', 'When']
- , colWidths: [6, 21, 25, 17]
-});
-
-table.push(
- ['v0.1', 'Testing something cool', 'rauchg@gmail.com', '7 minutes ago']
- , ['v0.1', 'Testing something cool', 'rauchg@gmail.com', '8 minutes ago']
-);
-
-console.log(table.toString());
2  support/cli-table/index.js
View
@@ -1,2 +0,0 @@
-
-module.exports = require('./lib/cli-table');
205 support/cli-table/lib/cli-table/index.js
View
@@ -1,205 +0,0 @@
-
-/**
- * Module dependencies.
- */
-
-var utils = require('./utils')
- , repeat = utils.repeat
- , truncate = utils.truncate
- , pad = utils.pad;
-
-require('colors');
-
-/**
- * Table constructor
- *
- * @param {Object} options
- * @api public
- */
-
-function Table (options){
- this.options = utils.options({
- chars: {
- 'top': ''
- , 'top-mid': ''
- , 'top-left': ''
- , 'top-right': ''
- , 'bottom': ''
- , 'bottom-mid': ''
- , 'bottom-left': ''
- , 'bottom-right': ''
- , 'left': ''
- , 'left-mid': ''
- , 'mid': ''
- , 'mid-mid': ''
- , 'right': ''
- , 'right-mid': ''
- }
- , truncate: ''
- , colWidths: []
- , colAligns: []
- , style: {
- 'padding-left': 1
- , 'padding-right': 1
- , head: ['cyan']
- }
- , head: []
- }, options);
-};
-
-/**
- * Inherit from Array.
- */
-
-Table.prototype.__proto__ = Array.prototype;
-
-/**
- * Width getter
- *
- * @return {Number} width
- * @api public
- */
-
-Table.prototype.__defineGetter__('width', function (){
- var str = this.toString().split("\n");
- if (str.length) return str[0].length;
- return 0;
-});
-
-/**
- * Render to a string.
- *
- * @return {String} table representation
- * @api public
- */
-
-Table.prototype.render
-Table.prototype.toString = function (){
- var ret = ''
- , options = this.options
- , style = options.style
- , head = options.head
- , chars = options.chars
- , truncater = options.truncate
- , colWidths = options.colWidths || []
- , totalWidth = 0;
-
- if (!head.length && !this.length) return '';
-
- if (!colWidths.length){
- this.concat([head]).forEach(function(cells){
- cells.forEach(function(cell, i){
- var width = typeof cell == 'object' && cell.width != undefined
- ? cell.width
- : ((typeof cell == 'object' ? String(cell.text) : String(cell)).length + (style['padding-left'] || 0) + (style['padding-right'] || 0))
- colWidths[i] = Math.max(colWidths[i] || 0, width || 0);
- });
- });
- };
-
- totalWidth = (colWidths.length == 1 ? colWidths[0] : colWidths.reduce(
- function (a, b){
- return a + b
- })) + colWidths.length + 1;
-
- // draws a line
- function line (line, left, right, intersection){
- var width = 0
- , line =
- left
- + repeat(line, totalWidth - 2)
- + right;
-
- colWidths.forEach(function (w, i){
- if (i == colWidths.length - 1) return;
- width += w + 1;
- line = line.substr(0, width) + intersection + line.substr(width + 1);
- });
-
- ret += line;
- };
-
- // draws the top line
- function lineTop (){
- line(chars.top
- , chars['top-left'] || chars.top
- , chars['top-right'] || chars.top
- , chars['top-mid']);
- ret += "\n";
- };
-
- // renders a string, by padding it or truncating it
- function string (str, index){
- var str = String(typeof str == 'object' && str.text ? str.text : str)
- , length = str.length
- , width = colWidths[index]
- - (style['padding-left'] || 0)
- - (style['padding-right'] || 0)
- , align = options.colAligns[index] || 'left';
-
- return repeat(' ', style['padding-left'] || 0)
- + (length == width ? str :
- (length < width
- ? pad(str, width, ' ', align == 'left' ? 'right' :
- (align == 'middle' ? 'both' : 'left'))
- : (truncater ? truncate(str, width, truncater) : str))
- )
- + repeat(' ', style['padding-right'] || 0);
- };
-
- if (head.length){
- lineTop();
-
- ret += chars.left;
-
- head.forEach(function (th, index){
- var text = string(th, index);
- if (style.head){
- style.head.forEach(function(style){
- text = text[style];
- });
- }
-
- ret += text;
- ret += chars.right;
- });
-
- ret += "\n";
- }
-
- if (this.length)
- this.forEach(function (cells, i){
- if (!head.length && i == 0)
- lineTop();
- else {
- line(chars.mid
- , chars['left-mid']
- , chars['right-mid']
- , chars['mid-mid']);
-
- ret += "\n" + chars.left;
-
- cells.forEach(function(cell, i){
- ret += string(cell, i);
- ret += chars.right;
- });
-
- ret += "\n";
- }
- });
-
- line(chars.bottom
- , chars['bottom-left'] || chars.bottom
- , chars['bottom-right'] || chars.bottom
- , chars['bottom-mid']);
-
- return ret;
-};
-
-/**
- * Module exports.
- */
-
-module.exports = Table;
-
-module.exports.version = '0.0.1';
81 support/cli-table/lib/cli-table/utils.js
View
@@ -1,81 +0,0 @@
-
-/**
- * Repeats a string.
- *
- * @param {String} char(s)
- * @param {Number} number of times
- * @return {String} repeated string
- */
-
-exports.repeat = function (str, times){
- return Array(times + 1).join(str);
-};
-
-/**
- * Pads a string
- *
- * @api public
- */
-
-exports.pad = function (str, len, pad, dir) {
- if (len + 1 >= str.length)
- switch (dir){
- case 'left':
- str = Array(len + 1 - str.length).join(pad) + str;
- break;
-
- case 'both':
- var right = Math.ceil((padlen = len - str.length) / 2);
- var left = padlen - right;
- str = Array(left + 1).join(pad) + str + Array(right + 1).join(pad);
- break;
-
- default:
- str = str + Array(len + 1 - str.length).join(pad);
- };
-
- return str;
-};
-
-/**
- * Truncates a string
- *
- * @api public
- */
-
-exports.truncate = function (str, length, chr){
- chr = chr || '';
- return str.length >= length ? str.substr(0, length - chr.length) + chr : str;
-};
-
-/**
- * Copies and merges options with defaults.
- *
- * @param {Object} defaults
- * @param {Object} supplied options
- * @return {Object} new (merged) object
- */
-
-function clone(a){
- var b;
- if (Array.isArray(a)){
- b = [];
- for (var i = 0, l = a.length; i < l; i++)
- b.push(typeof a[i] == 'object' ? clone(a[i]) : a[i]);
- return b;
- } else if (typeof a == 'object'){
- b = {};
- for (var i in a)
- b[i] = typeof a[i] == 'object' ? clone(a[i]) : a[i];
- return b;
- }
- return a;
-};
-
-exports.options = function (defaults, opts){
- var c = clone(opts);
- for (var i in defaults)
- if (!(i in opts))
- c[i] = defaults[i];
- return c;
-};
11 support/cli-table/package.json
View
@@ -1,11 +0,0 @@
-{ "name": "cli-table"
- , "description": "Pretty unicode tables for the CLI"
- , "version": "0.0.1"
- , "author": "Guillermo Rauch <guillermo@learnboost.com>"
- , "keywords": ["cli", "colors", "table"]
- , "dependencies": {
- "colors": "0.3.0"
- }
- , "main": "./index.js"
- , "engines": { "node": ">= 0.2.0" }
-}
6 support/cli-table/test/common.js
View
@@ -1,6 +0,0 @@
-
-/**
- * Module dependencies.
- */
-
-require('should');
52 support/cli-table/test/index.test.js
View
@@ -1,52 +0,0 @@
-
-/**
- * Module requirements.
- */
-
-require('./common');
-
-var Table = require('cli-table');
-
-/**
- * Tests.
- */
-
-module.exports = {
-
- 'test complete table': function (){
- var table = new Table({
- head: ['Rel', 'Change', 'By', 'When']
- , style: {
- 'padding-left': 1
- , 'padding-right': 1
- }
- , colWidths: [6, 21, 25, 17]
- });
-
- table.push(
- ['v0.1', 'Testing something cool', 'rauchg@gmail.com', '7 minutes ago']
- , ['v0.1', 'Testing something cool', 'rauchg@gmail.com', '8 minutes ago']
- );
-
- var expected = [
- '┏━━━━━━┳━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━┓'
- , '┃ Rel ┃ Change ┃ By ┃ When ┃'
- , '┣━━━━━━╋━━━━━━━━━━━━━━━━━━━━━╋━━━━━━━━━━━━━━━━━━━━━━━━━╋━━━━━━━━━━━━━━━━━┫'
- , '┃ v0.1 ┃ Testing something … ┃ rauchg@gmail.com ┃ 7 minutes ago ┃'
- , '┣━━━━━━╋━━━━━━━━━━━━━━━━━━━━━╋━━━━━━━━━━━━━━━━━━━━━━━━━╋━━━━━━━━━━━━━━━━━┫'
- , '┃ v0.1 ┃ Testing something … ┃ rauchg@gmail.com ┃ 8 minutes ago ┃'
- , '┗━━━━━━┻━━━━━━━━━━━━━━━━━━━━━┻━━━━━━━━━━━━━━━━━━━━━━━━━┻━━━━━━━━━━━━━━━━━┛'
- ];
-
- table.toString().should.eql(expected.join("\n"));
- },
-
- 'test width property': function (){
- var table = new Table({
- head: ['Cool']
- });
-
- table.width.should.eql(8);
- }
-
-};
2  test/common.js
View
@@ -5,7 +5,7 @@
var mongoose = require('../')
, should = require('should')
- , Table = require('../support/cli-table')
+ , Table = require('cli-table')
, Mongoose = mongoose.Mongoose
, Collection = mongoose.Collection
, Assertion = should.Assertion
Please sign in to comment.
Something went wrong with that request. Please try again.