| Current Path : /home/emeraadmin/www/4d695/ |
| Current File : /home/emeraadmin/www/4d695/text-table.tar |
package.json 0000644 00000002131 15170141435 0007030 0 ustar 00 {
"_id": "text-table@0.2.0",
"_inBundle": true,
"_location": "/npm/text-table",
"_phantomChildren": {},
"_requiredBy": [
"/npm"
],
"author": {
"name": "James Halliday",
"email": "mail@substack.net",
"url": "http://substack.net"
},
"bugs": {
"url": "https://github.com/substack/text-table/issues"
},
"description": "borderless text tables with alignment",
"devDependencies": {
"cli-color": "~0.2.3",
"tap": "~0.4.0",
"tape": "~1.0.2"
},
"homepage": "https://github.com/substack/text-table",
"keywords": [
"text",
"table",
"align",
"ascii",
"rows",
"tabular"
],
"license": "MIT",
"main": "index.js",
"name": "text-table",
"repository": {
"type": "git",
"url": "git://github.com/substack/text-table.git"
},
"scripts": {
"test": "tap test/*.js"
},
"testling": {
"files": "test/*.js",
"browsers": [
"ie/6..latest",
"chrome/20..latest",
"firefox/10..latest",
"safari/latest",
"opera/11.0..latest",
"iphone/6",
"ipad/6"
]
},
"version": "0.2.0"
}
test/center.js 0000644 00000000722 15170141436 0007344 0 ustar 00 var test = require('tape');
var table = require('../');
test('center', function (t) {
t.plan(1);
var s = table([
[ 'beep', '1024', 'xyz' ],
[ 'boop', '3388450', 'tuv' ],
[ 'foo', '10106', 'qrstuv' ],
[ 'bar', '45', 'lmno' ]
], { align: [ 'l', 'c', 'l' ] });
t.equal(s, [
'beep 1024 xyz',
'boop 3388450 tuv',
'foo 10106 qrstuv',
'bar 45 lmno'
].join('\n'));
});
test/ansi-colors.js 0000644 00000001574 15170141436 0010323 0 ustar 00 var test = require('tape');
var table = require('../');
var color = require('cli-color');
var ansiTrim = require('cli-color/lib/trim');
test('center', function (t) {
t.plan(1);
var opts = {
align: [ 'l', 'c', 'l' ],
stringLength: function(s) { return ansiTrim(s).length }
};
var s = table([
[
color.red('Red'), color.green('Green'), color.blue('Blue')
],
[
color.bold('Bold'), color.underline('Underline'),
color.italic('Italic')
],
[
color.inverse('Inverse'), color.strike('Strike'),
color.blink('Blink')
],
[ 'bar', '45', 'lmno' ]
], opts);
t.equal(ansiTrim(s), [
'Red Green Blue',
'Bold Underline Italic',
'Inverse Strike Blink',
'bar 45 lmno'
].join('\n'));
});
test/doubledot.js 0000644 00000000734 15170141436 0010050 0 ustar 00 var test = require('tape');
var table = require('../');
test('dot align', function (t) {
t.plan(1);
var s = table([
[ '0.1.2' ],
[ '11.22.33' ],
[ '5.6.7' ],
[ '1.22222' ],
[ '12345.' ],
[ '5555.' ],
[ '123' ]
], { align: [ '.' ] });
t.equal(s, [
' 0.1.2',
'11.22.33',
' 5.6.7',
' 1.22222',
'12345.',
' 5555.',
' 123'
].join('\n'));
});
test/dotalign.js 0000644 00000000705 15170141436 0007666 0 ustar 00 var test = require('tape');
var table = require('../');
test('dot align', function (t) {
t.plan(1);
var s = table([
[ 'beep', '1024' ],
[ 'boop', '334.212' ],
[ 'foo', '1006' ],
[ 'bar', '45.6' ],
[ 'baz', '123.' ]
], { align: [ 'l', '.' ] });
t.equal(s, [
'beep 1024',
'boop 334.212',
'foo 1006',
'bar 45.6',
'baz 123.'
].join('\n'));
});
test/align.js 0000644 00000000611 15170141436 0007153 0 ustar 00 var test = require('tape');
var table = require('../');
test('align', function (t) {
t.plan(1);
var s = table([
[ 'beep', '1024' ],
[ 'boop', '33450' ],
[ 'foo', '1006' ],
[ 'bar', '45' ]
], { align: [ 'l', 'r' ] });
t.equal(s, [
'beep 1024',
'boop 33450',
'foo 1006',
'bar 45'
].join('\n'));
});
test/table.js 0000644 00000000506 15170141436 0007153 0 ustar 00 var test = require('tape');
var table = require('../');
test('table', function (t) {
t.plan(1);
var s = table([
[ 'master', '0123456789abcdef' ],
[ 'staging', 'fedcba9876543210' ]
]);
t.equal(s, [
'master 0123456789abcdef',
'staging fedcba9876543210'
].join('\n'));
});
LICENSE 0000644 00000002061 15170141436 0005552 0 ustar 00 This software is released under the MIT license:
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.
index.js 0000644 00000004574 15170141436 0006225 0 ustar 00 module.exports = function (rows_, opts) {
if (!opts) opts = {};
var hsep = opts.hsep === undefined ? ' ' : opts.hsep;
var align = opts.align || [];
var stringLength = opts.stringLength
|| function (s) { return String(s).length; }
;
var dotsizes = reduce(rows_, function (acc, row) {
forEach(row, function (c, ix) {
var n = dotindex(c);
if (!acc[ix] || n > acc[ix]) acc[ix] = n;
});
return acc;
}, []);
var rows = map(rows_, function (row) {
return map(row, function (c_, ix) {
var c = String(c_);
if (align[ix] === '.') {
var index = dotindex(c);
var size = dotsizes[ix] + (/\./.test(c) ? 1 : 2)
- (stringLength(c) - index)
;
return c + Array(size).join(' ');
}
else return c;
});
});
var sizes = reduce(rows, function (acc, row) {
forEach(row, function (c, ix) {
var n = stringLength(c);
if (!acc[ix] || n > acc[ix]) acc[ix] = n;
});
return acc;
}, []);
return map(rows, function (row) {
return map(row, function (c, ix) {
var n = (sizes[ix] - stringLength(c)) || 0;
var s = Array(Math.max(n + 1, 1)).join(' ');
if (align[ix] === 'r' || align[ix] === '.') {
return s + c;
}
if (align[ix] === 'c') {
return Array(Math.ceil(n / 2 + 1)).join(' ')
+ c + Array(Math.floor(n / 2 + 1)).join(' ')
;
}
return c + s;
}).join(hsep).replace(/\s+$/, '');
}).join('\n');
};
function dotindex (c) {
var m = /\.[^.]*$/.exec(c);
return m ? m.index + 1 : c.length;
}
function reduce (xs, f, init) {
if (xs.reduce) return xs.reduce(f, init);
var i = 0;
var acc = arguments.length >= 3 ? init : xs[i++];
for (; i < xs.length; i++) {
f(acc, xs[i], i);
}
return acc;
}
function forEach (xs, f) {
if (xs.forEach) return xs.forEach(f);
for (var i = 0; i < xs.length; i++) {
f.call(xs, xs[i], i);
}
}
function map (xs, f) {
if (xs.map) return xs.map(f);
var res = [];
for (var i = 0; i < xs.length; i++) {
res.push(f.call(xs, xs[i], i));
}
return res;
}
example/center.js 0000644 00000000335 15170141436 0010020 0 ustar 00 var table = require('../');
var t = table([
[ 'beep', '1024', 'xyz' ],
[ 'boop', '3388450', 'tuv' ],
[ 'foo', '10106', 'qrstuv' ],
[ 'bar', '45', 'lmno' ]
], { align: [ 'l', 'c', 'l' ] });
console.log(t);
example/doubledot.js 0000644 00000000316 15170141436 0010520 0 ustar 00 var table = require('../');
var t = table([
[ '0.1.2' ],
[ '11.22.33' ],
[ '5.6.7' ],
[ '1.22222' ],
[ '12345.' ],
[ '5555.' ],
[ '123' ]
], { align: [ '.' ] });
console.log(t);
example/dotalign.js 0000644 00000000320 15170141436 0010333 0 ustar 00 var table = require('../');
var t = table([
[ 'beep', '1024' ],
[ 'boop', '334.212' ],
[ 'foo', '1006' ],
[ 'bar', '45.6' ],
[ 'baz', '123.' ]
], { align: [ 'l', '.' ] });
console.log(t);
example/align.js 0000644 00000000265 15170141436 0007634 0 ustar 00 var table = require('../');
var t = table([
[ 'beep', '1024' ],
[ 'boop', '33450' ],
[ 'foo', '1006' ],
[ 'bar', '45' ]
], { align: [ 'l', 'r' ] });
console.log(t);
example/table.js 0000644 00000000214 15170141436 0007623 0 ustar 00 var table = require('../');
var t = table([
[ 'master', '0123456789abcdef' ],
[ 'staging', 'fedcba9876543210' ]
]);
console.log(t);