This commit is contained in:
chrosey
2017-09-13 07:52:34 +02:00
parent a1f16c37f4
commit 2340b0226b
24621 changed files with 2912161 additions and 149 deletions
+147
View File
@@ -0,0 +1,147 @@
'use strict';
var EventEmitter = require('events').EventEmitter;
var fmt = require('util').format;
var inherits = require('util').inherits;
var chalk = require('chalk');
var consoleStream = require('console-stream');
var lpadAlign = require('lpad-align');
/**
* Initialize a new `Squeak`
*
* @param {Object} opts
* @api public
*/
function Squeak(opts) {
if (!(this instanceof Squeak)) {
return new Squeak(opts);
}
EventEmitter.call(this);
this.opts = opts || {};
this.align = this.opts.align !== false;
this.indent = this.opts.indent || 2;
this.separator = this.opts.separator || ' : ';
this.stream = this.opts.stream || process.stderr || consoleStream();
this.types = [];
}
inherits(Squeak, EventEmitter);
module.exports = Squeak;
/**
* Write args to stream
*
* @api public
*/
Squeak.prototype.write = function () {
this.log([].slice.call(arguments));
return this;
};
/**
* Write args and new line to stream
*
* @api public
*/
Squeak.prototype.writeln = function () {
this.log([].slice.call(arguments));
this.stream.write('\n');
return this;
};
/**
* Pad and write args to stream
*
* @api public
*/
Squeak.prototype.writelpad = function () {
var args = [].slice.call(arguments);
var pad = new Array(this.indent + 1).join(' ');
if (args.length) {
args[0] = pad + args[0];
}
this.log(args);
return this;
};
/**
* Add type
*
* @param {String} type
* @param {Object} opts
* @param {Function} cb
* @api public
*/
Squeak.prototype.type = function (type, opts, cb) {
if (!cb && typeof opts === 'function') {
cb = opts;
opts = {};
}
opts = opts || {};
opts.color = opts.color || 'reset';
opts.prefix = opts.prefix || type;
this.types.push(opts.prefix);
this[type] = function () {
this.log([].slice.call(arguments), opts);
if (cb) {
cb();
}
};
return this;
};
/**
* End
*
* @param {Function} cb
* @api public
*/
Squeak.prototype.end = function (cb) {
this.stream.write('\n');
if (cb) {
cb();
}
return this;
};
/**
* Log
*
* @param {Array} args
* @param {Object} opts
* @api private
*/
Squeak.prototype.log = function (args, opts) {
opts = opts || {};
var msg = [fmt.apply(null, args)];
var color = opts.color;
var prefix = opts.prefix;
if (prefix) {
var arr = this.align ? this.types : [prefix];
msg.unshift(chalk[color](lpadAlign(prefix, arr, this.indent)));
}
this.stream.write(msg.join(this.separator));
this.stream.write('\n');
return this;
};
+21
View File
@@ -0,0 +1,21 @@
The MIT License (MIT)
Copyright (c) Kevin Mårtensson <kevinmartensson@gmail.com>
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.
+95
View File
@@ -0,0 +1,95 @@
{
"_args": [
[
{
"raw": "squeak@^1.0.0",
"scope": null,
"escapedName": "squeak",
"name": "squeak",
"rawSpec": "^1.0.0",
"spec": ">=1.0.0 <2.0.0",
"type": "range"
},
"c:\\xampp\\htdocs\\laravel\\node_modules\\logalot"
]
],
"_from": "squeak@>=1.0.0 <2.0.0",
"_id": "squeak@1.3.0",
"_inCache": true,
"_location": "/squeak",
"_nodeVersion": "4.1.2",
"_npmUser": {
"name": "kevva",
"email": "kevinmartensson@gmail.com"
},
"_npmVersion": "3.3.3",
"_phantomChildren": {},
"_requested": {
"raw": "squeak@^1.0.0",
"scope": null,
"escapedName": "squeak",
"name": "squeak",
"rawSpec": "^1.0.0",
"spec": ">=1.0.0 <2.0.0",
"type": "range"
},
"_requiredBy": [
"/logalot"
],
"_resolved": "https://registry.npmjs.org/squeak/-/squeak-1.3.0.tgz",
"_shasum": "33045037b64388b567674b84322a6521073916c3",
"_shrinkwrap": null,
"_spec": "squeak@^1.0.0",
"_where": "c:\\xampp\\htdocs\\laravel\\node_modules\\logalot",
"author": {
"name": "Kevin Mårtensson",
"email": "kevinmartensson@gmail.com",
"url": "https://github.com/kevva"
},
"bugs": {
"url": "https://github.com/kevva/squeak/issues"
},
"dependencies": {
"chalk": "^1.0.0",
"console-stream": "^0.1.1",
"lpad-align": "^1.0.1"
},
"description": "A tiny stream log",
"devDependencies": {
"ava": "^0.0.4"
},
"directories": {},
"dist": {
"shasum": "33045037b64388b567674b84322a6521073916c3",
"tarball": "https://registry.npmjs.org/squeak/-/squeak-1.3.0.tgz"
},
"engines": {
"node": ">=0.10.0"
},
"files": [
"index.js"
],
"gitHead": "5fd68a6e256015bc2bed80a89047629fb6ebfd41",
"homepage": "https://github.com/kevva/squeak#readme",
"keywords": [
"log"
],
"license": "MIT",
"maintainers": [
{
"name": "kevva",
"email": "kevinmartensson@gmail.com"
}
],
"name": "squeak",
"optionalDependencies": {},
"readme": "ERROR: No README data found!",
"repository": {
"type": "git",
"url": "git+https://github.com/kevva/squeak.git"
},
"scripts": {
"test": "node test.js"
},
"version": "1.3.0"
}
+160
View File
@@ -0,0 +1,160 @@
# squeak [![Build Status](http://img.shields.io/travis/kevva/squeak.svg?style=flat)](https://travis-ci.org/kevva/squeak)
> A tiny stream log
![](https://cloud.githubusercontent.com/assets/709159/5165451/f0ca124e-73e4-11e4-8a49-9e278b7aff16.png)
## Install
```
$ npm install --save squeak
```
## Usage
```js
var Squeak = require('squeak');
var log = new Squeak()
.type('info')
.type('success', {color: 'green'})
.type('warn', {color: 'yellow'})
.type('error', {color: 'red'}, function () {
log.end();
process.exit(1);
});
log.info('this is a info message');
log.success('this is a success message');
log.warn('this is a warning');
log.error(new Error('this is an error').stack);
/*
info : this is a info message
success : this is a success message
warn : this is a warning
error : this is an error
at ChildProcess.exithandler (child_process.js:648:15)
at ChildProcess.emit (events.js:98:17)
*/
```
You can also customize the different types to use a custom prefix using the
`prefix` option:
```js
var Squeak = require('squeak');
var log = new Squeak({separator: ' '})
.type('success', {color: 'green', prefix: '✔'})
.type('warn', {color: 'yellow', prefix: '⚠'});
log.success('this is a success message');
log.warn('this is a warning');
/*
✔ this is a success message
⚠ this is a warning
*/
```
## API
### new Squeak(options)
Creates a new `Squeak` instance.
#### options.align
Type: `boolean`
Default: `true`
Whether to align the prefixes or not. E.g:
```sh
foo : hello
foobar : world
```
#### options.indent
Type: `number`
Default: `2`
Sets the indentation.
#### options.separator
Type: `string`
Default: ` : `
Customize the separator between the `prefix` and the message.
#### options.stream
Type: `stream`
Default: `process.stderr`
Which `stream` to write to.
### .write(args)
Type: `string`
Writes to `options.stream`, using `process.stderr` by default.
### .writeln(args)
Type: `string`
Same as `.write()` but with a new line.
### .writelpad(args)
Type: `string`
Same as `.write()` but with padding.
### .type(type, options, callback)
Adds a type.
#### type
Type: `string`
The name of the type. Will be used as `prefix` by default.
#### options.color
Type: `string`
Sets the prefix color. Supported colors can be found [here](https://github.com/sindresorhus/ansi-styles#colors).
#### options.prefix
Type: `string`
Sets the `type` prefix. Uses `type` by default.
#### callback
Type: `function`
An optional callback to be called when the `type` is called.
### .emit(event, data)
Emits an event.
### .end(callback)
Type: `function`
Writes a newline and executes an optional callback function.
## License
MIT © [Kevin Mårtensson](https://github.com/kevva)