Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

verbalize

Package Overview
Dependencies
Maintainers
2
Versions
10
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

verbalize - npm Package Compare versions

Comparing version 0.1.2 to 0.2.0

lib/plugins/colors.js

381

index.js

@@ -1,7 +0,6 @@

/**
/*!
* verbalize <https://github.com/jonschlinkert/verbalize>
* A lightweight logging library.
*
* Copyright (c) 2014 Jon Schlinkert, contributors.
* Licensed under the MIT license.
* Copyright (c) 2014-2015, Jon Schlinkert.
* Licensed under the MIT License.
*/

@@ -11,248 +10,206 @@

var chalk = require('chalk');
var Base = require('log-events');
var util = require('util');
var use = require('use');
var utils = require('./lib/utils');
var plugins = require('./lib/plugins');
function create() {
/**
* General log
*
* @api public
* @return {string}
*/
var Logger = Base.create();
var log = function () {
var args = Array.prototype.map.call(arguments, function (arg) {
return chalk.stripColor(arg);
});
args[0] = chalk.bold(args[0]);
return console.log.apply(this, args);
};
/**
* Create an instance of `Verbalize` with the given `options`.
*
* ```js
* var logger = new Verbalize({verbose: true});
* ```
* @param {Object} `options`
* @api public
*/
function Verbalize(options) {
if (!(this instanceof Verbalize)) {
return new Verbalize(options);
}
Logger.call(this);
this.options = options || {};
this.define('cache', {});
use(this);
this.initDefaults();
this.initPlugins();
}
/**
* Runner, customize with the name of your lib.
*
* @api public
* @return {String}
*/
/**
* Mixin `Logger` prototype methods
*/
log.runner = '';
util.inherits(Verbalize, Logger);
/**
* Initialize default settings
*/
/**
* Expose verbose logging.
*/
Verbalize.prototype.initDefaults = function() {
this.mode('verbose');
this.mode('not', {mode: 'toggle'});
};
log.mode = {};
log.mode.verbose = false;
/**
* Initialize core plugins
*/
Verbalize.prototype.initPlugins = function() {
this.use(plugins.colors(this.options));
this.use(plugins.styles(this.options));
this.use(plugins.isEnabled(this.options));
this.use(plugins.format(this.options));
};
/**
* Style a basic separator
*/
/**
* Base formatting.
*
* @return {String} `msg`
* @api public
*/
log.sep = chalk.gray('·');
Verbalize.prototype._format = function(args) {
args = utils.toArray.apply(null, arguments);
if (args.length > 0) {
args[0] = String(args[0]);
}
return util.format.apply(util, args);
};
/**
* Expose chalk
*/
/**
* Write to the console.
*
* @return {String} `msg`
* @api public
*/
Object.keys(chalk.styles).map(function(color) {
log[color] = chalk[color];
});
Verbalize.prototype._write = function(msg) {
process.stdout.write(utils.markup(msg || ''));
return this;
};
/**
* Write to the console followed by a newline. A blank
* line is returned if no value is passed.
*
* @return {String} `msg`
* @api public
*/
/**
* Get the current time using `.toLocaleTimeString()`.
*
* @api private
* @return {String}
*/
Verbalize.prototype._writeln = function(msg) {
return this._write((msg || '') + '\n');
};
var time = function() {
var time = new Date().toLocaleTimeString();
return chalk.bgBlack.white(time) + ' ';
};
/**
* Write formatted output.
*
* @return {String}
* @api public
*/
Verbalize.prototype.write = function() {
return this._write(this._format(arguments));
};
/**
* Base formatting for special logging.
*
* @api private
* @return {String}
*/
/**
* Write formatted output followed by a newline.
*
* @return {String}
* @api public
*/
var format = function(color, text) {
return chalk[color](' ' + log.runner + ' [' + text + '] ' + log.sep);
};
Verbalize.prototype.writeln = function() {
return this._writeln(this._format(arguments));
};
/**
* Style a basic separator.
*
* @return {String}
* @api public
*/
/**
* Timestamp
*
* @api public
* @return {string}
*/
Verbalize.prototype.sep = function(str) {
return this._sep || (this._sep = this.gray(str || ' · '));
};
log.timestamp = function () {
var args = arguments;
args[0] = time() + chalk.gray(args[0]);
return console.log.apply(this, args);
};
/**
* Stylize the given `msg` with the specified `color`.
*
* @param {String} `color` The name of the color to use
* @param {String} `msg` The args to stylize.
* @return {String}
* @api public
*/
Verbalize.prototype.stylize = function(color, args) {
args = utils.toArray(args);
var len = args.length;
var res = [];
var idx = -1;
/**
* Testing some specialized logging formats.
*/
var strip = this.options.stripColor === true;
while (++idx < len) {
var arg = args[idx];
if (strip) {
res.push(utils.stripColor(arg));
} else {
var style = null;
if (typeof color === 'string') {
style = this.styleKeys.indexOf(color) !== -1 && this[color];
} else {
style = color;
}
if (typeof style === 'function') {
res.push(style(arg));
} else {
res.push(arg);
}
}
}
return res;
};
log.subhead = function () {
var args = arguments;
args[0] = format('bold', args[0]);
return console.log.apply(this, args);
};
/**
* Define non-enumerable property `key` with the given value.
*
* @param {String} `key`
* @param {any} `value`
* @return {String}
* @api public
*/
log.setup = function () {
var args = arguments;
args[0] = format('yellow', args[0]);
return console.log.apply(this, args);
};
Verbalize.prototype.define = function(key, value) {
utils.define(this, key, value);
return this;
};
log.register = function () {
var args = arguments;
args[0] = format('green', args[0]);
return console.log.apply(this, args);
};
return Verbalize;
}
log.inform = function () {
var args = arguments;
args[0] = format('gray', args[0]);
return console.log.apply(this, args);
};
log.run = log.inform;
/**
* Write
*
* @api public
* @return {string}
* Expose `Verbalize`
*/
log.write = function () {
return console.log.apply(this, arguments);
};
module.exports = create();
log.writeln = function () {
var args = arguments;
return console.log.apply('\n' + this, args);
};
/**
* Info
* Static method to create a new constructor.
* This is useful in tests and places where the original
* prototype should not be updated.
*
* ```js
* var MyLogger = Verbalize.create();
* var logger = new MyLogger();
* ```
* @name Verbalize.create
* @api public
* @return {string}
*/
log.info = function () {
var args = arguments;
args[0] = chalk.cyan(args[0]);
return console.log.apply(this, args);
};
/**
* Success
*
* @api public
* @return {string}
*/
log.success = function () {
var args = arguments;
args[0] = chalk.green(args[0]);
return console.log.apply(this, args);
};
/**
* Done.
*
* @api public
* @return {string}
*/
log.done = function () {
var args = arguments;
args[0] = (chalk.green(' ' + log.runner + ' [' + args[0] + ']'));
return console.log.apply(this, args);
};
/**
* Warn
*
* @api public
* @return {string}
*/
log.warn = function () {
var args = arguments;
args[0] = chalk.yellow(args[0]);
return console.warn.apply(this, args);
};
/**
* Error
*
* @api public
* @return {string}
*/
log.error = function () {
var args = arguments;
args[0] = chalk.red(args[0]);
return console.error.apply(this, args);
};
/**
* Fatal
*
* @api public
* @return {string}
*/
log.fatal = function () {
var args = arguments;
args[0] = (chalk.red(' ' + log.runner + ' [FAIL]:') + chalk.gray(' · ') + args[0]);
console.log();
console.log.apply(this, args);
process.exit(1);
};
/**
* Expose all properties on the `log` object
* to `verbose` mode.
*/
log.verbose = {};
Object.keys(log).filter(function(key) {
return typeof log[key] === 'function';
}).forEach(function(key) {
log.verbose[key] = function() {
if(log.mode.verbose !== false) {
log[key].apply(log, arguments);
return log.verbose;
} else {
return;
}
};
});
module.exports = log;
module.exports.create = create;
{
"name": "verbalize",
"version": "0.1.2",
"description": "A lightweight command line logging utility, with verbose mode and colors by chalk.",
"author": {
"name": "Jon Schlinkert",
"url": "https://github.com/jonschlinkert"
},
"description": "A pluggable logging utility with built-in colors, styles, and modes.",
"version": "0.2.0",
"homepage": "https://github.com/jonschlinkert/verbalize",
"licenses": [
{
"type": "MIT",
"url": "https://github.com/jonschlinkert/verbalize/blob/master/LICENSE-MIT"
}
],
"repository": {
"type": "git",
"url": "https://github.com/jonschlinkert/verbalize.git"
},
"author": "Jon Schlinkert (https://github.com/jonschlinkert)",
"repository": "jonschlinkert/verbalize",
"bugs": {
"url": "https://github.com/jonschlinkert/verbalize/issues"
},
"license": "MIT",
"files": [
"index.js",
"lib"
],
"main": "index.js",
"engines": {
"node": ">=0.10.0",
"npm": ">=1.2.10"
},
"scripts": {
"test": "mocha --R spec"
"test": "mocha"
},
"dependencies": {
"chalk": "~0.4.0"
"ansi-bold": "^0.1.1",
"ansi-underline": "^0.1.1",
"base-is-enabled": "^0.1.0",
"define-property": "^0.2.5",
"extend-shallow": "^2.0.1",
"falsey": "^0.3.0",
"get-value": "^2.0.3",
"lazy-cache": "^1.0.3",
"log-events": "^0.3.0",
"set-value": "^0.3.3",
"strip-color": "^0.1.0",
"use": "^1.1.2"
},
"devDependencies": {
"verb": "~0.1.20"
"base": "^0.7.9",
"base-logger": "^0.1.0",
"base-option": "^0.6.2",
"capture-stream": "^0.1.2",
"gulp": "^3.9.1",
"gulp-eslint": "^2.0.0",
"gulp-istanbul": "^0.10.3",
"gulp-mocha": "^2.2.0",
"minimist": "^1.2.0"
},
"engines": {
"node": ">=0.10.0",
"npm": ">=1.2.10"
},
"keywords": [
"logging",
"256",
"ansi",
"chalk",
"cli",
"color",
"colors",
"colour",
"command",
"command-line",
"console",
"formatting",
"line",
"log",
"logger",
"terminal",
"command",
"logging",
"message",
"messages",
"command line"
]
"rgb",
"shell",
"string",
"styles",
"terminal",
"text",
"tty",
"xterm"
],
"verb": {
"toc": true,
"layout": "default",
"tasks": [
"readme"
],
"related": {
"list": [
"base",
"base-logger",
"log-events"
]
},
"reflinks": [
"strip-ansi"
]
}
}

