Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@homer0/simple-logger

Package Overview
Dependencies
Maintainers
1
Versions
21
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@homer0/simple-logger - npm Package Compare versions

Comparing version 2.0.1 to 2.0.2

86

./dist/index.js

@@ -22,2 +22,6 @@ "use strict";

var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
// If the importer is in node compatibility mode or this is not an ESM
// file that has been converted to a CommonJS file using a Babel-
// compatible transform (i.e. "__esModule" has not been set), then set
// "default" to the CommonJS "module.exports" for node compatibility.
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,

@@ -45,3 +49,9 @@ mod

constructor({ prefix = "", showTime = false } = {}) {
/**
* A prefix to include in front of all the messages.
*/
__publicField(this, "prefix");
/**
* Whether or not to show the time on each message.
*/
__publicField(this, "showTime");

@@ -56,2 +66,29 @@ this.prefix = prefix;

}
/**
* Logs a message with an specific color on the console.
*
* @param message A text message to log or a list of them.
* @param color The color of the message (the default is the terminal default).
* This can be overwritten line by line when the message is an array,
* take a look at the example.
* @example
*
* // Simple
* logger.log('hello world');
* // Custom color
* logger.log('It was the shadow who did it', 'red');
* // A list of messages all the same color
* logger.log(["Ph'nglu", "mglw'nafh"], 'grey');
* // A list of messages with different colors per line
* logger.log(
* [
* "Ph'nglu",
* "mglw'nafh",
* ['Cthulhu', 'green'],
* ["R'lyeh wgah'nagl fhtagn", 'red'],
* ],
* 'grey',
* );
*
*/
log(message, color = "raw") {

@@ -72,11 +109,44 @@ const lines = [];

}
/**
* Logs a success (green) message or messages on the console.
*
* @param message A single message of a list of them.
* @see {@link SimpleLogger.log}
*/
success(message) {
this.log(message, "green");
}
/**
* Logs an information (gray) message or messages on the console.
*
* @param message A single message of a list of them.
* @see {@link SimpleLogger.log}
*/
info(message) {
this.log(message, "grey");
}
/**
* Logs a warning (yellow) message or messages on the console.
*
* @param message A single message of a list of them.
* @see {@link SimpleLogger.log}
*/
warn(message) {
this.log(message, "yellow");
}
/**
* Logs an error (red) message or messages on the console.
*
* @param message A single message of a list of them.
* See the `log()` documentation to see all the supported
* properties for the `message` parameter. Different from the other
* log methods, you can use an `Error` object and the method will
* take care of extracting the message and the stack information.
* @param exception If the exception has a `stack`
* property, the method will log each of the stack calls using
* `info()`.
* @template ErrorType The type of the exception, to be infered and validate if it
* has a `stack` property.
* @see {@link SimpleLogger.log}
*/
error(message, exception) {

@@ -98,2 +168,8 @@ if (message instanceof Error) {

}
/**
* Prefixes a message with the text sent to the constructor and, if enabled, the current
* time.
*
* @param text The text that needs the prefix.
*/
addPrefix(text) {

@@ -105,3 +181,3 @@ const parts = [];

if (this.showTime) {
const time = new Date().toISOString().replace(/T/, " ").replace(/\..+/, "");
const time = (/* @__PURE__ */ new Date()).toISOString().replace(/T/, " ").replace(/\..+/, "");
parts.push(`[${time}]`);

@@ -112,2 +188,10 @@ }

}
/**
* Gets a function to modify the color of a string. The reason for this _"proxy method"_
* is that the `colors` module doesn't have a `raw` option and the alternative would've
* been adding a few `if`s on the `log` method.
*
* @param color The name of the color.
* @returns A function that receives a string and returns it colored.
*/
getColorFn(color) {

@@ -114,0 +198,0 @@ if (color === "raw") {

@@ -13,3 +13,9 @@ var __defProp = Object.defineProperty;

constructor({ prefix = "", showTime = false } = {}) {
/**
* A prefix to include in front of all the messages.
*/
__publicField(this, "prefix");
/**
* Whether or not to show the time on each message.
*/
__publicField(this, "showTime");

@@ -24,2 +30,29 @@ this.prefix = prefix;

}
/**
* Logs a message with an specific color on the console.
*
* @param message A text message to log or a list of them.
* @param color The color of the message (the default is the terminal default).
* This can be overwritten line by line when the message is an array,
* take a look at the example.
* @example
*
* // Simple
* logger.log('hello world');
* // Custom color
* logger.log('It was the shadow who did it', 'red');
* // A list of messages all the same color
* logger.log(["Ph'nglu", "mglw'nafh"], 'grey');
* // A list of messages with different colors per line
* logger.log(
* [
* "Ph'nglu",
* "mglw'nafh",
* ['Cthulhu', 'green'],
* ["R'lyeh wgah'nagl fhtagn", 'red'],
* ],
* 'grey',
* );
*
*/
log(message, color = "raw") {

@@ -40,11 +73,44 @@ const lines = [];

}
/**
* Logs a success (green) message or messages on the console.
*
* @param message A single message of a list of them.
* @see {@link SimpleLogger.log}
*/
success(message) {
this.log(message, "green");
}
/**
* Logs an information (gray) message or messages on the console.
*
* @param message A single message of a list of them.
* @see {@link SimpleLogger.log}
*/
info(message) {
this.log(message, "grey");
}
/**
* Logs a warning (yellow) message or messages on the console.
*
* @param message A single message of a list of them.
* @see {@link SimpleLogger.log}
*/
warn(message) {
this.log(message, "yellow");
}
/**
* Logs an error (red) message or messages on the console.
*
* @param message A single message of a list of them.
* See the `log()` documentation to see all the supported
* properties for the `message` parameter. Different from the other
* log methods, you can use an `Error` object and the method will
* take care of extracting the message and the stack information.
* @param exception If the exception has a `stack`
* property, the method will log each of the stack calls using
* `info()`.
* @template ErrorType The type of the exception, to be infered and validate if it
* has a `stack` property.
* @see {@link SimpleLogger.log}
*/
error(message, exception) {

@@ -66,2 +132,8 @@ if (message instanceof Error) {

}
/**
* Prefixes a message with the text sent to the constructor and, if enabled, the current
* time.
*
* @param text The text that needs the prefix.
*/
addPrefix(text) {

@@ -73,3 +145,3 @@ const parts = [];

if (this.showTime) {
const time = new Date().toISOString().replace(/T/, " ").replace(/\..+/, "");
const time = (/* @__PURE__ */ new Date()).toISOString().replace(/T/, " ").replace(/\..+/, "");
parts.push(`[${time}]`);

@@ -80,2 +152,10 @@ }

}
/**
* Gets a function to modify the color of a string. The reason for this _"proxy method"_
* is that the `colors` module doesn't have a `raw` option and the alternative would've
* been adding a few `if`s on the `log` method.
*
* @param color The name of the color.
* @returns A function that receives a string and returns it colored.
*/
getColorFn(color) {

@@ -82,0 +162,0 @@ if (color === "raw") {

@@ -22,2 +22,6 @@ "use strict";

var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
// If the importer is in node compatibility mode or this is not an ESM
// file that has been converted to a CommonJS file using a Babel-
// compatible transform (i.e. "__esModule" has not been set), then set
// "default" to the CommonJS "module.exports" for node compatibility.
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,

@@ -45,3 +49,9 @@ mod

constructor({ prefix = "", showTime = false } = {}) {
/**
* A prefix to include in front of all the messages.
*/
__publicField(this, "prefix");
/**
* Whether or not to show the time on each message.
*/
__publicField(this, "showTime");

@@ -56,2 +66,29 @@ this.prefix = prefix;

}
/**
* Logs a message with an specific color on the console.
*
* @param message A text message to log or a list of them.
* @param color The color of the message (the default is the terminal default).
* This can be overwritten line by line when the message is an array,
* take a look at the example.
* @example
*
* // Simple
* logger.log('hello world');
* // Custom color
* logger.log('It was the shadow who did it', 'red');
* // A list of messages all the same color
* logger.log(["Ph'nglu", "mglw'nafh"], 'grey');
* // A list of messages with different colors per line
* logger.log(
* [
* "Ph'nglu",
* "mglw'nafh",
* ['Cthulhu', 'green'],
* ["R'lyeh wgah'nagl fhtagn", 'red'],
* ],
* 'grey',
* );
*
*/
log(message, color = "raw") {

@@ -72,11 +109,44 @@ const lines = [];

}
/**
* Logs a success (green) message or messages on the console.
*
* @param message A single message of a list of them.
* @see {@link SimpleLogger.log}
*/
success(message) {
this.log(message, "green");
}
/**
* Logs an information (gray) message or messages on the console.
*
* @param message A single message of a list of them.
* @see {@link SimpleLogger.log}
*/
info(message) {
this.log(message, "grey");
}
/**
* Logs a warning (yellow) message or messages on the console.
*
* @param message A single message of a list of them.
* @see {@link SimpleLogger.log}
*/
warn(message) {
this.log(message, "yellow");
}
/**
* Logs an error (red) message or messages on the console.
*
* @param message A single message of a list of them.
* See the `log()` documentation to see all the supported
* properties for the `message` parameter. Different from the other
* log methods, you can use an `Error` object and the method will
* take care of extracting the message and the stack information.
* @param exception If the exception has a `stack`
* property, the method will log each of the stack calls using
* `info()`.
* @template ErrorType The type of the exception, to be infered and validate if it
* has a `stack` property.
* @see {@link SimpleLogger.log}
*/
error(message, exception) {

@@ -98,2 +168,8 @@ if (message instanceof Error) {

}
/**
* Prefixes a message with the text sent to the constructor and, if enabled, the current
* time.
*
* @param text The text that needs the prefix.
*/
addPrefix(text) {

@@ -105,3 +181,3 @@ const parts = [];

if (this.showTime) {
const time = new Date().toISOString().replace(/T/, " ").replace(/\..+/, "");
const time = (/* @__PURE__ */ new Date()).toISOString().replace(/T/, " ").replace(/\..+/, "");
parts.push(`[${time}]`);

@@ -112,2 +188,10 @@ }

}
/**
* Gets a function to modify the color of a string. The reason for this _"proxy method"_
* is that the `colors` module doesn't have a `raw` option and the alternative would've
* been adding a few `if`s on the `log` method.
*
* @param color The name of the color.
* @returns A function that receives a string and returns it colored.
*/
getColorFn(color) {

@@ -114,0 +198,0 @@ if (color === "raw") {

16

package.json
{
"name": "@homer0/simple-logger",
"description": "A small service to log messages in the console",
"version": "2.0.1",
"version": "2.0.2",
"repository": {

@@ -26,12 +26,12 @@ "type": "git",

"dependencies": {
"@homer0/jimple": "^2.0.1",
"@homer0/package-info": "^2.0.1",
"@homer0/path-utils": "^2.0.1",
"@homer0/jimple": "^2.0.2",
"@homer0/package-info": "^2.0.2",
"@homer0/path-utils": "^2.0.2",
"colors": "^1.4.0"
},
"devDependencies": {
"jest": "^29.4.1",
"jest": "^29.4.3",
"ts-jest": "^29.0.5",
"tsup": "^6.5.0",
"typescript": "^4.9.4"
"tsup": "^6.6.3",
"typescript": "^4.9.5"
},

@@ -52,3 +52,3 @@ "engine-strict": true,

},
"gitHead": "59c0f6af6901b9f4edb8d2ec36abaf11f6b0780d"
"gitHead": "1ed6ea29e2035f10f0dff60203b6b1d54c601dc8"
}

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc