@akc42/server-utils 1.2.1 → 1.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/logger.js +35 -29
  2. package/package.json +3 -4
package/logger.js CHANGED
@@ -24,7 +24,7 @@
24
24
  (function() {
25
25
  'use strict';
26
26
 
27
- const chalk = require('chalk');
27
+ const chalkPromise = import('chalk');
28
28
  const { isIP } = require('net');
29
29
  let cyrb53;
30
30
 
@@ -43,37 +43,43 @@
43
43
  return 4294967296 * (2097151 & h2) + (h1 >>> 0);
44
44
  };
45
45
  }
46
- const COLOURS = {
47
- app: chalk.rgb(255, 136, 0).bold, //orange,
48
- db: chalk.greenBright,
49
- api: chalk.magentaBright,
50
- client: chalk.redBright,
51
- log: chalk.yellowBright,
52
- mail:chalk.cyanBright,
53
- //error like have backGround colouring
54
- auth: chalk.black.bgCyan,
55
- err: chalk.white.bgBlue,
56
- error: chalk.white.bgRed
57
- };
46
+ const COLOURPromise = new Promise(async accept => {
47
+ const {default: chalk} = await import('chalk');
48
+ accept({
49
+ app: chalk.rgb(255, 136, 0).bold, //orange,
50
+ db: chalk.greenBright,
51
+ api: chalk.magentaBright,
52
+ client: chalk.redBright,
53
+ log: chalk.yellowBright,
54
+ mail: chalk.cyanBright,
55
+ //error like have backGround colouring
56
+ auth: chalk.black.bgCyan,
57
+ err: chalk.white.bgBlue,
58
+ error: chalk.white.bgRed
59
+ });
60
+ });
61
+
58
62
 
59
63
  function logger(ip,level, ...messages) {
60
64
  if (process.env.LOG_NONE === undefined) {
61
- let logLine = '';
62
- if (process.env.LOG_NO_DATE === undefined) logLine += new Date().toISOString() + ': ';
63
- let message;
64
- let logcolor
65
- if (isIP(ip) === 0 ) {
66
- logcolor = ip;
67
- message = level + messages.join(' ');
68
- } else {
69
- const client = process.env.LOG_IP_HIDDEN !== undefined ? cyrb53(ip): ip;
70
- logLine += COLOURS.client(client + ': ');
71
- logcolor = level
72
- message = messages.join(' ');
73
- }
74
- logLine += COLOURS[logcolor](message);
75
- //eslint-disable-next-line no-console
76
- console.log(logLine.trim());
65
+ COLOURPromise.then(COLOURS => {
66
+ let logLine = '';
67
+ if (process.env.LOG_NO_DATE === undefined) logLine += new Date().toISOString() + ': ';
68
+ let message;
69
+ let logcolor;
70
+ if (isIP(ip) === 0 ) {
71
+ logcolor = ip;
72
+ message = level + messages.join(' ');
73
+ } else {
74
+ const client = process.env.LOG_IP_HIDDEN !== undefined ? cyrb53(ip): ip;
75
+ logLine += COLOURS.client(client + ': ');
76
+ logcolor = level
77
+ message = messages.join(' ');
78
+ }
79
+ logLine += COLOURS[logcolor](message);
80
+ //eslint-disable-next-line no-console
81
+ console.log(logLine.trim());
82
+ });
77
83
  }
78
84
  }
79
85
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@akc42/server-utils",
3
- "version": "1.2.1",
3
+ "version": "1.3.0",
4
4
  "description": "A Set of Utilities to use on the Server Side of a Project",
5
5
  "main": "utils.js",
6
6
  "scripts": {
@@ -22,8 +22,7 @@
22
22
  "homepage": "https://github.com/akc42/server-utils#readme",
23
23
  "dependencies": {
24
24
  "app-root-path": "^3.0.0",
25
-
26
- "chalk": "^4.1.0",
27
- "debug": "^4.2.0"
25
+ "chalk": "^5.0.0",
26
+ "debug": "^4.3.3"
28
27
  }
29
28
  }