项目作者: BlackB1RD-Development

项目描述 :
An easy to use, powerful and multi-functionality tools-kit library for NodeJS written entirely in JavaScript.
高级语言: JavaScript
项目地址: git://github.com/BlackB1RD-Development/tools-kit.git
创建时间: 2019-04-15T16:10:38Z
项目社区:https://github.com/BlackB1RD-Development/tools-kit

开源协议:MIT License

下载



Tools-Kit Logo


An easy to use, powerful and multi-functionality tools-kit library for NodeJS written entirely in JavaScript.





npm


release


downloads


node


license


Coverage Status


Build





Code Style








© Tools-Kit By BlackB1RD-Development (Author: @RealBlackB1RD). All rights reserved ©

Features

  • A Hastebin Client that can post and fetch code easily from Hastebin.
  • A Logger Manager that can log a styled and colored text into the console.
  • A Styles Manager that can transfer your simple text into a styled and modern one.
  • A collection of easy to use and useful functions.
  • Extremely configurable and debuggable.
  • Well documented.

Install

NPM Through GitHub

  1. npm install BlackB1RD-Development/tools-kit --save

NPM

  1. npm install tools-kit --save

Yarn

  1. yarn add tools-kit

Documentations

Read the Documentations for more information about each method.

Table of Content

Click to jump between class examples

Class Name Class Description
Hastebin Client Post and fetch code easily from Hastebin
Logger Manager Log a styled and colored text into the console
Styles Manager Transfer your simple text into a styled and modern one (Console support only)
Utilities A collection of easy to use and useful functions

Hastebin Client

With the Hastebin Client you can post and fetch code easily from Hastebin.

  1. const { logger, hastebin } = require('tools-kit');
  2. hastebin.post('var test = \'test\';\n\nconsole.log(test);', '.js')
  3. .then(async postRes => {
  4. logger.success({ tag: 'POST RES' }, postRes);
  5. // Console > [20/02/2020 - 00:00:00 | POST RES]: HastebinObject{}
  6. await hastebin.get(postRes.link)
  7. .then(getRes => {
  8. logger.success({ tag: 'GET RES' }, getRes);
  9. // Console > [20/02/2020 - 00:00:00 | GET RES]: HastebinObject{}
  10. })
  11. .catch(getErr => {
  12. logger.error({ tag: 'GET ERROR' }, getErr);
  13. // Console > [20/02/2020 - 00:00:00 | GET ERROR]: Error: Get Error
  14. });
  15. })
  16. .catch(postErr => {
  17. logger.error({ tag: 'POST ERROR' }, postErr);
  18. // Console > [20/02/2020 - 00:00:00 | POST ERROR]: Error: Post Error
  19. });

Logger Manager

With the Logger Manager you can log a styled and colored text into the console with pre made logging settings in each method.

  1. const { logger } = require('tools-kit');
  2. logger.log('content');
  3. // Console > [20/02/2020 - 00:00:00 | LOG]: content
  4. logger.important('Important log');
  5. // Console > [20/02/2020 - 00:00:00 | IMPORTANT]: Important log
  6. logger.success('Success log');
  7. // Console > [20/02/2020 - 00:00:00 | SUCCESS]: Success log
  8. logger.fatal('Fatal log');
  9. // Console > [20/02/2020 - 00:00:00 | FATAL]: Fatal log
  10. logger.trace('Trace log');
  11. // Console > [20/02/2020 - 00:00:00 | TRACE]: Trace log
  12. logger.error('Error log');
  13. // Console > [20/02/2020 - 00:00:00 | ERROR]: Error log
  14. logger.debug('Debug log');
  15. // Console > [20/02/2020 - 00:00:00 | DEBUG]: Debugging log
  16. logger.info('Information log');
  17. // Console > [20/02/2020 - 00:00:00 | INFO]: Information log
  18. logger.warn('Warning log');
  19. // Console > [20/02/2020 - 00:00:00 | WARN]: Warning log
  20. logger.figlet('FIGLET', 'LOG');
  21. /*
  22. Console > [20/02/2020 - 00:00:00 | FIGLET]: _____ ___ ____ _ _____ _____ _ ___ ____
  23. Console > [20/02/2020 - 00:00:00 | FIGLET]: | ___|_ _/ ___| | | ____|_ _| | | / _ \ / ___|
  24. Console > [20/02/2020 - 00:00:00 | FIGLET]: | |_ | | | _| | | _| | | | | | | | | | _
  25. Console > [20/02/2020 - 00:00:00 | FIGLET]: | _| | | |_| | |___| |___ | | | |__| |_| | |_| |
  26. Console > [20/02/2020 - 00:00:00 | FIGLET]: |_| |___\____|_____|_____| |_| |_____\___/ \____|
  27. Console > [20/02/2020 - 00:00:00 | FIGLET]:
  28. */

