Compare commits

..

No commits in common. "main" and "v2023.07.08" have entirely different histories.

7 changed files with 138 additions and 243 deletions

View file

@ -1,40 +0,0 @@
{
"extends": "eslint:recommended",
"env": {
"node": true,
"es6": true
},
"parserOptions": {
"ecmaVersion": 2021
},
"rules": {
"arrow-spacing": ["warn", { "before": true, "after": true }],
"brace-style": "off",
"comma-dangle": ["error", "always-multiline"],
"comma-spacing": "error",
"comma-style": "error",
"curly": ["error", "multi-line", "consistent"],
"dot-location": ["error", "property"],
"handle-callback-err": "off",
"indent": ["error", "tab"],
"keyword-spacing": "error",
"max-nested-callbacks": ["error", { "max": 4 }],
"max-statements-per-line": ["error", { "max": 2 }],
"no-console": "off",
"no-unused-vars": "off",
"no-floating-decimal": "error",
"no-inline-comments": "error",
"no-multi-spaces": "error",
"no-multiple-empty-lines": ["error", { "max": 2, "maxEOF": 1, "maxBOF": 0 }],
"no-shadow": ["error", { "allow": ["err", "resolve", "reject"] }],
"object-curly-spacing": ["error", "always"],
"quotes": ["error", "single"],
"semi": ["error", "always"],
"space-before-blocks": "error",
"space-infix-ops": "error",
"space-unary-ops": "error",
"spaced-comment": "error",
"yoda": "error",
"no-extra-boolean-cast": "off"
}
}

26
.github/workflows/npm-publish.yml vendored Normal file
View file

@ -0,0 +1,26 @@
name: Publish to NPM
on:
release:
types: [created]
jobs:
Publish-NPM:
runs-on: node1
steps:
- name: Checkout
uses: actions/checkout@v2
- name: Setup Node
uses: actions/setup-node@v2
with:
node-version: '16.x'
registry-url: 'https://registry.npmjs.org'
scope: '@thundernetworkrad'
- name: Install Dependencies
run: npm i
- name: Build
run: npm run build
- name: Publish package on NPM 📦
run: npm publish --access public
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
REGISTRY1: 'registry.npmjs.org'
REGISTRY2: 'registry=https://registry.npmjs.org/'

2
.npmrc Normal file
View file

@ -0,0 +1,2 @@
//${REGISTRY1}/:_authToken=${NODE_AUTH_TOKEN}
${REGISTRY2}

View file

