node-cout
Advanced tools
Comparing version 2023.7.8 to 2023.9.3
{ | ||
"name": "node-cout", | ||
"version": "2023.07.08", | ||
"version": "2023.09.03", | ||
"description": "Standard output module for JavaScript / TypeScript", | ||
@@ -9,2 +9,3 @@ "main": "build/index.js", | ||
"scripts": { | ||
"install": "npm run build", | ||
"build": "tsc" | ||
@@ -14,3 +15,3 @@ }, | ||
"type": "git", | ||
"url": "git+https://github.com/ThunderNetworkRaD/node-cout.git" | ||
"url": "git+https://source.thundernetwork.org/ThunderNetworkRaD/node-cout.git" | ||
}, | ||
@@ -27,10 +28,11 @@ "keywords": [ | ||
"cout", | ||
"await" | ||
"await", | ||
"log" | ||
], | ||
"author": "Thunder Network RaD | Killer Boss Original", | ||
"author": "Thunder Network RaD | Killer Boss Original, Mambuco", | ||
"license": "Mozilla Public License 2.0", | ||
"bugs": { | ||
"url": "https://github.com/ThunderNetworkRaD/node-cout/issues" | ||
"url": "https://source.thundernetwork.org/ThunderNetworkRaD/node-cout/issues" | ||
}, | ||
"homepage": "https://github.com/ThunderNetworkRaD/node-cout#readme", | ||
"homepage": "https://source.thundernetwork.org/ThunderNetworkRaD/node-cout#readme", | ||
"dependencies": { | ||
@@ -37,0 +39,0 @@ "@thundernetworkrad/logs": "^2023.2.5-1", |
@@ -1,29 +0,73 @@ | ||
# COUT | ||
# node-cout | ||
This module allow you to make COUT and Debugs in NodeJS | ||
This package allows you to use `cout` and debug levels in Node.js. | ||
## MJS or TypeScript | ||
## Installation | ||
Run this in your project folder: | ||
```bash | ||
npm install node-cout | ||
``` | ||
## Usage | ||
Learn how to use `node-cout` here: | ||
### Import | ||
```js | ||
import cc from 'node-cout'; | ||
const cout = new cc(0, true, true); // debugLevel, logs enabled (file), emojis enabled | ||
const cout = new cc(1, { save: true, emoji: true, types: ['loading', 'uploading'] }); | ||
``` | ||
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') | ||
> You're using CommonJS and can use `require()` instead of `import`? Go on [troubleshooting](#troubleshooting). | ||
> Parameters: | ||
> ``` | ||
> debugLevel: number | ||
> options?: { | ||
> save?: boolean | ||
> emoji?: boolean | ||
> types?: string[] | ||
> } | ||
> ``` | ||
### Logging | ||
```js | ||
cout.debug('Hello World', 1); // Sends a debug log (1 is debug level, if its higher than the one defined in the constructor, its not going to be logged.) | ||
cout.info('Hello World'); // Sends an info log | ||
cout.warn('Hello World'); // Sends a warning log | ||
cout.error('Hello World'); // Sends an error log | ||
cout.log('Hello World'); // Sends a normal log | ||
``` | ||
## CJS | ||
use `await import("")` | ||
If you want to use the `types` option, you can do it like this: | ||
```js | ||
const { default } = await import('node-cout'); // ti put in an async function | ||
const cout = new default(); // from here equal to MJS example | ||
cout.debug('Hello World', 1, types); | ||
``` | ||
## Changelogs | ||
### v2023.07.08 | ||
- Exported the main class as default | ||
- Add Stringify to all functions | ||
- Changed the string type in the function to "any" | ||
`types` can either be a string or an array of strings, and if one of them matches with one of the types defined in the constructor, the log is going to be logged. | ||
# Troubleshooting | ||
Unfortunately, this is not supported anymore: | ||
```js | ||
const cc = require('node-cout'); | ||
``` | ||
If you want to `import` the package in your CommonJS project, add this to your `package.json` file: | ||
```json | ||
{ | ||
"type": "module" | ||
} | ||
``` |
186
src/index.ts
@@ -1,99 +0,115 @@ | ||
import { getTime } from '@thundernetworkrad/time'; | ||
import { log } from '@thundernetworkrad/logs'; | ||
import { getTime } from "@thundernetworkrad/time"; | ||
import { log } from "@thundernetworkrad/logs"; | ||
import chalk from "chalk"; | ||
export default class cout { | ||
private debugLevel: number | ||
private file: boolean | ||
private emoji: boolean | ||
private debugLevel: number | ||
private save: boolean | ||
private emoji: boolean | ||
private types: string[] | ||
/** | ||
* | ||
* @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? | ||
*/ | ||
constructor(debugLevel?: number, file?: boolean, emoji?: boolean) { | ||
this.debugLevel = debugLevel || 0; | ||
this.file = file || false; | ||
this.emoji = emoji || false; | ||
} | ||
/** | ||
* | ||
* @param debugLevel The maximum debug level preferred | ||
* @param options.save Whetever logs are saved in a file or not | ||
* @param options.emoji If logs are followed by an emoji | ||
* @param options.types Types of logs that are allowed to appear | ||
* | ||
*/ | ||
constructor(debugLevel: number, options?: { save?: boolean, emoji?: boolean, types?: string[] }) { | ||
const { save, emoji, types } = options || {}; | ||
this.debugLevel = debugLevel || 0; | ||
this.save = save || false; | ||
this.emoji = emoji || false; | ||
this.types = types || []; | ||
} | ||
private l(string: string, type: string) { | ||
let time = `${getTime().hours}:${getTime().minutes}:${getTime().seconds}`; | ||
type = type.toUpperCase(); | ||
private l(string: string, type: string) { | ||
let time = `${getTime().hours}:${getTime().minutes}:${getTime().seconds}`; | ||
type = type.toUpperCase(); | ||
if (getTime().hours < 10) time += " "; | ||
if (getTime().minutes < 10) time += " "; | ||
if (getTime().seconds < 10) time += " "; | ||
if (getTime().hours < 10) time += " "; | ||
if (getTime().minutes < 10) time += " "; | ||
if (getTime().seconds < 10) time += " "; | ||
let timec = chalk.blue(time), stringc: string = " ", typec: string, emoji: string, emojic: string; | ||
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; | ||
} | ||
if (this.file) { | ||
string.split("\n").forEach((line) => { | ||
log(`${this.emoji ? emoji : ""}[${time} ${type}] | ${line}`); | ||
}) | ||
} | ||
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; | ||
} | ||
if (this.save) { | ||
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}`); | ||
}) | ||
} | ||
stringc.split("\n").forEach((line) => { | ||
console.log(`${this.emoji ? emojic : ''}[${timec} ${typec}] | ${line}`); | ||
}) | ||
} | ||
debug(string: any, level?: number) { | ||
if (this.debugLevel >= (level || 0)) { | ||
this.l(String(string), "DEBUG") | ||
} | ||
} | ||
private checkTypes(types: string | string[]) { | ||
if (!Array.isArray(types)) types = [types]; | ||
return types.some((type) => this.types.includes(type)); | ||
log(string: any) { | ||
this.l(String(string), "LOG"); | ||
} | ||
} | ||
info(string: any) { | ||
this.l(String(string), "INFO"); | ||
} | ||
debug(string: any, level: number, types?: string | string[]) { | ||
if ((level || 0) <= this.debugLevel) { | ||
if (types && !this.checkTypes(types)) return; | ||
this.l(String(string), "DEBUG"); | ||
} | ||
} | ||
warn(string: any) { | ||
this.l(String(string), "WARN"); | ||
} | ||
log(string: any, types?: string | string[]) { | ||
if (types && !this.checkTypes(types)) return; | ||
this.l(String(string), "LOG"); | ||
} | ||
error(string: any) { | ||
this.l(String(string), "ERROR"); | ||
} | ||
} | ||
info(string: any, types?: string | string[]) { | ||
if (types && !this.checkTypes(types)) return; | ||
this.l(String(string), "INFO"); | ||
} | ||
warn(string: any, types?: string | string[]) { | ||
if (types && !this.checkTypes(types)) return; | ||
this.l(String(string), "WARN"); | ||
} | ||
error(string: any, types?: string | string[]) { | ||
if (types && !this.checkTypes(types)) return; | ||
this.l(String(string), "ERROR"); | ||
} | ||
} |
Install scripts
Supply chain riskInstall scripts are run when the package is installed. The majority of malware in npm is hidden in install scripts.
Found 1 instance in 1 package
Manifest confusion
Supply chain riskThis package has inconsistent metadata. This could be malicious or caused by an error when publishing the package.
Found 1 instance in 1 package
Manifest confusion
Supply chain riskThis package has inconsistent metadata. This could be malicious or caused by an error when publishing the package.
Found 1 instance in 1 package
73
35913
7
236
1