Using custom options:

  1. const { logger } = require('tools-kit');
  2. // Support custom logging options and rewriting of existing methods settings
  3. const scsSettings = {
  4. time: 'H:mm',
  5. tag: 'PUBLISH SUCCESS',
  6. format: (options) => {
  7. return `[${options.tag}]: Published ${options.content} successfully at ${options.time}`;
  8. }
  9. }, errSettings = {
  10. time: 'H:mm',
  11. tag: 'PUBLISH ERROR',
  12. format: (options) => {
  13. return `[${options.tag}]: Couldn't publish ${options.content} at ${options.time}`;
  14. }
  15. }, settings = {
  16. tag: 'PUBLISH API',
  17. format: (options) => {
  18. return `[${options.tag}]: Publish API ${options.content} | Last Check: ${options.time}`;
  19. }
  20. }, figSettings = {
  21. figlet: {
  22. font: 'Ghost',
  23. verticalLayout: 'default',
  24. horizontalLayout: 'default'
  25. },
  26. log: {
  27. name: 'figlet',
  28. options: {
  29. background: 'black',
  30. color: 'red',
  31. style: 'bold',
  32. type: 'log',
  33. time: 'MM/DD/YY',
  34. tag: true,
  35. format: (options) => {
  36. return !options.time && !options.tag ? options.content : !options.time ? `[${options.tag}]: ${options.content}` : !options.tag ? `[${options.time}]: ${options.content}` : `[${options.time} | ${options.tag}]: ${options.content}`;
  37. }
  38. }
  39. }
  40. }, image = {
  41. name: 'logo.png',
  42. size: '5MB'
  43. }, api = {
  44. message: 'Internal Server Error',
  45. code: '500'
  46. };
  47. logger.success(scsSettings, 'image named "%s" with a total size of %s', image.name, image.size);
  48. // Console > [PUBLISH SUCCESS]: Published image named "logo.png" with a total size of 5MB successfully at 20:00
  49. logger.error(errSettings, 'image named "%s" with a total size of %s', image.name, image.size);
  50. // Console > [PUBLISH ERROR]: Couldn't publish image named "logo.png" with a total size of 5MB at 20:00
  51. logger.info(settings, 'respond with %s status code and "%s" message', api.code, api.message);
  52. // Console > [PUBLISH API]: Publish API respond with 500 status code and "Internal Server Error" message | Last Check: 20/2/2020 - 20:00:00
  53. logger.log({ time: false }, 'log', 'no time');
  54. // Console > [LOG]: log no time
  55. logger.figlet(figSettings, 'Boo');
  56. /*
  57. Console > [20/02/2020 - 00:00:00 | FIGLET]: .-. .-')
  58. Console > [20/02/2020 - 00:00:00 | FIGLET]: \ ( OO )
  59. Console > [20/02/2020 - 00:00:00 | FIGLET]: ;-----.\ .-'),-----. .-'),-----.
  60. Console > [20/02/2020 - 00:00:00 | FIGLET]: | .-. | ( OO' .-. '( OO' .-. '
  61. Console > [20/02/2020 - 00:00:00 | FIGLET]: | '-' /_)/ | | | |/ | | | |
  62. Console > [20/02/2020 - 00:00:00 | FIGLET]: | .-. `. \_) | |\| |\_) | |\| |
  63. Console > [20/02/2020 - 00:00:00 | FIGLET]: | | \ | \ | | | | \ | | | |
  64. Console > [20/02/2020 - 00:00:00 | FIGLET]: | '--' / `' '-' ' `' '-' '
  65. Console > [20/02/2020 - 00:00:00 | FIGLET]: `------' `-----' `-----'
  66. */
  67. logger.log({ time: 'MM-DD-YY' }, 'log', 'custom time format');
  68. // Console > [02-20-2020 | LOG]: log custom time format
  69. logger.log({ tag: false }, 'log', 'no tag');
  70. // Console > [20/02/2020 - 00:00:00]: log no tag
  71. logger.log({ tag: 'CUSTOM TAG' }, 'log', 'custom tag');
  72. // Console > [20/02/2020 - 00:00:00 | CUSTOM TAG]: log custom tag
  73. logger.log({ time: false, tag: false }, 'log', 'no tag', 'no time');
  74. // Console > log no tag no time
  75. logger // Support chain logging
  76. .log({ tag: 'FIRST LOG' }, 'First content')
  77. .log({ tag: 'SECOND LOG' }, 'Second content')
  78. .log({ tag: 'THIRD LOG' }, 'Third content');
  79. /*
  80. Console > [20/02/2020 - 00:00:00 | FIRST LOG]: First content
  81. Console > [20/02/2020 - 00:00:00 | SECOND LOG]: Second content
  82. Console > [20/02/2020 - 00:00:00 | THIRD LOG]: Third content
  83. */

