From 88cd6ab7db6aefb03155b9d97b868c5cb59e4fbb Mon Sep 17 00:00:00 2001 From: Killer Boss Original <73131550+killerbossoriginal@users.noreply.github.com> Date: Tue, 24 Jan 2023 22:50:10 +0100 Subject: [PATCH] 2023.01.24-4 --- README.md | 6 +++--- index.js | 31 +++++++++++++------------------ package.json | 4 ++-- 3 files changed, 18 insertions(+), 23 deletions(-) diff --git a/README.md b/README.md index 17e9783..0699946 100644 --- a/README.md +++ b/README.md @@ -1,8 +1,8 @@ Work IN PROGRESS ```js -require('@thundernetworkrad/std').cin('Question') -.then((response) => { +const { cin } = require('@thundernetworkrad/std'); +cin('Question').then((response) => { console.log(response) }) ``` @@ -10,7 +10,7 @@ require('@thundernetworkrad/std').cin('Question') ```js const { createCout } = require('@thundernetworkrad/std'); -let ccout = new createCout(0); // debugLevel +let ccout = new createCout(0, true); // debugLevel, logs enabled (file) let cout = ccout.cout; diff --git a/index.js b/index.js index eb0e87b..6f15f25 100644 --- a/index.js +++ b/index.js @@ -1,7 +1,10 @@ -const { writeFile, readFile, mkdir } = require('node:fs/promises'); -const { stdin, stdout } = require('node:process'); +const { appendFile, existsSync } = require('node:fs'); +const { mkdir } = require('node:fs/promises') var readlineSync = require('readline-sync'); -var name, debug, logs1; +var debug, logs1; + +let time = getTime() +const name = `${time.year}.${time.month}.${time.day}.${time.hours}.${time.minutes}.${time.seconds}.log`; function getTime () { const date_time = new Date(); @@ -14,20 +17,12 @@ function getTime () { return({year, month, day, hours, minutes, seconds}) }; -function createLog () { - mkdir('./logs', { recursive: true }); - var time = getTime(); - name = `${time.year}.${time.month}.${time.day}.${time.hours}.${time.minutes}.${time.seconds}.log`; - writeFile(`./logs/${name}`, ''); - return(name) -}; - function log (string) { - readFile(`./logs/${name}`, 'utf8') - .then(async (err, data) => { - if (!data) data = ''; - data += string + '\n'; - writeFile(`./logs/${name}`, data); + if (!existsSync('./logs')) mkdir('./logs', { recursive: true }); + appendFile(`./logs/${name}`, string+'\n', err => { + if (err) { + throw err + } }) }; @@ -60,11 +55,11 @@ class createCout { if (debug >= debugLevel) { console.log(`[${time.year}.${time.month}.${time.day}-${time.hours}:${time.minutes}:${time.seconds}] | ${String(string)}`); if (logs1) { - log(string); + log(`[${time.year}.${time.month}.${time.day}-${time.hours}:${time.minutes}:${time.seconds}] | ${String(string)}`); } } return; }; } -module.exports = { cin, createCout, createLog, log }; +module.exports = { cin, createCout, log }; diff --git a/package.json b/package.json index 9abe39e..608ab31 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@thundernetworkrad/std", - "version": "2023.01.24-3", + "version": "2023.01.24-4", "description": "Standard module for javascript", "main": "index.js", "scripts": { @@ -25,6 +25,6 @@ }, "homepage": "https://github.com/FIUSDevelopment/std#readme", "dependencies": { - "readline-sync": "^1.4.10" + "@thundernetworkrad/readline-sync": "^2023.1.10" } }