diff --git a/package-lock.json b/package-lock.json deleted file mode 100644 index 35e222d..0000000 --- a/package-lock.json +++ /dev/null @@ -1,91 +0,0 @@ -{ - "name": "node-cout", - "version": "2023.02.05", - "lockfileVersion": 2, - "requires": true, - "packages": { - "": { - "name": "node-cout", - "version": "2023.02.05", - "license": "Mozilla Public License 2.0", - "dependencies": { - "@thundernetworkrad/logs": "^2023.2.5-1", - "@thundernetworkrad/time": "^2023.2.5-2", - "@types/node": "^18.11.18", - "tslib": "^2.5.0", - "typescript": "^4.9.4" - } - }, - "node_modules/@thundernetworkrad/logs": { - "version": "2023.2.5-1", - "resolved": "https://registry.npmjs.org/@thundernetworkrad/logs/-/logs-2023.2.5-1.tgz", - "integrity": "sha512-ixGWloefa7otGFSRZRb1UO2rlDUYStJ/Tp2SNZ+riTxJYup1qYBjnGzN7H0y39W30H8CwTj1GZmDZGY4430ExA==", - "dependencies": { - "@thundernetworkrad/time": "^2023.2.5-2", - "@types/node": "^18.11.18", - "tslib": "^2.5.0", - "typescript": "^4.9.4" - } - }, - "node_modules/@thundernetworkrad/time": { - "version": "2023.2.5-2", - "resolved": "https://registry.npmjs.org/@thundernetworkrad/time/-/time-2023.2.5-2.tgz", - "integrity": "sha512-ERxP7iQ9ZZmEb0vaFNkE+WTRS6yg2jkA4pE2i789Qd8k1/lvR3WIZ84tKReV4MT3kn2YCitw8beh8Go5V8Id+g==" - }, - "node_modules/@types/node": { - "version": "18.11.18", - "resolved": "https://registry.npmjs.org/@types/node/-/node-18.11.18.tgz", - "integrity": "sha512-DHQpWGjyQKSHj3ebjFI/wRKcqQcdR+MoFBygntYOZytCqNfkd2ZC4ARDJ2DQqhjH5p85Nnd3jhUJIXrszFX/JA==" - }, - "node_modules/tslib": { - "version": "2.5.0", - "resolved": "https://registry.npmjs.org/tslib/-/tslib-2.5.0.tgz", - "integrity": "sha512-336iVw3rtn2BUK7ORdIAHTyxHGRIHVReokCR3XjbckJMK7ms8FysBfhLR8IXnAgy7T0PTPNBWKiH514FOW/WSg==" - }, - "node_modules/typescript": { - "version": "4.9.5", - "resolved": "https://registry.npmjs.org/typescript/-/typescript-4.9.5.tgz", - "integrity": "sha512-1FXk9E2Hm+QzZQ7z+McJiHL4NW1F2EzMu9Nq9i3zAaGqibafqYwCVU6WyWAuyQRRzOlxou8xZSyXLEN8oKj24g==", - "bin": { - "tsc": "bin/tsc", - "tsserver": "bin/tsserver" - }, - "engines": { - "node": ">=4.2.0" - } - } - }, - "dependencies": { - "@thundernetworkrad/logs": { - "version": "2023.2.5-1", - "resolved": "https://registry.npmjs.org/@thundernetworkrad/logs/-/logs-2023.2.5-1.tgz", - "integrity": "sha512-ixGWloefa7otGFSRZRb1UO2rlDUYStJ/Tp2SNZ+riTxJYup1qYBjnGzN7H0y39W30H8CwTj1GZmDZGY4430ExA==", - "requires": { - "@thundernetworkrad/time": "^2023.2.5-2", - "@types/node": "^18.11.18", - "tslib": "^2.5.0", - "typescript": "^4.9.4" - } - }, - "@thundernetworkrad/time": { - "version": "2023.2.5-2", - "resolved": "https://registry.npmjs.org/@thundernetworkrad/time/-/time-2023.2.5-2.tgz", - "integrity": "sha512-ERxP7iQ9ZZmEb0vaFNkE+WTRS6yg2jkA4pE2i789Qd8k1/lvR3WIZ84tKReV4MT3kn2YCitw8beh8Go5V8Id+g==" - }, - "@types/node": { - "version": "18.11.18", - "resolved": "https://registry.npmjs.org/@types/node/-/node-18.11.18.tgz", - "integrity": "sha512-DHQpWGjyQKSHj3ebjFI/wRKcqQcdR+MoFBygntYOZytCqNfkd2ZC4ARDJ2DQqhjH5p85Nnd3jhUJIXrszFX/JA==" - }, - "tslib": { - "version": "2.5.0", - "resolved": "https://registry.npmjs.org/tslib/-/tslib-2.5.0.tgz", - "integrity": "sha512-336iVw3rtn2BUK7ORdIAHTyxHGRIHVReokCR3XjbckJMK7ms8FysBfhLR8IXnAgy7T0PTPNBWKiH514FOW/WSg==" - }, - "typescript": { - "version": "4.9.5", - "resolved": "https://registry.npmjs.org/typescript/-/typescript-4.9.5.tgz", - "integrity": "sha512-1FXk9E2Hm+QzZQ7z+McJiHL4NW1F2EzMu9Nq9i3zAaGqibafqYwCVU6WyWAuyQRRzOlxou8xZSyXLEN8oKj24g==" - } - } -} diff --git a/package.json b/package.json index 1da148b..750565e 100644 --- a/package.json +++ b/package.json @@ -1,9 +1,10 @@ { "name": "node-cout", - "version": "2023.02.05-1", + "version": "2023.06.19", "description": "Standard output module for JavaScript / TypeScript", "main": "build/index.js", "types": "build/index.d.ts", + "type": "module", "scripts": { "build": "tsc" }, @@ -33,6 +34,7 @@ "@thundernetworkrad/logs": "^2023.2.5-1", "@thundernetworkrad/time": "^2023.2.5-2", "@types/node": "^18.11.18", + "chalk": "^5.2.0", "tslib": "^2.5.0", "typescript": "^4.9.4" } diff --git a/readme.md b/readme.md index f996023..ed57ada 100644 --- a/readme.md +++ b/readme.md @@ -2,14 +2,15 @@ This module allow you to make COUT and Debugs in NodeJS -Readme work in progress ```js -import { createCout } from '@thundernetworkrad/std'; +import { cout } from '@thundernetworkrad/std'; -let ccout = new createCout(0, true); // debugLevel, logs enabled (file) (like using log() ) +cout = new cout(0, true, true); // debugLevel, logs enabled (file), emojis enabled -let cout = ccout.cout; - -cout('test', 0) // console.log day, time and the string, if the number is >= to the debugLevel +cout.debug('test', 0) // console.log time and the string, if the number is >= to the debugLevel +cout.log('test') +cout.error('test') +cout.warn('test') +cout.info('test') ``` \ No newline at end of file diff --git a/src/index.ts b/src/index.ts index be3046d..891a16e 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,36 +1,95 @@ -let debug: number, logs1: boolean|undefined|null; import { getTime } from '@thundernetworkrad/time'; import { log } from '@thundernetworkrad/logs'; +import chalk from "chalk"; -export class createCout { - /** - * @constructor - * @param debugLevel from what debug level you want to log? - * @param logs do you want files log? - */ - constructor (debugLevel: number, logs?: boolean) { - if (!debugLevel) debugLevel = 0; - if (!logs) logs = false; - debug = debugLevel; - logs1 = logs; - } +export class cout { + private debugLevel: number + private file: boolean + private emoji: boolean /** * - * @param string what to log? - * @param debugLevel from what debug level this will logged? - * @returns + * @param debugLevel The debug level of the logging + * @param file Do you want put the logs in a file? + * @param emoji Do you want put the logs in an emoji? */ - cout (string: string, debugLevel?: number) { - if (!debugLevel) debugLevel = 0; - var time = getTime(); + constructor(debugLevel?: number, file?: boolean, emoji?: boolean) { + this.debugLevel = debugLevel || 0; + this.file = file || false; + this.emoji = emoji || false; + } - if (debug >= debugLevel) { - console.log(`[${time.year}.${time.month}.${time.day}-${time.hours}:${time.minutes}:${time.seconds}] | ${String(string)}`); - if (logs1) { - log(`[${time.year}.${time.month}.${time.day}-${time.hours}:${time.minutes}:${time.seconds}] | ${String(string)}`); - } + private l(string: string, type: string) { + let time = `${getTime().hours}:${getTime().minutes}:${getTime().seconds}`; + type = type.toUpperCase(); + + let timec = chalk.blue(time), stringc: string = " ", typec: string, emoji: string, emojic: string; + + switch (type) { + case "DEBUG": + stringc = chalk.grey(string); + typec = chalk.grey(type); + emoji = "📝"; + emojic = "📝 "; + break; + case "LOG": + stringc = chalk.white(string); + type = " " + type; + typec = chalk.white(type); + emoji = "🪵"; + emojic = "🪵 "; + break; + case "INFO": + stringc = chalk.cyan(string); + type = " " + type; + typec = chalk.cyan(type); + emoji = " ℹ️ "; + emojic = " ℹ️ "; + break; + case "WARN": + stringc = chalk.yellow(string); + type = " " + type; + typec = chalk.yellow(type); + emoji = "⚠️"; + emojic = "⚠️ "; + break; + case "ERROR": + stringc = chalk.red(string); + typec = chalk.red(type); + emoji = "❌"; + emojic = "❌ "; + break; } - return; - }; + if (this.file) { + string.split("\n").forEach((line) => { + log(`${this.emoji ? emoji : ""}[${time} ${type}] | ${line}`); + }) + } + + stringc.split("\n").forEach((line) => { + console.log(`${this.emoji ? emojic : ""}[${timec} ${typec}] | ${line}`); + }) + } + + debug(string: string, level?: number) { + if (this.debugLevel >= (level || 0)) { + this.l(string, "DEBUG") + } + } + + log(string: string) { + this.l(string, "LOG"); + } + + info(string: string) { + this.l(string, "INFO"); + } + + warn(string: string) { + this.l(string, "WARN"); + } + + error(string: string) { + this.l(string, "ERROR"); + } } \ No newline at end of file diff --git a/tsconfig.json b/tsconfig.json index f5214c3..b775cb5 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -25,7 +25,7 @@ // "moduleDetection": "auto", /* Control what method is used to detect module-format JS files. */ /* Modules */ - "module": "CommonJS", /* Specify what module code is generated. */ + "module": "ESNext", /* Specify what module code is generated. */ "rootDir": "./src/", /* Specify the root folder within your source files. */ "moduleResolution": "node", /* Specify how TypeScript looks up a file from a given module specifier. */ // "baseUrl": "./", /* Specify the base directory to resolve non-relative module names. */