See more backgrounds, colors, styles & consoles types by clicking here

Styles Manager

With the Styles Manager you can transfer your simple text into a styled and modern one.

  1. const { logger, style } = require('tools-kit');
  2. logger.log({ tag: 'STYLE' },
  3. styles.bgGreen('testing %s', 'background'),
  4. styles.red('testing %s', 'color'),
  5. styles.underline('testing %s', 'style'),
  6. styles.bgGreen.red.underline('testing %s', 'a style chain')
  7. );
  8. // Console > [20/02/2020 - 00:00:00 | STYLE]: testing background testing color testing style testing a style chain
  9. logger.log({ tag: 'STYLE OBJECT' }, styles.stylify({ background: 'bgGreen' }, 'styled background'), 'normal background');
  10. // Console > [20/02/2020 - 00:00:00 | STYLE OBJECT]: styled background normal background
  11. logger.log({ tag: 'STYLE OBJECT' }, styles.stylify({ color: 'red' }, 'styled color'), 'normal color');
  12. // Console > [20/02/2020 - 00:00:00 | STYLE OBJECT]: styled color normal color
  13. logger.log({ tag: 'STYLE OBJECT' }, styles.stylify({ style: 'underline' }, 'styled style'), 'normal style');
  14. // Console > [20/02/2020 - 00:00:00 | STYLE OBJECT]: styled style normal style
  15. logger.log({ tag: 'STYLE OBJECT' }, styles.stylify({ background: 'bgGreen', color: 'red', style: 'underline' }, 'styled text'), 'normal text');
  16. // Console > [20/02/2020 - 00:00:00 | STYLE OBJECT]: styled text normal text
  17. logger.log({ tag: 'STYLE METHOD' }, styles.background('bgGreen', 'styled background'), 'normal style');
  18. // Console > [20/02/2020 - 00:00:00 | STYLE METHOD]: styled background normal style
  19. logger.log({ tag: 'STYLE METHOD' }, styles.color('red', 'styled color'), 'normal style');
  20. // Console > [20/02/2020 - 00:00:00 | STYLE METHOD]: styled color normal style
  21. logger.log({ tag: 'STYLE METHOD' }, styles.style('underline', 'styled style'), 'normal style');
  22. // Console > [20/02/2020 - 00:00:00 | STYLE METHOD]: styled style normal style
  23. logger.log({ tag: 'STYLE METHOD' }, styles.bgGreen.red.underline('styled text'), 'normal text');
  24. // Console > [20/02/2020 - 00:00:00 | STYLE METHOD]: styled text normal text
  25. const colors = [
  26. styles.rgb([255, 0, 0]),
  27. styles.hex('#ffff00'),
  28. styles.hsv([180, 100, 100]),
  29. styles.hsl([120, 100, 50]),
  30. styles.hwb([240, 0, 0]),
  31. styles.lab([35, 80, -104]),
  32. styles.xyz([59, 28, 97]),
  33. styles.lch([88, 90, 149]),
  34. styles.cmyk([100, 50, 0, 0]),
  35. styles.ansi16(12),
  36. styles.ansi256(250),
  37. styles.keyword('DeepSkyBlue')
  38. ];
  39. logger.log({ tag: 'CUSTOM MAP' }, styles.map('custom map styled-text', colors), 'normal text');
  40. // Console > [20/02/2020 - 00:00:00 | CUSTOM MAP]: custom map styled-text normal text

