[Pkg-javascript-commits] [node-grunt-legacy-log-utils] 01/05: Import Upstream version 1.0.0

Sruthi Chandran srud-guest at moszumanska.debian.org
Fri Nov 11 06:49:26 UTC 2016


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

srud-guest pushed a commit to branch master
in repository node-grunt-legacy-log-utils.

commit a519c5db2feb82789edd430aae747f9639025a93
Author: Sruthi <srud at disroot.org>
Date:   Fri Nov 11 12:08:03 2016 +0530

    Import Upstream version 1.0.0
---
 .gitignore    |   1 +
 .jshintrc     |  14 +++++++
 .travis.yml   |  14 +++++++
 Gruntfile.js  |  30 +++++++++++++++
 LICENSE-MIT   |  22 +++++++++++
 README.md     |   6 +++
 appveyor.yml  |  27 ++++++++++++++
 index.js      | 115 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 package.json  |  40 ++++++++++++++++++++
 test/index.js |  79 ++++++++++++++++++++++++++++++++++++++++
 10 files changed, 348 insertions(+)

diff --git a/.gitignore b/.gitignore
new file mode 100644
index 0000000..3c3629e
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1 @@
+node_modules
diff --git a/.jshintrc b/.jshintrc
new file mode 100644
index 0000000..2b7e39b
--- /dev/null
+++ b/.jshintrc
@@ -0,0 +1,14 @@
+{
+  "curly": true,
+  "eqeqeq": true,
+  "immed": true,
+  "latedef": "nofunc",
+  "newcap": true,
+  "noarg": true,
+  "sub": true,
+  "undef": true,
+  "unused": true,
+  "boss": true,
+  "eqnull": true,
+  "node": true
+}
diff --git a/.travis.yml b/.travis.yml
new file mode 100644
index 0000000..201c484
--- /dev/null
+++ b/.travis.yml
@@ -0,0 +1,14 @@
+sudo: false
+language: node_js
+node_js:
+  - "0.10"
+  - "0.12"
+  - "4.0"
+  - "4.1"
+  - "4.2"
+  - "5"
+  - "iojs"
+before_install:
+  - npm install -g npm
+matrix:
+  fast_finish: true
diff --git a/Gruntfile.js b/Gruntfile.js
new file mode 100644
index 0000000..d7e5845
--- /dev/null
+++ b/Gruntfile.js
@@ -0,0 +1,30 @@
+'use strict';
+
+module.exports = function(grunt) {
+
+  grunt.initConfig({
+    jshint: {
+      options: {
+        jshintrc: '.jshintrc',
+      },
+      all: ['*.js', 'test/*.js'],
+    },
+    nodeunit: {
+      util: ['test/index.js']
+    },
+    watch: {
+      all: {
+        files: ['<%= jshint.all %>'],
+        tasks: ['test'],
+      },
+    },
+  });
+
+  grunt.loadNpmTasks('grunt-contrib-jshint');
+  grunt.loadNpmTasks('grunt-contrib-nodeunit');
+  grunt.loadNpmTasks('grunt-contrib-watch');
+
+  grunt.registerTask('test', ['jshint', 'nodeunit']);
+  grunt.registerTask('default', ['test', 'watch']);
+
+};
diff --git a/LICENSE-MIT b/LICENSE-MIT
new file mode 100644
index 0000000..8ac94f0
--- /dev/null
+++ b/LICENSE-MIT
@@ -0,0 +1,22 @@
+Copyright (c) 2016 "Cowboy" Ben Alman
+
+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.
diff --git a/README.md b/README.md
new file mode 100644
index 0000000..aa10daf
--- /dev/null
+++ b/README.md
@@ -0,0 +1,6 @@
+# grunt-legacy-log-utils
+> Static methods for the Grunt 0.4.x logger.
+
+[![Build Status: Linux](https://travis-ci.org/gruntjs/grunt-legacy-log-utils.svg?branch=master)](https://travis-ci.org/gruntjs/grunt-legacy-log-utils)
+[![Build Status: Windows](https://ci.appveyor.com/api/projects/status/a6s4cy3fcbl33hnp?svg=true)](https://ci.appveyor.com/project/gruntjs/grunt-legacy-log-utils)
+[![Built with Grunt](https://cdn.gruntjs.com/builtwith.png)](http://gruntjs.com/)
diff --git a/appveyor.yml b/appveyor.yml
new file mode 100644
index 0000000..0e77dee
--- /dev/null
+++ b/appveyor.yml
@@ -0,0 +1,27 @@
+# Fix line endings on Windows
+init:
+  - git config --global core.autocrlf true
+# What combinations to test
+environment:
+  matrix:
+    - nodejs_version: "0.10"
+    - nodejs_version: "0.12"
+    - nodejs_version: "4"
+platform:
+  - x86
+  - x64
+install:
+  - ps: Install-Product node $env:nodejs_version
+  - npm install
+test_script:
+  # Output useful info for debugging.
+  - node --version && npm --version
+  # We test multiple Windows shells because of prior stdout buffering issues
+  # filed against Grunt. https://github.com/joyent/node/issues/3584
+  - ps: "npm test # PowerShell" # Pass comment to PS for easier debugging
+  - cmd: npm test
+build: off
+matrix:
+  fast_finish: true
+cache:
+  - node_modules -> package.json # local npm modules
diff --git a/index.js b/index.js
new file mode 100644
index 0000000..2b72907
--- /dev/null
+++ b/index.js
@@ -0,0 +1,115 @@
+/*
+ * grunt
+ * http://gruntjs.com/
+ *
+ * Copyright (c) 2016 "Cowboy" Ben Alman
+ * Licensed under the MIT license.
+ * https://github.com/gruntjs/grunt/blob/master/LICENSE-MIT
+ */
+
+'use strict';
+
+var chalk = require('chalk');
+var _ = require('lodash');
+
+// Pretty-format a word list.
+exports.wordlist = function(arr, options) {
+  options = _.defaults(options || {}, {
+    separator: ', ',
+    color: 'cyan'
+  });
+  return arr.map(function(item) {
+    return options.color ? chalk[options.color](item) : item;
+  }).join(options.separator);
+};
+
+// Return a string, uncolored (suitable for testing .length, etc).
+exports.uncolor = function(str) {
+  return str.replace(/\x1B\[\d+m/g, '');
+};
+
+// Word-wrap text to a given width, permitting ANSI color codes.
+exports.wraptext = function(width, text) {
+  // notes to self:
+  // grab 1st character or ansi code from string
+  // if ansi code, add to array and save for later, strip from front of string
+  // if character, add to array and increment counter, strip from front of string
+  // if width + 1 is reached and current character isn't space:
+  //  slice off everything after last space in array and prepend it to string
+  //  etc
+
+  // This result array will be joined on \n.
+  var result = [];
+  var matches, color, tmp;
+  var captured = [];
+  var charlen = 0;
+
+  while (matches = text.match(/(?:(\x1B\[\d+m)|\n|(.))([\s\S]*)/)) {
+    // Updated text to be everything not matched.
+    text = matches[3];
+
+    // Matched a color code?
+    if (matches[1]) {
+      // Save last captured color code for later use.
+      color = matches[1];
+      // Capture color code.
+      captured.push(matches[1]);
+      continue;
+
+    // Matched a non-newline character?
+    } else if (matches[2]) {
+      // If this is the first character and a previous color code was set, push
+      // that onto the captured array first.
+      if (charlen === 0 && color) { captured.push(color); }
+      // Push the matched character.
+      captured.push(matches[2]);
+      // Increment the current charlen.
+      charlen++;
+      // If not yet at the width limit or a space was matched, continue.
+      if (charlen <= width || matches[2] === ' ') { continue; }
+      // The current charlen exceeds the width and a space wasn't matched.
+      // "Roll everything back" until the last space character.
+      tmp = captured.lastIndexOf(' ');
+      text = captured.slice(tmp === -1 ? tmp : tmp + 1).join('') + text;
+      captured = captured.slice(0, tmp);
+    }
+
+    // The limit has been reached. Push captured string onto result array.
+    result.push(captured.join(''));
+
+    // Reset captured array and charlen.
+    captured = [];
+    charlen = 0;
+  }
+
+  result.push(captured.join(''));
+  return result.join('\n');
+};
+
+// Format output into columns, wrapping words as-necessary.
+exports.table = function(widths, texts) {
+  var rows = [];
+  widths.forEach(function(width, i) {
+    var lines = this.wraptext(width, texts[i]).split('\n');
+    lines.forEach(function(line, j) {
+      var row = rows[j];
+      if (!row) { row = rows[j] = []; }
+      row[i] = line;
+    });
+  }, this);
+
+  var lines = [];
+  rows.forEach(function(row) {
+    var txt = '';
+    var column;
+    for (var i = 0; i < row.length; i++) {
+      column = row[i] || '';
+      txt += column;
+      var diff = widths[i] - this.uncolor(column).length;
+      if (diff > 0) { txt += _.repeat(' ', diff); }
+    }
+    lines.push(txt);
+  }, this);
+
+  return lines.join('\n');
+};
diff --git a/package.json b/package.json
new file mode 100644
index 0000000..e6d4b9e
--- /dev/null
+++ b/package.json
@@ -0,0 +1,40 @@
+{
+  "name": "grunt-legacy-log-utils",
+  "description": "Static methods for the Grunt 0.4.x logger.",
+  "version": "1.0.0",
+  "author": "\"Cowboy\" Ben Alman (http://benalman.com/)",
+  "homepage": "http://gruntjs.com/",
+  "repository": {
+    "type": "git",
+    "url": "git://github.com/gruntjs/grunt-legacy-log-utils.git"
+  },
+  "bugs": {
+    "url": "http://github.com/gruntjs/grunt-legacy-log-utils/issues"
+  },
+  "license": "MIT",
+  "main": "index.js",
+  "files": [
+    "index.js"
+  ],
+  "scripts": {
+    "test": "grunt test"
+  },
+  "engines": {
+    "node": ">= 0.10.0"
+  },
+  "keywords": [
+    "grunt",
+    "legacy"
+  ],
+  "dependencies": {
+    "chalk": "~1.1.1",
+    "lodash": "~4.3.0"
+  },
+  "devDependencies": {
+    "grunt": "~0.4.4",
+    "grunt-cli": "~0.1.13",
+    "grunt-contrib-jshint": "~0.10.0",
+    "grunt-contrib-nodeunit": "~0.3.3",
+    "grunt-contrib-watch": "~0.6.1"
+  }
+}
diff --git a/test/index.js b/test/index.js
new file mode 100644
index 0000000..bb565bf
--- /dev/null
+++ b/test/index.js
@@ -0,0 +1,79 @@
+'use strict';
+
+var logUtils = require('../');
+
+exports['Helpers'] = {
+  setUp: function(done) {
+    done();
+  },
+  'uncolor': function(test) {
+    test.expect(1);
+
+    test.equal(logUtils.uncolor('a'.red + 'b'.bold.green + 'c'.blue.underline), 'abc');
+
+    test.done();
+  },
+  'wordlist': function(test) {
+    test.expect(2);
+
+    test.equal(logUtils.uncolor(logUtils.wordlist(['a', 'b'])), 'a, b');
+    test.equal(logUtils.uncolor(logUtils.wordlist(['a', 'b'], {separator: '-'})), 'a-b');
+
+    test.done();
+  },
+  'wraptext': function(test) {
+    test.expect(8);
+
+    // // I'm not writing out comprehensive unit tests for this right now.
+    // function doAll(text) {
+    //   console.log('==========');
+    //   console.log('==========');
+    //   [4, 6, 10, 15, 20, 25, 30, 40, 60].forEach(function(n) {
+    //     doOne(n, text);
+    //   });
+    // }
+    // function doOne(n, text) {
+    //   console.log(new Array(n + 1).join('-'));
+    //   console.log(logUtils.wraptext(n, text));
+    // }
+    // var text = 'this is '.red + 'a simple'.yellow.inverse + ' test of'.green + ' ' + 'some wrapped'.blue + ' text over '.inverse.magenta + 'many lines'.red;
+    // doAll(text);
+    // text = 'foolish '.red.inverse + 'monkeys'.yellow + ' eating'.green + ' ' + 'delicious'.inverse.blue + ' bananas '.magenta + 'forever'.red;
+    // doAll(text);
+    // text = 'foolish monkeys eating delicious bananas forever'.rainbow;
+    // doAll(text);
+
+    test.equal(logUtils.wraptext(2, 'aabbc'), 'aa\nbb\nc');
+    test.equal(logUtils.wraptext(2, 'aabbcc'), 'aa\nbb\ncc');
+    test.equal(logUtils.wraptext(3, 'aaabbbc'), 'aaa\nbbb\nc');
+    test.equal(logUtils.wraptext(3, 'aaabbbcc'), 'aaa\nbbb\ncc');
+    test.equal(logUtils.wraptext(3, 'aaabbbccc'), 'aaa\nbbb\nccc');
+    test.equal(logUtils.uncolor(logUtils.wraptext(3, 'aaa'.blue + 'bbb'.green + 'c'.underline)), 'aaa\nbbb\nc');
+    test.equal(logUtils.uncolor(logUtils.wraptext(3, 'aaa'.blue + 'bbb'.green + 'cc'.underline)), 'aaa\nbbb\ncc');
+    test.equal(logUtils.uncolor(logUtils.wraptext(3, 'aaa'.blue + 'bbb'.green + 'ccc'.underline)), 'aaa\nbbb\nccc');
+
+    test.done();
+  },
+  'table': function(test) {
+    test.expect(1);
+
+    test.equal(logUtils.table([3, 1, 5, 1, 8, 1, 12, 1, 20], [
+      'a aa aaa aaaa aaaaa',
+      '|||||||',
+      'b bb bbb bbbb bbbbb',
+      '|||||||',
+      'c cc ccc cccc ccccc',
+      '|||||||',
+      'd dd ddd dddd ddddd',
+      '|||||||',
+      'e ee eee eeee eeeee eeeeee',
+    ]), 'a  |b bb |c cc ccc|d dd ddd    |e ee eee eeee eeeee \n' +
+        'aa |bbb  |cccc    |dddd ddddd  |eeeeee              \n' +
+        'aaa|bbbb |ccccc   |            |\n' +
+        'aaa|bbbbb|        |            |\n' +
+        'a  |     |        |            |\n' +
+        'aaa|     |        |            |\n' +
+        'aa |     |        |            |');
+    test.done();
+  },
+};

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-javascript/node-grunt-legacy-log-utils.git



More information about the Pkg-javascript-commits mailing list