├── .editorconfig ├── .eslintrc.json ├── .gitattributes ├── .gitignore ├── .travis.yml ├── .verb.md ├── LICENSE ├── README.md ├── examples.js ├── index.js ├── package.json └── test.js /.editorconfig: -------------------------------------------------------------------------------- 1 | root = true 2 | 3 | [*] 4 | indent_style = space 5 | end_of_line = lf 6 | charset = utf-8 7 | indent_size = 2 8 | trim_trailing_whitespace = true 9 | insert_final_newline = true 10 | 11 | [{,**/}{actual,fixtures,expected,templates}/**/*.*] 12 | trim_trailing_whitespace = false 13 | insert_final_newline = false 14 | -------------------------------------------------------------------------------- /.eslintrc.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": [ 3 | "eslint:recommended" 4 | ], 5 | 6 | "env": { 7 | "browser": false, 8 | "es6": true, 9 | "node": true, 10 | "mocha": true 11 | }, 12 | 13 | "parserOptions":{ 14 | "ecmaVersion": 9, 15 | "sourceType": "module", 16 | "ecmaFeatures": { 17 | "modules": true, 18 | "experimentalObjectRestSpread": true 19 | } 20 | }, 21 | 22 | "globals": { 23 | "document": false, 24 | "navigator": false, 25 | "window": false 26 | }, 27 | 28 | "rules": { 29 | "accessor-pairs": 2, 30 | "arrow-spacing": [2, { "before": true, "after": true }], 31 | "block-spacing": [2, "always"], 32 | "brace-style": [2, "1tbs", { "allowSingleLine": true }], 33 | "comma-dangle": [2, "never"], 34 | "comma-spacing": [2, { "before": false, "after": true }], 35 | "comma-style": [2, "last"], 36 | "constructor-super": 2, 37 | "curly": [2, "multi-line"], 38 | "dot-location": [2, "property"], 39 | "eol-last": 2, 40 | "eqeqeq": [2, "allow-null"], 41 | "generator-star-spacing": [2, { "before": true, "after": true }], 42 | "handle-callback-err": [2, "^(err|error)$" ], 43 | "indent": [2, 2, { "SwitchCase": 1 }], 44 | "key-spacing": [2, { "beforeColon": false, "afterColon": true }], 45 | "keyword-spacing": [2, { "before": true, "after": true }], 46 | "new-cap": [2, { "newIsCap": true, "capIsNew": false }], 47 | "new-parens": 2, 48 | "no-array-constructor": 2, 49 | "no-caller": 2, 50 | "no-class-assign": 2, 51 | "no-cond-assign": 2, 52 | "no-const-assign": 2, 53 | "no-control-regex": 2, 54 | "no-debugger": 2, 55 | "no-delete-var": 2, 56 | "no-dupe-args": 2, 57 | "no-dupe-class-members": 2, 58 | "no-dupe-keys": 2, 59 | "no-duplicate-case": 2, 60 | "no-empty-character-class": 2, 61 | "no-eval": 2, 62 | "no-ex-assign": 2, 63 | "no-extend-native": 2, 64 | "no-extra-bind": 2, 65 | "no-extra-boolean-cast": 2, 66 | "no-extra-parens": [2, "functions"], 67 | "no-fallthrough": 2, 68 | "no-floating-decimal": 2, 69 | "no-func-assign": 2, 70 | "no-implied-eval": 2, 71 | "no-inner-declarations": [2, "functions"], 72 | "no-invalid-regexp": 2, 73 | "no-irregular-whitespace": 2, 74 | "no-iterator": 2, 75 | "no-label-var": 2, 76 | "no-labels": 2, 77 | "no-lone-blocks": 2, 78 | "no-mixed-spaces-and-tabs": 2, 79 | "no-multi-spaces": 2, 80 | "no-multi-str": 2, 81 | "no-multiple-empty-lines": [2, { "max": 1 }], 82 | "no-native-reassign": 0, 83 | "no-negated-in-lhs": 2, 84 | "no-new": 2, 85 | "no-new-func": 2, 86 | "no-new-object": 2, 87 | "no-new-require": 2, 88 | "no-new-wrappers": 2, 89 | "no-obj-calls": 2, 90 | "no-octal": 2, 91 | "no-octal-escape": 2, 92 | "no-proto": 0, 93 | "no-redeclare": 2, 94 | "no-regex-spaces": 2, 95 | "no-return-assign": 2, 96 | "no-self-compare": 2, 97 | "no-sequences": 2, 98 | "no-shadow-restricted-names": 2, 99 | "no-spaced-func": 2, 100 | "no-sparse-arrays": 2, 101 | "no-this-before-super": 2, 102 | "no-throw-literal": 2, 103 | "no-trailing-spaces": 0, 104 | "no-undef": 2, 105 | "no-undef-init": 2, 106 | "no-unexpected-multiline": 2, 107 | "no-unneeded-ternary": [2, { "defaultAssignment": false }], 108 | "no-unreachable": 2, 109 | "no-unused-vars": [2, { "vars": "all", "args": "none" }], 110 | "no-useless-call": 0, 111 | "no-with": 2, 112 | "one-var": [0, { "initialized": "never" }], 113 | "operator-linebreak": [0, "after", { "overrides": { "?": "before", ":": "before" } }], 114 | "padded-blocks": [0, "never"], 115 | "quotes": [2, "single", "avoid-escape"], 116 | "radix": 2, 117 | "semi": [2, "always"], 118 | "semi-spacing": [2, { "before": false, "after": true }], 119 | "space-before-blocks": [2, "always"], 120 | "space-before-function-paren": [2, "never"], 121 | "space-in-parens": [2, "never"], 122 | "space-infix-ops": 2, 123 | "space-unary-ops": [2, { "words": true, "nonwords": false }], 124 | "spaced-comment": [0, "always", { "markers": ["global", "globals", "eslint", "eslint-disable", "*package", "!", ","] }], 125 | "use-isnan": 2, 126 | "valid-typeof": 2, 127 | "wrap-iife": [2, "any"], 128 | "yoda": [2, "never"] 129 | } 130 | } 131 | -------------------------------------------------------------------------------- /.gitattributes: -------------------------------------------------------------------------------- 1 | # Enforce Unix newlines 2 | * text eol=lf 3 | 4 | # binaries 5 | *.ai binary 6 | *.psd binary 7 | *.jpg binary 8 | *.gif binary 9 | *.png binary 10 | *.jpeg binary 11 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # always ignore files 2 | *.DS_Store 3 | *.sublime-* 4 | 5 | # test related, or directories generated by tests 6 | test/actual 7 | actual 8 | coverage 9 | 10 | # npm 11 | node_modules 12 | npm-debug.log 13 | 14 | # misc 15 | _gh_pages 16 | benchmark 17 | bower_components 18 | vendor 19 | temp 20 | tmp 21 | TODO.md 22 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | sudo: false 2 | os: 3 | - linux 4 | - osx 5 | language: node_js 6 | node_js: 7 | - node 8 | - '10' 9 | - '9' 10 | - '8.6' 11 | -------------------------------------------------------------------------------- /.verb.md: -------------------------------------------------------------------------------- 1 | ## Usage 2 | 3 | ```js 4 | const log = require('{%= name %}'); 5 | ``` 6 | 7 | ## API 8 | 9 | {%= apidocs("index.js") %} 10 | 11 | ### Colors 12 | 13 | Available colors from [ansi-colors][]: 14 | 15 | ## Changes 16 | 17 | **v0.2.0 (2016-07-16)** 18 | 19 | - `removed`: all spinner methods 20 | 21 | **v0.1.5 (2016-07-16)** 22 | 23 | - `added`: `.header` method 24 | - `fixed`: `.ok` method, so that whitespace is respected 25 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2016, Jon Schlinkert. 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in 13 | all copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 21 | THE SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # log-utils [![NPM version](https://img.shields.io/npm/v/log-utils.svg?style=flat)](https://www.npmjs.com/package/log-utils) [![NPM monthly downloads](https://img.shields.io/npm/dm/log-utils.svg?style=flat)](https://npmjs.org/package/log-utils) [![NPM total downloads](https://img.shields.io/npm/dt/log-utils.svg?style=flat)](https://npmjs.org/package/log-utils) [![Linux Build Status](https://img.shields.io/travis/jonschlinkert/log-utils.svg?style=flat&label=Travis)](https://travis-ci.org/jonschlinkert/log-utils) 2 | 3 | > Tiny wrapper around ansi-colors to add colored symbols and a timestamp. 4 | 5 | Please consider following this project's author, [Jon Schlinkert](https://github.com/jonschlinkert), and consider starring the project to show your :heart: and support. 6 | 7 | ## Install 8 | 9 | Install with [npm](https://www.npmjs.com/): 10 | 11 | ```sh 12 | $ npm install --save log-utils 13 | ``` 14 | 15 | ## Usage 16 | 17 | ```js 18 | const log = require('log-utils'); 19 | ``` 20 | 21 | ## API 22 | 23 | ### [.error](index.js#L23) 24 | 25 | Get a red error symbol. 26 | 27 | **Example** 28 | 29 | ```js 30 | console.log(log.error); //=> ✖ 31 | ``` 32 | 33 | ### [.info](index.js#L35) 34 | 35 | Get a cyan info symbol. 36 | 37 | **Example** 38 | 39 | ```js 40 | console.log(log.info); //=> ℹ 41 | ``` 42 | 43 | ### [.success](index.js#L47) 44 | 45 | Get a green success symbol. 46 | 47 | **Example** 48 | 49 | ```js 50 | console.log(log.success); //=> ✔ 51 | ``` 52 | 53 | ### [.warning](index.js#L59) 54 | 55 | Get a yellow warning symbol. 56 | 57 | **Example** 58 | 59 | ```js 60 | console.log(log.warning); //=> ⚠ 61 | ``` 62 | 63 | ### [.timestamp](index.js#L71) 64 | 65 | Get a formatted timestamp. 66 | 67 | **Example** 68 | 69 | ```js 70 | console.log(log.timestamp); //=> [15:27:46] 71 | ``` 72 | 73 | ### [.ok](index.js#L93) 74 | 75 | Returns a formatted string prefixed by a green check. 76 | 77 | **Example** 78 | 79 | ```js 80 | console.log(log.ok(' foo')); 81 | console.log(log.ok(' foo')); 82 | console.log(log.ok(' foo')); 83 | console.log(log.ok('foo')); 84 | // Results in: 85 | // ✔ foo 86 | // ✔ foo 87 | // ✔ foo 88 | // ✔ foo 89 | ``` 90 | 91 | ### [.heading](index.js#L112) 92 | 93 | Make the given text bold and underlined. 94 | 95 | **Example** 96 | 97 | ```js 98 | console.log(log.heading('foo')); 99 | // or 100 | console.log(log.heading('foo', 'bar')); 101 | ``` 102 | 103 | ### Colors 104 | 105 | Available colors from [ansi-colors](https://github.com/doowb/ansi-colors): 106 | 107 | ## Changes 108 | 109 | **v0.2.0 (2016-07-16)** 110 | 111 | * `removed`: all spinner methods 112 | 113 | **v0.1.5 (2016-07-16)** 114 | 115 | * `added`: `.header` method 116 | * `fixed`: `.ok` method, so that whitespace is respected 117 | 118 | ## About 119 | 120 |
121 | Contributing 122 | 123 | Pull requests and stars are always welcome. For bugs and feature requests, [please create an issue](../../issues/new). 124 | 125 |
126 | 127 |
128 | Running Tests 129 | 130 | Running and reviewing unit tests is a great way to get familiarized with a library and its API. You can install dependencies and run tests with the following command: 131 | 132 | ```sh 133 | $ npm install && npm test 134 | ``` 135 | 136 |
137 | 138 |
139 | Building docs 140 | 141 | _(This project's readme.md is generated by [verb](https://github.com/verbose/verb-generate-readme), please don't edit the readme directly. Any changes to the readme must be made in the [.verb.md](.verb.md) readme template.)_ 142 | 143 | To generate the readme, run the following command: 144 | 145 | ```sh 146 | $ npm install -g verbose/verb#dev verb-generate-readme && verb 147 | ``` 148 | 149 |
150 | 151 | ### Related projects 152 | 153 | You might also be interested in these projects: 154 | 155 | [ansi-colors](https://www.npmjs.com/package/ansi-colors): Easily add ANSI colors to your text and symbols in the terminal. A faster drop-in… [more](https://github.com/doowb/ansi-colors) | [homepage](https://github.com/doowb/ansi-colors "Easily add ANSI colors to your text and symbols in the terminal. A faster drop-in replacement for chalk, kleur and turbocolor (without the dependencies and rendering bugs).") 156 | 157 | ### Contributors 158 | 159 | | **Commits** | **Contributor** | 160 | | --- | --- | 161 | | 23 | [jonschlinkert](https://github.com/jonschlinkert) | 162 | | 5 | [doowb](https://github.com/doowb) | 163 | 164 | ### Author 165 | 166 | **Jon Schlinkert** 167 | 168 | * [GitHub Profile](https://github.com/jonschlinkert) 169 | * [Twitter Profile](https://twitter.com/jonschlinkert) 170 | * [LinkedIn Profile](https://linkedin.com/in/jonschlinkert) 171 | 172 | ### License 173 | 174 | Copyright © 2018, [Jon Schlinkert](https://github.com/jonschlinkert). 175 | Released under the [MIT License](LICENSE). 176 | 177 | *** 178 | 179 | _This file was generated by [verb-generate-readme](https://github.com/verbose/verb-generate-readme), v0.8.0, on November 17, 2018._ -------------------------------------------------------------------------------- /examples.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | const log = require('./'); 4 | 5 | for (let key in log) { 6 | if (typeof log[key] === 'string') { 7 | console.log(log[key], `${key}`); 8 | } 9 | } 10 | 11 | console.log(log.heading('foo', 'bar')); 12 | // console.log(log.timestamp); 13 | // console.log(log.symbols); 14 | console.log(log.ok(' foo')); 15 | console.log(log.ok(' foo')); 16 | console.log(log.ok(' foo')); 17 | console.log(log.ok('foo')); 18 | -------------------------------------------------------------------------------- /index.js: -------------------------------------------------------------------------------- 1 | /*! 2 | * log-utils 3 | * Copyright (c) 2016-present, Jon Schlinkert. 4 | * Licensed under the MIT License. 5 | */ 6 | 7 | 'use strict'; 8 | 9 | const timestamp = require('time-stamp'); 10 | const colors = require('ansi-colors'); 11 | const log = console.log; 12 | 13 | /** 14 | * Get a red error symbol. 15 | * 16 | * ```js 17 | * console.log(log.error); //=> ✖ 18 | * ``` 19 | * @name .error 20 | * @api public 21 | */ 22 | 23 | getter(log, 'error', () => colors.red(colors.symbols.cross)); 24 | 25 | /** 26 | * Get a cyan info symbol. 27 | * 28 | * ```js 29 | * console.log(log.info); //=> ℹ 30 | * ``` 31 | * @name .info 32 | * @api public 33 | */ 34 | 35 | getter(log, 'info', () => colors.cyan(colors.symbols.info)); 36 | 37 | /** 38 | * Get a green success symbol. 39 | * 40 | * ```js 41 | * console.log(log.success); //=> ✔ 42 | * ``` 43 | * @name .success 44 | * @api public 45 | */ 46 | 47 | getter(log, 'success', () => colors.green(colors.symbols.check)); 48 | 49 | /** 50 | * Get a yellow warning symbol. 51 | * 52 | * ```js 53 | * console.log(log.warning); //=> ⚠ 54 | * ``` 55 | * @name .warning 56 | * @api public 57 | */ 58 | 59 | getter(log, 'warning', () => colors.yellow(colors.symbols.warning)); 60 | 61 | /** 62 | * Get a formatted timestamp. 63 | * 64 | * ```js 65 | * console.log(log.timestamp); //=> [15:27:46] 66 | * ``` 67 | * @name .timestamp 68 | * @api public 69 | */ 70 | 71 | getter(log, 'timestamp', () => { 72 | return '[' + colors.gray(timestamp('HH:mm:ss')) + ']'; 73 | }); 74 | 75 | /** 76 | * Returns a formatted string prefixed by a green check. 77 | * 78 | * ```js 79 | * console.log(log.ok(' foo')); 80 | * console.log(log.ok(' foo')); 81 | * console.log(log.ok(' foo')); 82 | * console.log(log.ok('foo')); 83 | * // Results in: 84 | * // ✔ foo 85 | * // ✔ foo 86 | * // ✔ foo 87 | * // ✔ foo 88 | * ``` 89 | * @name .ok 90 | * @api public 91 | */ 92 | 93 | log.ok = str => { 94 | let ok = colors.green(colors.symbols.check); 95 | return str.replace(/^(\s*)(.*?)$/, (m, s, v) => { 96 | return s + ok + ' ' + v; 97 | }); 98 | }; 99 | 100 | /** 101 | * Make the given text bold and underlined. 102 | * 103 | * ```js 104 | * console.log(log.heading('foo')); 105 | * // or 106 | * console.log(log.heading('foo', 'bar')); 107 | * ``` 108 | * @name .heading 109 | * @api public 110 | */ 111 | 112 | log.heading = (...args) => { 113 | let str = args.filter(v => v !== void 0).map(String).join(' '); 114 | return colors.bold.underline(str); 115 | }; 116 | 117 | /** 118 | * Utility for defining a getter 119 | */ 120 | 121 | function getter(obj, prop, fn) { 122 | Object.defineProperty(obj, prop, { 123 | configurable: true, 124 | enumerable: true, 125 | get: fn 126 | }); 127 | } 128 | 129 | /** 130 | * Expose `log` 131 | */ 132 | 133 | log.__proto__ = colors; 134 | module.exports = log; 135 | 136 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "log-utils", 3 | "description": "Tiny wrapper around ansi-colors to add colored symbols and a timestamp.", 4 | "version": "1.0.0", 5 | "homepage": "https://github.com/jonschlinkert/log-utils", 6 | "author": "Jon Schlinkert (https://github.com/jonschlinkert)", 7 | "repository": "jonschlinkert/log-utils", 8 | "bugs": { 9 | "url": "https://github.com/jonschlinkert/log-utils/issues" 10 | }, 11 | "license": "MIT", 12 | "files": [ 13 | "index.js" 14 | ], 15 | "main": "index.js", 16 | "engines": { 17 | "node": ">=8.6" 18 | }, 19 | "scripts": { 20 | "test": "mocha" 21 | }, 22 | "dependencies": { 23 | "ansi-colors": "^3.2.1", 24 | "time-stamp": "^2.2.0" 25 | }, 26 | "devDependencies": { 27 | "gulp-format-md": "^1.0.0", 28 | "mocha": "^5.2.0" 29 | }, 30 | "keywords": [ 31 | "ansi", 32 | "chalk", 33 | "check", 34 | "checkmark", 35 | "cli", 36 | "color", 37 | "colors", 38 | "command", 39 | "console", 40 | "cyan", 41 | "error", 42 | "green", 43 | "info", 44 | "line", 45 | "log", 46 | "red", 47 | "stamp", 48 | "success", 49 | "terminal", 50 | "time", 51 | "time-stamp", 52 | "timestamp", 53 | "util", 54 | "utility", 55 | "utils", 56 | "warn", 57 | "warning", 58 | "yellow" 59 | ], 60 | "verb": { 61 | "layout": "default", 62 | "plugins": [ 63 | "gulp-format-md" 64 | ], 65 | "related": { 66 | "list": [ 67 | "ansi-colors" 68 | ] 69 | } 70 | } 71 | } 72 | -------------------------------------------------------------------------------- /test.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | require('mocha'); 4 | const assert = require('assert'); 5 | const log = require('./'); 6 | 7 | describe('log-utils', function() { 8 | it('should export a function', function() { 9 | assert(log); 10 | assert.equal(typeof log, 'function'); 11 | }); 12 | 13 | it('should expose getters', function() { 14 | assert(log.symbols); 15 | assert(log.symbols.hasOwnProperty('check')); 16 | 17 | assert(log.symbols.hasOwnProperty('cross')); 18 | assert(log.symbols.hasOwnProperty('check')); 19 | assert(log.symbols.hasOwnProperty('info')); 20 | assert(log.symbols.hasOwnProperty('warning')); 21 | 22 | assert.equal(typeof log.green, 'function'); 23 | assert.equal(typeof log.cyan, 'function'); 24 | assert.equal(typeof log.yellow, 'function'); 25 | assert.equal(typeof log.red, 'function'); 26 | 27 | assert(log.hasOwnProperty('error')); 28 | assert(log.hasOwnProperty('info')); 29 | assert(log.hasOwnProperty('success')); 30 | assert(log.hasOwnProperty('warning')); 31 | }); 32 | }); 33 | --------------------------------------------------------------------------------