@ -1,31 +0,0 @@
# Changelogs
Here are the changelogs since the first package version.
## 2023.09.03
- Cleaned up some files
## 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 (also added Troubleshooting section)
- Repository moved to [Thunder Network Source](https://source.thundernetwork.org/ThunderNetworkRaD/node-cout)
- Fixed `tsc` build script in `package.json`
## 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"

View file

@ -1,17 +1,16 @@
{ {
"name": "node-cout", "name": "node-cout",
"version": "2023.09.03", "version": "2023.07.08",
"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",
"type": "module", "type": "module",
"scripts": { "scripts": {
"install": "npm run build",
"build": "tsc" "build": "tsc"
}, },
"repository": { "repository": {
"type": "git", "type": "git",
"url": "git+https://source.thundernetwork.org/ThunderNetworkRaD/node-cout.git" "url": "git+https://github.com/ThunderNetworkRaD/node-cout.git"
}, },
"keywords": [ "keywords": [
"std", "std",
@ -23,15 +22,14 @@
"typescript", "typescript",
"input", "input",
"cout", "cout",
"await", "await"
"log"
], ],
"author": "Thunder Network RaD | Killer Boss Original, Mambuco", "author": "Thunder Network RaD | Killer Boss Original",
"license": "Mozilla Public License 2.0", "license": "Mozilla Public License 2.0",
"bugs": { "bugs": {
"url": "https://source.thundernetwork.org/ThunderNetworkRaD/node-cout/issues" "url": "https://github.com/ThunderNetworkRaD/node-cout/issues"
}, },
"homepage": "https://source.thundernetwork.org/ThunderNetworkRaD/node-cout#readme", "homepage": "https://github.com/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",

View file

@ -1,73 +1,29 @@
# node-cout # COUT
This package allows you to use `cout` and debug levels in Node.js. This module allow you to make COUT and Debugs in NodeJS
## Installation
Run this in your project folder:
```bash
npm install node-cout
```
## Usage
Learn how to use `node-cout` here:
### Import
## MJS or TypeScript
```js ```js
import cc from 'node-cout'; import cc from 'node-cout';
const cout = new cc(1, { save: true, emoji: true, types: ['loading', 'uploading'] }); const cout = new cc(0, true, true); // debugLevel, logs enabled (file), emojis enabled
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). ## CJS
use `await import("")`
> Parameters:
> ```
> debugLevel: number
> options?: {
> save?: boolean
> emoji?: boolean
> types?: string[]
> }
> ```
### Logging
```js ```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.) const { default } = await import('node-cout'); // ti put in an async function
const cout = new default(); // from here equal to MJS example
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: ## Changelogs
### v2023.07.08
```js - Exported the main class as default
cout.debug('Hello World', 1, types); - 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"
}
```

View file

@ -1,115 +1,99 @@
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 save: boolean private file: boolean
private emoji: boolean private emoji: boolean
private types: string[]
/** /**
* *
* @param debugLevel The maximum debug level preferred * @param debugLevel The debug level of the logging
* @param options.save Whetever logs are saved in a file or not * @param file Do you want put the logs in a file?
* @param options.emoji If logs are followed by an emoji * @param emoji Do you want put the logs in an emoji?
* @param options.types Types of logs that are allowed to appear */
* constructor(debugLevel?: number, file?: boolean, emoji?: boolean) {
*/ this.debugLevel = debugLevel || 0;
constructor(debugLevel: number, options?: { save?: boolean, emoji?: boolean, types?: string[] }) { this.file = file || false;
const { save, emoji, types } = options || {}; this.emoji = emoji || false;
this.debugLevel = debugLevel || 0; }
this.save = save || false;
this.emoji = emoji || false;
this.types = types || [];
}
private l(string: string, type: string) { private l(string: string, type: string) {
let time = `${getTime().hours}:${getTime().minutes}:${getTime().seconds}`; let time = `${getTime().hours}:${getTime().minutes}:${getTime().seconds}`;
type = type.toUpperCase(); type = type.toUpperCase();
if (getTime().hours < 10) time += " "; if (getTime().hours < 10) time += " ";
if (getTime().minutes < 10) time += " "; if (getTime().minutes < 10) time += " ";
if (getTime().seconds < 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) { switch (type) {
case "DEBUG": case "DEBUG":
stringc = chalk.grey(string); stringc = chalk.grey(string);
typec = chalk.grey(type); typec = chalk.grey(type);
emoji = "📝"; emoji = "📝";
emojic = "📝 "; emojic = "📝 ";
break; break;
case "LOG": case "LOG":
stringc = chalk.white(string); stringc = chalk.white(string);
type = " " + type; type = " " + type;
typec = chalk.white(type); typec = chalk.white(type);
emoji = "🪵"; emoji = "🪵";
emojic = "🪵 "; emojic = "🪵 ";
break; break;
case "INFO": case "INFO":
stringc = chalk.cyan(string); stringc = chalk.cyan(string);
type = " " + type; type = " " + type;
typec = chalk.cyan(type); typec = chalk.cyan(type);
emoji = " "; emoji = " ";
emojic = " "; emojic = " ";
break; break;
case "WARN": case "WARN":
stringc = chalk.yellow(string); stringc = chalk.yellow(string);
type = " " + type; type = " " + type;
typec = chalk.yellow(type); typec = chalk.yellow(type);
emoji = "⚠️"; emoji = "⚠️";
emojic = "⚠️ "; emojic = "⚠️ ";
break; break;
case "ERROR": case "ERROR":
stringc = chalk.red(string); stringc = chalk.red(string);
typec = chalk.red(type); typec = chalk.red(type);
emoji = "❌"; emoji = "❌";
emojic = "❌ "; emojic = "❌ ";
break; break;
} }
if (this.save) { if (this.file) {
string.split("\n").forEach((line) => { string.split("\n").forEach((line) => {
log(`${this.emoji ? emoji : ''}[${time} ${type}] | ${line}`); log(`${this.emoji ? emoji : ""}[${time} ${type}] | ${line}`);
}) })
} }
stringc.split("\n").forEach((line) => { stringc.split("\n").forEach((line) => {
console.log(`${this.emoji ? emojic : ''}[${timec} ${typec}] | ${line}`); console.log(`${this.emoji ? emojic : ""}[${timec} ${typec}] | ${line}`);
}) })
} }
private checkTypes(types: string | string[]) { debug(string: any, level?: number) {
if (!Array.isArray(types)) types = [types]; if (this.debugLevel >= (level || 0)) {
return types.some((type) => this.types.includes(type)); this.l(String(string), "DEBUG")
}
}
} log(string: any) {
this.l(String(string), "LOG");
}
debug(string: any, level: number, types?: string | string[]) { info(string: any) {
if ((level || 0) <= this.debugLevel) { this.l(String(string), "INFO");
if (types && !this.checkTypes(types)) return; }
this.l(String(string), "DEBUG");
}
}
log(string: any, types?: string | string[]) { warn(string: any) {
if (types && !this.checkTypes(types)) return; this.l(String(string), "WARN");
this.l(String(string), "LOG"); }
}
info(string: any, types?: string | string[]) { error(string: any) {
if (types && !this.checkTypes(types)) return; this.l(String(string), "ERROR");
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");
}
} }