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

console-styles

Package Overview
Dependencies
Maintainers
1
Versions
27
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

console-styles - npm Package Compare versions

Comparing version 0.2.4 to 1.0.0

npm-debug.log.126656780

4

index.d.ts

@@ -29,2 +29,6 @@ declare module "console-styles" {

inverse: this;
upper: this;
lower: this;
trim: this;
timestamp: this;
log(...text: string): void

@@ -31,0 +35,0 @@ }

75

index.js

@@ -31,30 +31,65 @@ const { format } = require("util");

let open = [];
let close = [];
const modifiers = {
upper: text => text.toUpperCase(),
lower: text => text.toLowerCase(),
trim: text => text.trim(),
timestamp: text => {
const date = new Date();
const hours = date.getHours();
const minutes = date.getMinutes();
const seconds = date.getSeconds();
const timestamp = `[` +
`${hours < 10 ? `0${hours}` : hours}:` +
`${minutes < 10 ? `0${minutes}` : minutes}:` +
`${seconds < 10 ? `0${seconds}` : seconds}` +
`]`;
return `${timestamp}${text}`;
}
}
const base = new Proxy(function() {}, {
get: function (target, prop, receiver) {
const styler = new Proxy({}, {
get: function (t, prop, rec) {
const baseTarget = function() {}
baseTarget.open = [];
baseTarget.close = [];
baseTarget.mods = [];
if (prop in codes) {
if (!open.includes(codes[prop][0])) open.push(codes[prop][0]);
if (!close.includes(codes[prop][1])) close.push(codes[prop][1]);
} else if (prop === "log") {
baseTarget.open.push(codes[prop][0]);
baseTarget.close.push(codes[prop][1]);
}
else if (prop in modifiers) baseTarget.mods.push(prop);
else if (prop === "log") {
return (...args) => {
const output = this.apply(target, null, args);
process.stdout.write(`${format(output)}\n`);
};
}
return receiver;
},
apply: function (target, thisArg, args) {
let styled = args.join(" ");
for (const o of open) styled = `\u001b[${o}m${styled}`;
for (const c of close) styled = `${styled}\u001b[${c}m`;
open = []; close = [];
return styled;
process.stdout.write(`${format(args.join(" "))}\n`);
}
} else return rec;
return new Proxy(baseTarget, {
get: function (t, prop, rec) {
if (prop in codes) {
if (!t.open.includes(codes[prop][0])) t.open.push(codes[prop][0]);
if (!t.close.includes(codes[prop][1])) t.close.push(codes[prop][1]);
}
else if (prop in modifiers && !t.mods.includes(prop)) t.mods.push(prop);
else if (prop === "log") {
return (...args) => {
const output = this.apply(t, null, args);
process.stdout.write(`${format(output)}\n`);
};
}
return rec;
},
apply: function (t, thisArg, args) {
let styled = args.join(" ");
for (const m of t.mods) styled = modifiers[m](styled);
for (const o of t.open) styled = `\u001b[${o}m${styled}`;
for (const c of t.close) styled = `${styled}\u001b[${c}m`;
return styled;
}
});
}
});
module.exports = styler;
{
"name": "console-styles",
"version": "0.2.4",
"version": "1.0.0",
"typings": "index.d.ts",

@@ -5,0 +5,0 @@ "description": "a styled console logger with no dependencies",

@@ -25,2 +25,4 @@ # About

console.log(styler.black.bgCyan("this is great Kappa", "hello"));
console.log(styler.red("nested", styler.blue("colours")));
```

@@ -27,0 +29,0 @@

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