@serenityjs/logger 0.3.2 → 0.3.3-beta-20240611195516

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.
package/dist/index.d.ts CHANGED
@@ -71,6 +71,7 @@ declare class Logger {
71
71
  * @param arguments_ - The arguments to log.
72
72
  */
73
73
  chat(...arguments_: Array<unknown>): void;
74
+ colorize(...arguments_: Array<unknown>): Array<unknown>;
74
75
  }
75
76
 
76
77
  /**
@@ -96,4 +97,6 @@ declare const LoggerColors: {
96
97
  Gray: colorette.Color;
97
98
  };
98
99
 
99
- export { Logger, LoggerColors };
100
+ declare function formatMinecraftColorCode(text: string): string;
101
+
102
+ export { Logger, LoggerColors, formatMinecraftColorCode };
package/dist/index.js CHANGED
@@ -4024,13 +4024,61 @@ var require_moment = __commonJS({
4024
4024
  var src_exports = {};
4025
4025
  __export(src_exports, {
4026
4026
  Logger: () => Logger,
4027
- LoggerColors: () => LoggerColors
4027
+ LoggerColors: () => LoggerColors,
4028
+ formatMinecraftColorCode: () => formatMinecraftColorCode
4028
4029
  });
4029
4030
  module.exports = __toCommonJS(src_exports);
4030
4031
 
4031
4032
  // src/logger.ts
4032
4033
  var import_moment = __toESM(require_moment());
4033
4034
  var import_colorette = require("colorette");
4035
+
4036
+ // src/minecraft-colors.ts
4037
+ function formatMinecraftColorCode(text) {
4038
+ const ansiColors = {
4039
+ "0": "\x1B[30m",
4040
+ // Black
4041
+ "1": "\x1B[34m",
4042
+ // Dark Blue
4043
+ "2": "\x1B[32m",
4044
+ // Dark Green
4045
+ "3": "\x1B[36m",
4046
+ // Dark Aqua
4047
+ "4": "\x1B[31m",
4048
+ // Dark Red
4049
+ "5": "\x1B[35m",
4050
+ // Dark Purple
4051
+ "6": "\x1B[33m",
4052
+ // Gold
4053
+ "7": "\x1B[37m",
4054
+ // Gray
4055
+ "8": "\x1B[90m",
4056
+ // Dark Gray
4057
+ "9": "\x1B[94m",
4058
+ // Blue
4059
+ a: "\x1B[92m",
4060
+ // Green
4061
+ b: "\x1B[96m",
4062
+ // Aqua
4063
+ c: "\x1B[91m",
4064
+ // Red
4065
+ d: "\x1B[95m",
4066
+ // Light Purple
4067
+ e: "\x1B[93m",
4068
+ // Yellow
4069
+ f: "\x1B[97m",
4070
+ // White
4071
+ r: "\x1B[0m"
4072
+ // Reset
4073
+ };
4074
+ const regex = /§[\da-fk-or]/g;
4075
+ return text.replaceAll(regex, (match) => {
4076
+ const code = match.charAt(1);
4077
+ return ansiColors[code] || "";
4078
+ }) + "\x1B[0m";
4079
+ }
4080
+
4081
+ // src/logger.ts
4034
4082
  var Logger = class _Logger {
4035
4083
  /**
4036
4084
  * Whether or not debug messages should be shown.
@@ -4065,10 +4113,11 @@ var Logger = class _Logger {
4065
4113
  * @param arguments_ - The arguments to log.
4066
4114
  */
4067
4115
  log(...arguments_) {
4116
+ const colorized = this.colorize(...arguments_);
4068
4117
  const format = `${this.colorette.gray("<")}${(0, import_moment.default)().format("MM-DD-YYYY HH:mm:ss")}${this.colorette.gray(">")} ${this.colorette.gray(
4069
4118
  "["
4070
4119
  )}${this.color(`${this.name}`)}${this.colorette.gray("]")}`;
4071
- console.info(format, ...arguments_);
4120
+ console.info(format, ...colorized);
4072
4121
  }
4073
4122
  /**
4074
4123
  * Logs an info message to the console.
@@ -4076,10 +4125,11 @@ var Logger = class _Logger {
4076
4125
  * @param arguments_ - The arguments to log.
4077
4126
  */
4078
4127
  info(...arguments_) {
4128
+ const colorized = this.colorize(...arguments_);
4079
4129
  const format = `${this.colorette.gray("<")}${(0, import_moment.default)().format("MM-DD-YYYY HH:mm:ss")}${this.colorette.gray(">")} ${this.colorette.gray(
4080
4130
  "["
4081
4131
  )}${this.color(`${this.name}`)}${this.colorette.gray("]")} ${this.colorette.gray("[")}${this.colorette.cyan("Info")}${this.colorette.gray("]")}`;
4082
- console.info(format, ...arguments_);
4132
+ console.info(format, ...colorized);
4083
4133
  }
4084
4134
  /**
4085
4135
  * Logs a warning message to the console.
@@ -4087,10 +4137,11 @@ var Logger = class _Logger {
4087
4137
  * @param arguments_ - The arguments to log.
4088
4138
  */
4089
4139
  warn(...arguments_) {
4140
+ const colorized = this.colorize(...arguments_);
4090
4141
  const format = `${this.colorette.gray("<")}${(0, import_moment.default)().format("MM-DD-YYYY HH:mm:ss")}${this.colorette.gray(">")} ${this.colorette.gray(
4091
4142
  "["
4092
4143
  )}${this.color(`${this.name}`)}${this.colorette.gray("]")} ${this.colorette.gray("[")}${this.colorette.yellow("Warning")}${this.colorette.gray("]")}`;
4093
- console.info(format, ...arguments_);
4144
+ console.info(format, ...colorized);
4094
4145
  }
