Compare commits

...

21 commits

Author SHA1 Message Date
mambuco
1c396feba2 Update CHANGELOGS.md 2023-09-03 22:19:45 +02:00
mambuco
a7c0bee5cf Fixed a problem cause by KillerBoss 2023-09-03 22:18:09 +02:00
5b2ebd3e90 Update src/index.ts 2023-09-03 16:49:34 +02:00
18d07c3b64 removed npmrc 2023-09-03 16:30:14 +02:00
aade8a4107 Fix Repository Settings? 2023-09-03 16:13:59 +02:00
Gabriele Giambrone
d56eb00801 Update package.json 2023-09-03 00:27:47 +02:00
Gabriele Giambrone
d39c56761b Added Mambuco to authors 2023-09-03 00:27:16 +02:00
mambuco
24d665f2a9 Other Cleanup 2023-09-03 00:10:58 +02:00
mambuco
21d7b4adff Update CHANGELOGS.md 2023-09-03 00:09:30 +02:00
mambuco
9494c7f1a1 Added Troubleshooting section 2023-09-03 00:07:21 +02:00
mambuco
662b7ea482 Fixed build script 2023-09-02 23:59:14 +02:00
mambuco
d7ecab02bd 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.
2023-09-02 23:44:03 +02:00
mambuco
230b7062f2 Added eslint configuration 2023-09-02 22:53:43 +02:00
Killer Boss Original
02c0348f12
Update readme.md 2023-07-08 17:20:39 +02:00
Killer Boss Original
36a319e9e9
2023.07.08-2 2023-07-08 17:20:06 +02:00
Killer Boss Original
71de81ad73
Update index.ts 2023-07-08 17:19:40 +02:00
ca04f1f7b2 2023.07.08-1 2023-07-08 16:38:38 +02:00
1338067250 exported as default 2023-07-08 16:22:24 +02:00
fe12da748a changelogs 2023-07-08 16:22:05 +02:00
f504f4a612 2023.07.08 2023-07-08 16:15:00 +02:00
da6997f0ab 2023.06.22 2023-06-22 17:48:01 +02:00
7 changed files with 247 additions and 132 deletions

40
.eslintrc.json Normal file
View file

@ -0,0 +1,40 @@
{
"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"
}
}

View file

@ -1,26 +0,0 @@
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
View file

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

31
CHANGELOGS.md Normal file
View file

@ -0,0 +1,31 @@
# 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,16 +1,17 @@
{
"name": "node-cout",
"version": "2023.06.19-1",
"version": "2023.09.03",
"description": "Standard output module for JavaScript / TypeScript",
"main": "build/index.js",
"types": "build/index.d.ts",
"type": "module",
"scripts": {
"install": "npm run build",
"build": "tsc"
},
"repository": {
"type": "git",
"url": "git+https://github.com/ThunderNetworkRaD/node-cout.git"
"url": "git+https://source.thundernetwork.org/ThunderNetworkRaD/node-cout.git"
},
"keywords": [
"std",
@ -22,14 +23,15 @@
"typescript",
"input",
"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": {
"@thundernetworkrad/logs": "^2023.2.5-1",
"@thundernetworkrad/time": "^2023.2.5-2",

View file

@ -1,23 +1,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
```js
import { cout as cc } from 'node-cout';
## Installation
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
cout.log('test')
cout.error('test')
cout.warn('test')
cout.info('test')
```bash
npm install node-cout
```
## CJS
use `await import("")`
## Usage
Learn how to use `node-cout` here:
### Import
```js
let { cout } = await import('node-cout'); // ti put in an async function
cout = new cout(); // from here equal to MJS example
import cc from 'node-cout';
const cout = new cc(1, { save: true, emoji: true, types: ['loading', 'uploading'] });
```
> 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
```
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.
# 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,28 +1,37 @@
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 class cout {
export default class cout {
private debugLevel: number
private file: boolean
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?
* @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, file?: boolean, emoji?: boolean) {
constructor(debugLevel: number, options?: { save?: boolean, emoji?: boolean, types?: string[] }) {
const { save, emoji, types } = options || {};
this.debugLevel = debugLevel || 0;
this.file = file || false;
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();
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;
switch (type) {
@ -60,36 +69,47 @@ export class cout {
emojic = "❌ ";
break;
}
if (this.file) {
if (this.save) {
string.split("\n").forEach((line) => {
log(`${this.emoji ? emoji : ""}[${time} ${type}] | ${line}`);
log(`${this.emoji ? emoji : ''}[${time} ${type}] | ${line}`);
})
}
stringc.split("\n").forEach((line) => {
console.log(`${this.emoji ? emojic : ""}[${timec} ${typec}] | ${line}`);
console.log(`${this.emoji ? emojic : ''}[${timec} ${typec}] | ${line}`);
})
}
debug(string: string, level?: number) {
if (this.debugLevel >= (level || 0)) {
this.l(string, "DEBUG")
private checkTypes(types: string | string[]) {
if (!Array.isArray(types)) types = [types];
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: string) {
this.l(string, "LOG");
log(string: any, types?: string | string[]) {
if (types && !this.checkTypes(types)) return;
this.l(String(string), "LOG");
}
info(string: string) {
this.l(string, "INFO");
info(string: any, types?: string | string[]) {
if (types && !this.checkTypes(types)) return;
this.l(String(string), "INFO");
}
warn(string: string) {
this.l(string, "WARN");
warn(string: any, types?: string | string[]) {
if (types && !this.checkTypes(types)) return;
this.l(String(string), "WARN");
}
error(string: string) {
this.l(string, "ERROR");
error(string: any, types?: string | string[]) {
if (types && !this.checkTypes(types)) return;
this.l(String(string), "ERROR");
}
}