@@ -1,14 +0,143 @@

# verbalize [![NPM version](https://badge.fury.io/js/verbalize.png)](http://badge.fury.io/js/verbalize)
# verbalize [![NPM version](https://img.shields.io/npm/v/verbalize.svg)](https://www.npmjs.com/package/verbalize) [![Build Status](https://img.shields.io/travis/jonschlinkert/verbalize.svg)](https://travis-ci.org/jonschlinkert/verbalize)
> A lightweight command line logging utility, with verbose mode and colors by chalk.
> A pluggable logging utility with built-in colors, styles, and modes.
_(WIP)_
## TOC
- [Install](#install)
- [Usage](#usage)
- [API](#api)
- [Related projects](#related-projects)
- [Contributing](#contributing)
- [Building docs](#building-docs)
- [Running tests](#running-tests)
- [Author](#author)
- [License](#license)
## Install with [npm](npmjs.org)
```bash
npm i -g verbalize --save-dev
_(TOC generated by [verb](https://github.com/verbose/verb) using [markdown-toc](https://github.com/jonschlinkert/markdown-toc))_
## Install
Install with [npm](https://www.npmjs.com/):
```sh
$ npm install verbalize --save
```
## Usage
```js
var Verbalize = require('verbalize');
```
## API
### [Verbalize](index.js#L30)
Create an instance of `Verbalize` with the given `options`.
**Params**
* `options` **{Object}**
**Example**
```js
var logger = new Verbalize({verbose: true});
```
### [._format](index.js#L75)
Base formatting.
* `returns` **{String}** `msg`
### [._write](index.js#L91)
Write to the console.
* `returns` **{String}** `msg`
### [._writeln](index.js#L104)
Write to the console followed by a newline. A blank
line is returned if no value is passed.
* `returns` **{String}** `msg`
### [.write](index.js#L115)
Write formatted output.
* `returns` **{String}**
### [.writeln](index.js#L126)
Write formatted output followed by a newline.
* `returns` **{String}**
### [.sep](index.js#L137)
Style a basic separator.
* `returns` **{String}**
### [.stylize](index.js#L150)
Stylize the given `msg` with the specified `color`.
**Params**
* `color` **{String}**: The name of the color to use
* `msg` **{String}**: The args to stylize.
* `returns` **{String}**
### [.define](index.js#L187)
Define non-enumerable property `key` with the given value.
**Params**
* `key` **{String}**
* `value` **{any}**
* `returns` **{String}**
### [Verbalize.create](index.js#L214)
Static method to create a new constructor. This is useful in tests and places where the original prototype should not be updated.
**Example**
```js
var MyLogger = Verbalize.create();
var logger = new MyLogger();
```
## Related projects
* [base](https://www.npmjs.com/package/base): base is the foundation for creating modular, unit testable and highly pluggable node.js applications, starting… [more](https://www.npmjs.com/package/base) | [homepage](https://github.com/node-base/base)
* [base-logger](https://www.npmjs.com/package/base-logger): Add a verbalize logger to your base application. | [homepage](https://github.com/node-base/base-logger)
* [log-events](https://www.npmjs.com/package/log-events): Create custom, chainable logging methods that emit log events when called. | [homepage](https://github.com/doowb/log-events)
## Contributing
Pull requests and stars are always welcome. For bugs and feature requests, [please create an issue](https://github.com/jonschlinkert/verbalize/issues/new).
## Building docs
Generate readme and API documentation with [verb][]:
```sh
$ npm install verb && npm run docs
```
Or, if [verb][] is installed globally:
```sh
$ verb
```
## Running tests
Install dev dependencies:
```sh
$ npm install -d && npm test
```
## Author
**Jon Schlinkert**

@@ -20,7 +149,10 @@

## License
Copyright (c) 2014 Jon Schlinkert, contributors.
Released under the MIT license
Copyright © 2016 [Jon Schlinkert](https://github.com/jonschlinkert)
Released under the [MIT license](https://github.com/jonschlinkert/verbalize/blob/master/LICENSE).
***
_This file was generated by [verb-cli](https://github.com/assemble/verb-cli) on March 25, 2014._
_This file was generated by [verb](https://github.com/verbose/verb), v0.9.0, on March 06, 2016._
[strip-ansi]: https://github.com/chalk/strip-ansi
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc