summaryrefslogtreecommitdiff
path: root/tools/node_modules/eslint/node_modules/text-table/index.js
diff options
context:
space:
mode:
authorMichaël Zasso <targos@protonmail.com>2017-12-22 16:53:42 +0100
committerMichaël Zasso <targos@protonmail.com>2018-01-11 09:48:05 +0100
commit3dc30632755713179f345f4af024bd904c6162d0 (patch)
treef28c4f6dd6dfc5992edf301449d1a371d229755b /tools/node_modules/eslint/node_modules/text-table/index.js
parenta2c7085dd4a8e60d1a47572aca8bb6fcb7a32f88 (diff)
downloadandroid-node-v8-3dc30632755713179f345f4af024bd904c6162d0.tar.gz
android-node-v8-3dc30632755713179f345f4af024bd904c6162d0.tar.bz2
android-node-v8-3dc30632755713179f345f4af024bd904c6162d0.zip
tools: move eslint from tools to tools/node_modules
This is required because we need to add the babel-eslint dependency and it has to be able to resolve "eslint". babel-eslint is required to support future ES features such as async iterators and import.meta. Refs: https://github.com/nodejs/node/pull/17755 PR-URL: https://github.com/nodejs/node/pull/17820 Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
Diffstat (limited to 'tools/node_modules/eslint/node_modules/text-table/index.js')
-rw-r--r--tools/node_modules/eslint/node_modules/text-table/index.js86
1 files changed, 86 insertions, 0 deletions
diff --git a/tools/node_modules/eslint/node_modules/text-table/index.js b/tools/node_modules/eslint/node_modules/text-table/index.js
new file mode 100644
index 0000000000..5c0ba9876a
--- /dev/null
+++ b/tools/node_modules/eslint/node_modules/text-table/index.js
@@ -0,0 +1,86 @@
+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;
+}