4095
4146
  /**
4096
4147
  * Logs an error message to the console.
@@ -4098,10 +4149,11 @@ var Logger = class _Logger {
4098
4149
  * @param arguments_ - The arguments to log.
4099
4150
  */
4100
4151
  error(...arguments_) {
4152
+ const colorized = this.colorize(...arguments_);
4101
4153
  const format = `${this.colorette.gray("<")}${(0, import_moment.default)().format("MM-DD-YYYY HH:mm:ss")}${this.colorette.gray(">")} ${this.colorette.gray(
4102
4154
  "["
4103
4155
  )}${this.color(`${this.name}`)}${this.colorette.gray("]")} ${this.colorette.gray("[")}${this.colorette.red("Error")}${this.colorette.gray("]")}`;
4104
- console.info(format, ...arguments_);
4156
+ console.info(format, ...colorized);
4105
4157
  }
4106
4158
  /**
4107
4159
  * Logs a success message to the console.
@@ -4109,12 +4161,13 @@ var Logger = class _Logger {
4109
4161
  * @param arguments_ - The arguments to log.
4110
4162
  */
4111
4163
  success(...arguments_) {
4164
+ const colorized = this.colorize(...arguments_);
4112
4165
  const format = `${this.colorette.gray("<")}${(0, import_moment.default)().format("MM-DD-YYYY HH:mm:ss")}${this.colorette.gray(">")} ${this.colorette.gray(
4113
4166
  "["
4114
4167
  )}${this.color(`${this.name}`)}${this.colorette.gray("]")} ${this.colorette.gray("[")}${this.colorette.greenBright("Success")}${this.colorette.gray(
4115
4168
  "]"
4116
4169
  )}`;
4117
- console.info(format, ...arguments_);
4170
+ console.info(format, ...colorized);
4118
4171
  }
4119
4172
  /**
4120
4173
  * Logs a debug message to the console.
@@ -4123,12 +4176,12 @@ var Logger = class _Logger {
4123
4176
  * @param arguments_ - The arguments to log.
4124
4177
  */
4125
4178
  debug(...arguments_) {
4126
- if (!_Logger.DEBUG)
4127
- return;
4179
+ const colorized = this.colorize(...arguments_);
4180
+ if (!_Logger.DEBUG) return;
4128
4181
  const format = `${this.colorette.gray("<")}${(0, import_moment.default)().format("MM-DD-YYYY HH:mm:ss")}${this.colorette.gray(">")} ${this.colorette.gray(
4129
4182
  "["
4130
4183
  )}${this.color(`${this.name}`)}${this.colorette.gray("]")} ${this.colorette.gray("[")}${this.colorette.redBright("DEBUG")}${this.colorette.gray("]")}`;
4131
- console.info(format, ...arguments_);
4184
+ console.info(format, ...colorized);
4132
4185
  }
4133
4186
  /**
4134
4187
  * Logs a chat message to the console.
@@ -4136,12 +4189,21 @@ var Logger = class _Logger {
4136
4189
  * @param arguments_ - The arguments to log.
4137
4190
  */
4138
4191
  chat(...arguments_) {
4192
+ const colorized = this.colorize(...arguments_);
4139
4193
  const format = `${this.colorette.gray("<")}${(0, import_moment.default)().format("MM-DD-YYYY HH:mm:ss")}${this.colorette.gray(">")} ${this.colorette.gray(
4140
4194
  "["
4141
4195
  )}${this.color(`${this.name}`)}${this.colorette.gray("]")} ${this.colorette.gray("[")}${this.colorette.cyanBright("Chat")}${this.colorette.gray(
4142
4196
  "]"
4143
4197
  )}`;
4144
- console.info(format, arguments_[0], ">", arguments_[1]);
4198
+ console.info(format, colorized[0], ">", colorized[1]);
4199
+ }
4200
+ colorize(...arguments_) {
4201
+ const colorized = arguments_.map((argument) => {
4202
+ if (typeof argument === "string") {
4203
+ return formatMinecraftColorCode(argument);
4204
+ }
4205
+ });
4206
+ return colorized;
4145
4207
  }
4146
4208
  };
4147
4209
 
@@ -4169,7 +4231,8 @@ var LoggerColors = {
4169
4231
  // Annotate the CommonJS export names for ESM import in node:
4170
4232
  0 && (module.exports = {
4171
4233
  Logger,
4172
- LoggerColors
4234
+ LoggerColors,
4235
+ formatMinecraftColorCode
4173
4236
  });
4174
4237
  /*! Bundled license information:
4175
4238
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@serenityjs/logger",
3
- "version": "0.3.2",
3
+ "version": "0.3.3-beta-20240611195516",
4
4
  "main": "./dist/index.js",
5
5
  "types": "./dist/index.d.ts",
6
6
  "repository": "https://github.com/SerenityJS/serenity",
@@ -18,9 +18,9 @@
18
18
  "preset": "@serenityjs/jest-presets/jest/node"
19
19
  },
20
20
  "devDependencies": {
21
- "@serenityjs/eslint-config": "*",
22
- "@serenityjs/jest-presets": "*",
23
- "@serenityjs/typescript-config": "*",
21
+ "@serenityjs/eslint-config": "0.3.3-beta-20240611195516",
22
+ "@serenityjs/jest-presets": "0.3.3-beta-20240611195516",
23
+ "@serenityjs/typescript-config": "0.3.3-beta-20240611195516",
24
24
  "@types/jest": "^29.5.12",
25
25
  "@types/node": "^20.11.24",
26
26
  "jest": "^29.7.0",