[Pkg-javascript-commits] [node-component-consoler] 01/02: Imported Upstream version 2.0.0

Thorsten Alteholz alteholz at moszumanska.debian.org
Sun Mar 27 15:29:53 UTC 2016


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

alteholz pushed a commit to branch master
in repository node-component-consoler.

commit 392446ca5522d2988d0b2423344bf6628df31998
Author: Thorsten Alteholz <debian at alteholz.de>
Date:   Sun Mar 27 17:29:51 2016 +0200

    Imported Upstream version 2.0.0
---
 .gitignore    |  66 +++++++++++++++++++++++++++++++++
 HISTORY.md    |  11 ++++++
 README.md     |  29 +++++++++++++++
 index.js      | 115 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 package.json  |  10 +++++
 test/index.js |   6 +++
 6 files changed, 237 insertions(+)

diff --git a/.gitignore b/.gitignore
new file mode 100644
index 0000000..9af5ae2
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1,66 @@
+# Compiled source #
+###################
+*.com
+*.class
+*.dll
+*.exe
+*.o
+*.so
+
+# Packages #
+############
+# it's better to unpack these files and commit the raw source
+# git has its own built in compression methods
+*.7z
+*.dmg
+*.gz
+*.iso
+*.jar
+*.rar
+*.tar
+*.zip
+
+# Logs and databases #
+######################
+*.log
+*.sql
+*.sqlite
+
+# OS generated files #
+######################
+.DS_Store*
+ehthumbs.db
+Icon?
+Thumbs.db
+
+# Node.js #
+###########
+lib-cov
+*.seed
+*.log
+*.csv
+*.dat
+*.out
+*.pid
+*.gz
+
+pids
+logs
+results
+
+node_modules
+npm-debug.log
+
+# Git #
+#######
+*.orig
+*.BASE.*
+*.BACKUP.*
+*.LOCAL.*
+*.REMOTE.*
+
+# Components #
+##############
+
+/build
+/components
diff --git a/HISTORY.md b/HISTORY.md
new file mode 100644
index 0000000..ed78268
--- /dev/null
+++ b/HISTORY.md
@@ -0,0 +1,11 @@
+
+2.0.0 / 2014-09-22
+==================
+
+ * `.log` signature changed to `(type, message, ...subsitutes?)`
+ * `.fatal` uses the text `fatal` instead of `error`
+
+1.1.1 / 2014-04-07
+==================
+
+ * show stack traces for user errors
diff --git a/README.md b/README.md
new file mode 100644
index 0000000..02e8379
--- /dev/null
+++ b/README.md
@@ -0,0 +1,29 @@
+# Component Console
+
+Console commands for `component(1)`.
+Use this to create consistent logs across `component(1)` commands and libs.
+
+## License
+
+(The MIT License)
+
+Copyright (c) 2014 segmentio <team at segment.io>
+
+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/index.js b/index.js
new file mode 100644
index 0000000..fdd4c70
--- /dev/null
+++ b/index.js
@@ -0,0 +1,115 @@
+var debug = require('debug')('component-consoler');
+var slice = Array.prototype.slice;
+
+/**
+ * Error types where we show the stack trace.
+ * These are generally user errors, not "our" errors.
+ **/
+var showstack = [
+  'ParseError',
+  'SyntaxError',
+  'URIError'
+];
+
+/**
+ * Log message with `type` and `message` interpolated by `substitutes`.
+ *
+ * @param {String} type
+ * @param {String} message
+ * @param {...String} [substitutes]
+ * @api public
+**/
+exports.log = function (type, message /*, substitutes */) {
+  log('log', 36, type, message, slice.call(arguments, 2));
+};
+
+/**
+ * Log warning message with `type` and `message` interpolated by `substitutes`.
+ *
+ * @param {String} type
+ * @param {String} message
+ * @param {...String} [substitutes]
+ * @api public
+**/
+exports.warn = function (type, message /*, substitutes */) {
+  log('warn', 33, type, message, slice.call(arguments, 2));
+};
+
+/**
+ * Log error message with "error" type and `message` interpolated by `substitutes`.
+ *
+ * @param {String} message
+ * @param {...String} [substitutes]
+ * @api public
+**/
+exports.error = function (message /*, substitutes */) {
+  log('error', 31, 'error', message, slice.call(arguments, 1));
+};
+
+/**
+ * Log error message and exit with "fatal" type and `error` interpolated by `substitutes`.
+ * Depending on the error type, show the stack trace.
+ *
+ * @param {String|Error} error
+ * @param {...String} [substitutes]
+ * @api public
+**/
+exports.fatal = function (error /*, substitutes */) {
+  var message = error;
+
+  if (error instanceof Error) {
+    debug(error.stack);
+
+    if (error.stack && ~showstack.indexOf(error.name)) {
+      message = error.stack;
+    } else {
+      message = error.message;
+    }
+  }
+
+  console.error();
+  log('error', 31, 'fatal', message, slice.call(arguments, 1));
+  console.error();
+  process.exit(1);
+};
+
+/**
+ * Log message in console `method` with `color`, `type`, `message`, `substitutes`.
+ *
+ * @param {String} method
+ * @param {Number} color
+ * @param {String} type
+ * @param {String} message
+ * @param {String[]} substitues
+ * @api private
+**/
+function log (method, color, type, message, substitutes) {
+  console[method].apply(console, [stylize(type, message, color)].concat(substitutes));
+}
+
+/**
+ * Stylize message, use `color` for `type` before `message`.
+ *
+ * @param {String} type
+ * @param {String} message
+ * @param {Number} color
+ * @return {String}
+ * @api private
+**/
+function stylize (type, message, color) {
+  return '  \033[' + color + 'm' + pad(type) + '\033[m : \033[90m' + message + '\033[m';
+}
+
+/**
+ * Add whitespace indentation before text.
+ *
+ * @param {String} text
+ * @return {String}
+ * @api private
+**/
+function pad (text) {
+  var width = 10;
+  var length = Math.max(0, width - text.length);
+  var space = Array(length + 1).join(' ');
+  return space + text;
+}
diff --git a/package.json b/package.json
new file mode 100644
index 0000000..c92afad
--- /dev/null
+++ b/package.json
@@ -0,0 +1,10 @@
+{
+  "name": "component-consoler",
+  "description": "console commands for component(1)",
+  "version": "2.0.0",
+  "license": "MIT",
+  "repository": "component/console.js",
+  "dependencies": {
+    "debug": "*"
+  }
+}
diff --git a/test/index.js b/test/index.js
new file mode 100644
index 0000000..3a1f67a
--- /dev/null
+++ b/test/index.js
@@ -0,0 +1,6 @@
+var utils = require('..');
+
+utils.log('user', 'seems like %s is a real %s', 'wryk', 'person');
+utils.warn('addiction', 'take care about loving %s', 'component');
+utils.error('simple %s stuff', 'useless');
+utils.fatal(new Error('error message from error.message without stack :O'));
\ No newline at end of file

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



More information about the Pkg-javascript-commits mailing list