Cleanup and new features
Cleaned up some code, and added the types property to the constructor and log methods. Added a private checkTypes method to the class. Migrated changelogs to CHANGELOGS.md. Re-styled README.md. All changelogs inside their proper file.
This commit is contained in:
parent
230b7062f2
commit
d7ecab02bd
4 changed files with 178 additions and 113 deletions
26
CHANGELOGS.md
Normal file
26
CHANGELOGS.md
Normal file
|
@ -0,0 +1,26 @@
|
||||||
|
# Changelogs
|
||||||
|
|
||||||
|
Here are the changelogs since the first package version.
|
||||||
|
|
||||||
|
## 2023.09.02
|
||||||
|
|
||||||
|
- Migrated to CHANGELOGS.md
|
||||||
|
- Now debugLevel is required and no more optional
|
||||||
|
- Added types, to choose which debug message should be logged or not
|
||||||
|
- Cleaned up some code
|
||||||
|
- Restyled README.md
|
||||||
|
- Repository moved to [Thunder Network Source](https://source.thundernetwork.org/ThunderNetworkRaD/node-cout)
|
||||||
|
|
||||||
|
## 2023.07.08-2
|
||||||
|
|
||||||
|
- Fix emoji for Debug
|
||||||
|
|
||||||
|
## 2023.07.08-1
|
||||||
|
|
||||||
|
- Fix info Emoji
|
||||||
|
|
||||||
|
## 2023.07.08
|
||||||
|
|
||||||
|
- Exported the main class as default
|
||||||
|
- Add Stringify to all functions
|
||||||
|
- Changed the string type in the function to "any"
|
11
package.json
11
package.json
|
@ -1,6 +1,6 @@
|
||||||
{
|
{
|
||||||
"name": "node-cout",
|
"name": "node-cout",
|
||||||
"version": "2023.07.08-2",
|
"version": "2023.09.02",
|
||||||
"description": "Standard output module for JavaScript / TypeScript",
|
"description": "Standard output module for JavaScript / TypeScript",
|
||||||
"main": "build/index.js",
|
"main": "build/index.js",
|
||||||
"types": "build/index.d.ts",
|
"types": "build/index.d.ts",
|
||||||
|
@ -10,7 +10,7 @@
|
||||||
},
|
},
|
||||||
"repository": {
|
"repository": {
|
||||||
"type": "git",
|
"type": "git",
|
||||||
"url": "git+https://github.com/ThunderNetworkRaD/node-cout.git"
|
"url": "git+https://source.thundernetwork.org/ThunderNetworkRaD/node-cout.git"
|
||||||
},
|
},
|
||||||
"keywords": [
|
"keywords": [
|
||||||
"std",
|
"std",
|
||||||
|
@ -22,14 +22,15 @@
|
||||||
"typescript",
|
"typescript",
|
||||||
"input",
|
"input",
|
||||||
"cout",
|
"cout",
|
||||||
"await"
|
"await",
|
||||||
|
"log"
|
||||||
],
|
],
|
||||||
"author": "Thunder Network RaD | Killer Boss Original",
|
"author": "Thunder Network RaD | Killer Boss Original",
|
||||||
"license": "Mozilla Public License 2.0",
|
"license": "Mozilla Public License 2.0",
|
||||||
"bugs": {
|
"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": {
|
"dependencies": {
|
||||||
"@thundernetworkrad/logs": "^2023.2.5-1",
|
"@thundernetworkrad/logs": "^2023.2.5-1",
|
||||||
"@thundernetworkrad/time": "^2023.2.5-2",
|
"@thundernetworkrad/time": "^2023.2.5-2",
|
||||||
|
|
68
readme.md
68
readme.md
|
@ -1,35 +1,57 @@
|
||||||
# COUT
|
# 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
|
||||||
```js
|
|
||||||
import cc from 'node-cout';
|
|
||||||
|
|
||||||
const cout = new cc(0, true, true); // debugLevel, logs enabled (file), emojis enabled
|
Run this in your project folder:
|
||||||
|
|
||||||
cout.debug('test', 0) // console.log time and the string, if the number is >= to the debugLevel
|
```bash
|
||||||
cout.log('test')
|
npm install node-cout
|
||||||
cout.error('test')
|
|
||||||
cout.warn('test')
|
|
||||||
cout.info('test')
|
|
||||||
```
|
```
|
||||||
|
|
||||||
## CJS
|
## Usage
|
||||||
use `await import("")`
|
|
||||||
|
Learn how to use `node-cout` here:
|
||||||
|
|
||||||
|
### Import
|
||||||
|
|
||||||
```js
|
```js
|
||||||
const { default } = await import('node-cout'); // ti put in an async function
|
const cc = require('node-cout'); // CommonJS
|
||||||
const cout = new default(); // from here equal to MJS example
|
|
||||||
|
import cc from 'node-cout'; // MJS or TypeScript
|
||||||
|
|
||||||
|
const cout = new cc(1, { save: true, emoji: true, types: ['loading', 'uploading'] });
|
||||||
```
|
```
|
||||||
|
|
||||||
## Changelogs
|
> Parameters:
|
||||||
### 2023.07.08-2
|
> ```
|
||||||
- Fix emoji for Debug
|
> debugLevel: number
|
||||||
|
> options?: {
|
||||||
|
> save?: boolean
|
||||||
|
> emoji?: boolean
|
||||||
|
> types?: string[]
|
||||||
|
> }
|
||||||
|
> ```
|
||||||
|
|
||||||
### 2023.07.08-1
|
### Logging
|
||||||
- Fix info Emoji
|
|
||||||
|
|
||||||
### v2023.07.08
|
```js
|
||||||
- Exported the main class as default
|
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.)
|
||||||
- Add Stringify to all functions
|
|
||||||
- Changed the string type in the function to "any"
|
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
|
||||||
|
```
|
||||||
|
|
||||||
|
If you want to use the `types` option, you can do it like this:
|
||||||
|
|
||||||
|
```js
|
||||||
|
cout.debug('Hello World', 1, types);
|
||||||
|
```
|
||||||
|
|
||||||
|
`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.
|
48
src/index.ts
48
src/index.ts
|
@ -1,22 +1,27 @@
|
||||||
import { getTime } from '@thundernetworkrad/time';
|
import { getTime } from "@thundernetworkrad/time";
|
||||||
import { log } from '@thundernetworkrad/logs';
|
import { log } from "@thundernetworkrad/logs";
|
||||||
import chalk from "chalk";
|
import chalk from "chalk";
|
||||||
|
|
||||||
export default class cout {
|
export default class cout {
|
||||||
private debugLevel: number
|
private debugLevel: number
|
||||||
private file: boolean
|
private save: boolean
|
||||||
private emoji: boolean
|
private emoji: boolean
|
||||||
|
private types: string[]
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* @param debugLevel The debug level of the logging
|
* @param debugLevel The maximum debug level preferred
|
||||||
* @param file Do you want put the logs in a file?
|
* @param options.save Whetever logs are saved in a file or not
|
||||||
* @param emoji Do you want put the logs in an emoji?
|
* @param options.emoji If logs are followed by an emoji
|
||||||
|
* @param options.types Types of logs that are allowed to appear
|
||||||
|
*
|
||||||
*/
|
*/
|
||||||
constructor(debugLevel?: number, file?: boolean, emoji?: boolean) {
|
constructor(debugLevel: number, options?: { save?: boolean, emoji?: boolean, types?: string[] }) {
|
||||||
|
const { save, emoji, types } = options || {};
|
||||||
this.debugLevel = debugLevel || 0;
|
this.debugLevel = debugLevel || 0;
|
||||||
this.file = file || false;
|
this.save = save || false;
|
||||||
this.emoji = emoji || false;
|
this.emoji = emoji || false;
|
||||||
|
this.types = types || [];
|
||||||
}
|
}
|
||||||
|
|
||||||
private l(string: string, type: string) {
|
private l(string: string, type: string) {
|
||||||
|
@ -64,7 +69,7 @@ export default class cout {
|
||||||
emojic = "❌ ";
|
emojic = "❌ ";
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
if (this.file) {
|
if (this.save) {
|
||||||
string.split("\n").forEach((line) => {
|
string.split("\n").forEach((line) => {
|
||||||
log(`${this.emoji ? emoji : ""}[${time} ${type}] | ${line}`);
|
log(`${this.emoji ? emoji : ""}[${time} ${type}] | ${line}`);
|
||||||
})
|
})
|
||||||
|
@ -75,25 +80,36 @@ export default class cout {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
debug(string: any, level?: number) {
|
private checkTypes(types: string | string[]) {
|
||||||
if (this.debugLevel >= (level || 0)) {
|
if (!Array.isArray(types)) types = [types];
|
||||||
this.l(String(string), "DEBUG")
|
return types.some((type) => this.types.includes(type));
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
debug(string: any, level: number, types?: string | string[]) {
|
||||||
|
if ((level || 0) <= this.debugLevel) {
|
||||||
|
if (types && !this.checkTypes(types)) return;
|
||||||
|
this.l(String(string), "DEBUG");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
log(string: any) {
|
log(string: any, types?: string | string[]) {
|
||||||
|
if (types && !this.checkTypes(types)) return;
|
||||||
this.l(String(string), "LOG");
|
this.l(String(string), "LOG");
|
||||||
}
|
}
|
||||||
|
|
||||||
info(string: any) {
|
info(string: any, types?: string | string[]) {
|
||||||
|
if (types && !this.checkTypes(types)) return;
|
||||||
this.l(String(string), "INFO");
|
this.l(String(string), "INFO");
|
||||||
}
|
}
|
||||||
|
|
||||||
warn(string: any) {
|
warn(string: any, types?: string | string[]) {
|
||||||
|
if (types && !this.checkTypes(types)) return;
|
||||||
this.l(String(string), "WARN");
|
this.l(String(string), "WARN");
|
||||||
}
|
}
|
||||||
|
|
||||||
error(string: any) {
|
error(string: any, types?: string | string[]) {
|
||||||
|
if (types && !this.checkTypes(types)) return;
|
||||||
this.l(String(string), "ERROR");
|
this.l(String(string), "ERROR");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue