New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

color-loggers

Package Overview
Dependencies
Maintainers
0
Versions
8
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

color-loggers - npm Package Compare versions

Comparing version 0.2.0 to 0.3.0

lib/styles.d.ts

10

lib/index.d.ts
type Prefix = string | (() => string);
declare class Color {
export declare class Color {
color: string;
prefix: Prefix;
private disabled;
constructor(color: string, prefix?: Prefix);
log(message: string): void;
disable(): void;
}

@@ -17,2 +19,8 @@ export declare class Blue extends Color {

}
export declare class Black extends Color {
constructor(prefix?: Prefix);
}
export declare class White extends Color {
constructor(prefix?: Prefix);
}
export {};

@@ -18,6 +18,8 @@ "use strict";

Object.defineProperty(exports, "__esModule", { value: true });
exports.Red = exports.Green = exports.Blue = void 0;
exports.White = exports.Black = exports.Red = exports.Green = exports.Blue = exports.Color = void 0;
var styles_1 = require("./styles");
var Color = /** @class */ (function () {
function Color(color, prefix) {
if (prefix === void 0) { prefix = ''; }
this.disabled = false;
this.color = color;

@@ -27,10 +29,16 @@ this.prefix = prefix;

Color.prototype.log = function (message) {
var prefix = this.prefix;
if (prefix instanceof Function) {
prefix = prefix();
if (!this.disabled) {
var prefix = this.prefix;
if (prefix instanceof Function) {
prefix = prefix();
}
console.log([this.color, prefix, message, styles_1.default.Reset].join(''));
}
console.log(this.color, prefix, message, '\x1b[0m');
};
Color.prototype.disable = function () {
this.disabled = true;
};
return Color;
}());
exports.Color = Color;
var Blue = /** @class */ (function (_super) {

@@ -40,3 +48,3 @@ __extends(Blue, _super);

if (prefix === void 0) { prefix = '[Info]:'; }
return _super.call(this, '\x1b[34m', prefix) || this;
return _super.call(this, styles_1.default.FgBlue, prefix) || this;
}

@@ -50,3 +58,3 @@ return Blue;

if (prefix === void 0) { prefix = '[Done]:'; }
return _super.call(this, '\x1b[32m', prefix) || this;
return _super.call(this, styles_1.default.FgGreen, prefix) || this;
}

@@ -60,3 +68,3 @@ return Green;

if (prefix === void 0) { prefix = '[Error]:'; }
return _super.call(this, '\x1b[31m', prefix) || this;
return _super.call(this, styles_1.default.FgRed, prefix) || this;
}

@@ -66,1 +74,19 @@ return Red;

exports.Red = Red;
var Black = /** @class */ (function (_super) {
__extends(Black, _super);
function Black(prefix) {
if (prefix === void 0) { prefix = ''; }
return _super.call(this, styles_1.default.FgBlack, prefix) || this;
}
return Black;
}(Color));
exports.Black = Black;
var White = /** @class */ (function (_super) {
__extends(White, _super);
function White(prefix) {
if (prefix === void 0) { prefix = ''; }
return _super.call(this, styles_1.default.FgWhite, prefix) || this;
}
return White;
}(Color));
exports.White = White;

31

package.json
{
"name": "color-loggers",
"version": "0.2.0",
"version": "0.3.0",
"license": "MIT",

@@ -13,16 +13,21 @@ "main": "lib/index.js",

"devDependencies": {
"@types/node": "^18.15.11",
"@typescript-eslint/eslint-plugin": "^5.57.0",
"@typescript-eslint/parser": "^5.57.0",
"eslint": "^8.37.0",
"eslint-config-alloy": "^4.9.0",
"eslint-config-prettier": "^8.8.0",
"eslint-plugin-prettier": "^4.2.1",
"prettier": "^2.8.7",
"sort-package-json": "^2.4.1",
"ts-node": "^10.9.1",
"ttpt": "^0.5.3",
"typescript": "^5.0.3",
"@types/node": "^20.14.11",
"@typescript-eslint/eslint-plugin": "^7.16.1",
"@typescript-eslint/parser": "^7.16.1",
"eslint": "8.57.0",
"eslint-config-alloy": "^5.1.2",
"eslint-config-prettier": "^9.1.0",
"eslint-plugin-prettier": "^5.2.1",
"prettier": "^3.3.3",
"sort-package-json": "^2.10.0",
"ts-node": "^10.9.2",
"ttpt": "^0.9.6",
"typescript": "^5.5.3",
"yarn-upgrade-all": "^0.7.2"
},
"yarn-upgrade-all": {
"ignore": [
"eslint"
]
}
}

@@ -55,1 +55,19 @@ # color loggers

```
## Choose another color
```ts
import { Color } from 'color-loggers';
import Styles from 'color-loggers/styles';
const logger = new Color(Styles.FgWhite, '');
logger.log('This is a white text.');
```
## Disable logger
```ts
const logger = new Color(Styles.FgWhite, '');
logger.disable();
logger.log('This is a white text.'); // will not be printed
```

@@ -0,6 +1,9 @@

import Styles from './styles';
type Prefix = string | (() => string);
class Color {
export class Color {
public color: string;
public prefix: Prefix;
private disabled = false;

@@ -13,8 +16,14 @@ public constructor(color: string, prefix: Prefix = '') {

public log(message: string) {
let prefix = this.prefix;
if (prefix instanceof Function) {
prefix = prefix();
if (!this.disabled) {
let prefix = this.prefix;
if (prefix instanceof Function) {
prefix = prefix();
}
console.log([this.color, prefix, message, Styles.Reset].join(''));
}
console.log(this.color, prefix, message, '\x1b[0m');
}
public disable() {
this.disabled = true;
}
}

@@ -24,3 +33,3 @@

public constructor(prefix: Prefix = '[Info]:') {
super('\x1b[34m', prefix);
super(Styles.FgBlue, prefix);
}

@@ -31,3 +40,3 @@ }

public constructor(prefix: Prefix = '[Done]:') {
super('\x1b[32m', prefix);
super(Styles.FgGreen, prefix);
}

@@ -38,4 +47,16 @@ }

public constructor(prefix: Prefix = '[Error]:') {
super('\x1b[31m', prefix);
super(Styles.FgRed, prefix);
}
}
export class Black extends Color {
public constructor(prefix: Prefix = '') {
super(Styles.FgBlack, prefix);
}
}
export class White extends Color {
public constructor(prefix: Prefix = '') {
super(Styles.FgWhite, prefix);
}
}

@@ -1,2 +0,3 @@

import { Blue, Green, Red } from './index';
import { Blue, Green, Red, Color } from './index';
import Styles from './styles';

@@ -21,1 +22,6 @@ const info = new Blue();

info3.log('This is an information.');
const info4 = new Color(Styles.FgWhite, '');
info4.log('This is the last message.');
info4.disable();
info4.log('This message should not be displayed.');
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