Using pre-made cool colors maps:

  1. const { logger, color } = require('tools-kit');
  2. logger.log({ tag: 'RAINBOW' }, styles.rainbow('rainbow styled-text'), 'normal text');
  3. // Console > [20/02/2020 - 00:00:00 | RAINBOW]: rainbow styled-text normal text
  4. logger.log({ tag: 'RANDOM' }, styles.random('random styled-text'), 'normal text');
  5. // Console > [20/02/2020 - 00:00:00 | RANDOM]: random styled-text normal text
  6. logger.log({ tag: 'ZEBRA' }, styles.zebra('zebra styled-text'), 'normal text');
  7. // Console > [20/02/2020 - 00:00:00 | ZEBRA]: zebra styled-text normal text

Utilities

With Tools-Kit Utilities you can use the functions that everyone uses in one simple line.

  1. const { logger, util } = require('tools-kit');
  2. logger.log({ tag: 'HAS?' }, util.has({}, 'name'));
  3. // Console > [20/02/2020 - 00:00:00 | HAS?]: false
  4. logger.log({ tag: 'HAS?' }, util.has([], 'name'));
  5. // Console > [20/02/2020 - 00:00:00 | HAS?]: false
  6. logger.log({ tag: 'HAS?' }, util.has({ name: 'test' }, 'name'));
  7. // Console > [20/02/2020 - 00:00:00 | HAS?]: true
  8. logger.log({ tag: 'HAS?' }, util.has({ name: 'test' }, 'test'));
  9. // Console > [20/02/2020 - 00:00:00 | HAS?]: false
  10. logger.log({ tag: 'HAS?' }, util.has({ name: 'test' }, 'name', 'test'));
  11. // Console > [20/02/2020 - 00:00:00 | HAS?]: true
  12. logger.log({ tag: 'HAS?' }, util.has({ name: 'test' }, 'name', 'not test'));
  13. // Console > [20/02/2020 - 00:00:00 | HAS?]: false
  14. logger.log({ tag: 'HAS?' }, util.has(['name', 'test'], 'name'));
  15. // Console > [20/02/2020 - 00:00:00 | HAS?]: true
  16. logger.log({ tag: 'HAS?' }, util.has(['test', 'not test'], 'name'));
  17. // Console > [20/02/2020 - 00:00:00 | HAS?]: false
  18. logger.log({ tag: 'HAS?' }, util.has([{ 'name': 'not test' }, { 'name': 'test' }], 'name'));
  19. // Console > [20/02/2020 - 00:00:00 | HAS?]: true
  20. logger.log({ tag: 'HAS?' }, util.has([{ 'name': 'not test' }, { 'name': 'test' }], 'test', 'name'));
  21. // Console > [20/02/2020 - 00:00:00 | HAS?]: false
  22. logger.log({ tag: 'HAS?' }, util.has([{ 'name': 'not test' }, { 'name': 'test' }], 'name', 'test'));
  23. // Console > [20/02/2020 - 00:00:00 | HAS?]: true
  24. logger.log({ tag: 'ARRAY?' }, util.isArray(new Array()));
  25. // Console > [20/02/2020 - 00:00:00 | ARRAY?]: true
  26. logger.log({ tag: 'ARRAY?' }, util.isArray(new Object()));
  27. // Console > [20/02/2020 - 00:00:00 | ARRAY?]: false
  28. logger.log({ tag: 'ARRAY?' }, util.isArray([]));
  29. // Console > [20/02/2020 - 00:00:00 | ARRAY?]: true
  30. logger.log({ tag: 'ARRAY?' }, util.isArray({}));
  31. // Console > [20/02/2020 - 00:00:00 | ARRAY?]: false
  32. logger.log({ tag: 'OBJECT?' }, util.isObject(new Object()));
  33. // Console > [20/02/2020 - 00:00:00 | OBJECT?]: true
  34. logger.log({ tag: 'OBJECT?' }, util.isObject(new Array()));
  35. // Console > [20/02/2020 - 00:00:00 | OBJECT?]: false
  36. logger.log({ tag: 'OBJECT?' }, util.isObject({}));
  37. // Console > [20/02/2020 - 00:00:00 | OBJECT?]: true
  38. logger.log({ tag: 'OBJECT?' }, util.isObject([]));
  39. // Console > [20/02/2020 - 00:00:00 | OBJECT?]: false
  40. logger.log({ tag: 'RANDOM ITEM' }, util.randomItem(['cat', 'dog', 'fish']));
  41. // Console > [20/02/2020 - 00:00:00 | RANDOM ITEM]: fish
  42. logger.log({ tag: 'RANDOM NUMBER' }, util.randomNumber(5, 10));
  43. // Console > [20/02/2020 - 00:00:00 | RANDOM NUMBER]: 8
  44. logger.log({ tag: 'RANDOM NUMBER' }, util.randomNumber(5, 10, false)); // Default is true
  45. // Console > [20/02/2020 - 00:00:00 | RANDOM NUMBER]: 9.478004123859458

Logger Options

options.background

  • bgBlack
  • bgGray
  • bgGrey
  • bgRed
  • bgGreen
  • bgYellow
  • bgBlue
  • bgMagenta
  • bgCyan
  • bgWhite

Light Backgrounds

  • bgLBlack
  • bgLRed
  • bgLGreen
  • bgLYellow
  • bgLBlue
  • bgLMagenta
  • bgLCyan
  • bgLWhite

Bright Backgrounds

  • bgBGray
  • bgBGrey
  • bgBRed
  • bgBGreen
  • bgBYellow
  • bgBBlue
  • bgBMagenta
  • bgBCyan
  • bgBWhite

options.colors

  • black
  • gray
  • grey
  • red
  • green
  • yellow
  • blue
  • magenta
  • cyan
  • white

Light Colors

  • lblack
  • lred
  • lgreen
  • lyellow
  • lblue
  • lmagenta
  • lcyan
  • lwhite

Bright Colors

  • bgray
  • bgrey
  • bred
  • bgreen
  • byellow
  • bblue
  • bmagenta
  • bcyan
  • bwhite

options.style

  • reset - Resets the current color to the default console color.
  • bold - Make the text bold.
  • dim - Emitting only a small amount of the text light.
  • italic - Make the text italic styled - Not widely supported
  • underline - Make the text underline styled - Not widely supported
  • inverse- Inverse the background and the foreground colors.
  • hidden - Prints the text, but makes it invisible.
  • strikethrough - Puts a horizontal line through the center of the text - Not widely supported

options.type

  • log - Prints to stdout with newline. Multiple arguments can be passed, with the first used as the primary message and all additional used as substitution values similar to printf(3) (the arguments are all passed to util.format()).
  • error - Prints to stderr with newline. Multiple arguments can be passed, with the first used as the primary message and all additional used as substitution values similar to printf(3) (the arguments are all passed to util.format()).
  • trace - Prints to stderr the string ‘Trace: ‘, followed by the util.format() formatted message and stack trace to the current position in the code.
  • debug- The console.debug() function is an alias for console.log().
  • info - The console.info() function is an alias for console.log().
  • warn - The console.warn() function is an alias for console.error().

options.time

The options.time can be either of this two

  • Boolean (true/false) - If to include the current time and date with the stock format when logging (Stock used moment format: DD/M/YYYY - H:mm:ss)
  • String - A custom moment time format to use when logging

options.tag

The options.tag can be either of this two

  • Boolean (true/false) - If to include the a tag when logging
  • String - A custom string value to use as a tag when logging (Case sensitive)

Author

Maintainers

See also the list of contributors who participated in this project.

Changelog

See the Changes Log for more information about each update.

License

FOSSA Status

Related Modules

  • supports-color — Detect whether a terminal supports color.
  • color-convert — Plain color conversion functions.
  • node-fetch — A light-weight module that brings window.fetch to Node.js.
  • moment — A lightweight JavaScript date library for parsing, validating, manipulating, and formatting dates.
  • figlet — Creates ASCII Art from text. A full implementation of the FIGfont spec.