Socket
Socket
Sign inDemoInstall

console-stamp

Package Overview
Dependencies
7
Maintainers
1
Versions
35
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 3.0.6 to 3.1.0

18

index.d.ts

@@ -10,2 +10,16 @@ export type Token = ( payload?: TokenPayload ) => string | number;

export interface SpyStream extends NodeJS.WriteStream{
length: number
last: string
flush: ()=>void
asArray: string[]
}
declare global {
interface Console {
reset: () => void;
org: Console
}
}
declare function consoleStamp(console: Console, options?: {

@@ -17,4 +31,4 @@ format?: string

extend?: Record<string, number>
stdout?: NodeJS.WriteStream
stderr?: NodeJS.WriteStream
stdout?: NodeJS.WriteStream | SpyStream
stderr?: NodeJS.WriteStream | SpyStream
use_custom_message?: boolean

@@ -21,0 +35,0 @@ }): void;

38

index.js

@@ -8,15 +8,8 @@ const { checkLogLevel, generateConfig, generatePrefix, selectOutputStream, FakeStream } = require( './lib/utils.js' );

const isCustom = con !== console;
const customConsoleStream = new FakeStream();
const customConsole = new console.Console( customConsoleStream, customConsoleStream );
const helperConsoleStream = new FakeStream();
const helperConsole = new console.Console( helperConsoleStream, helperConsoleStream );
// Fix the lack of debug alias in pre 8.0 node
if ( typeof con.debug === "undefined" ) {
con.debug = ( ...arg ) => con.org.log ? con.org.log( ...arg ) : con.log( ...arg );
}
const config = generateConfig( options );
const include = config.include.filter( m => typeof con[m] === 'function' );
const helperConsole = new console.Console( config.stdout, config.stderr );
const org = {};

@@ -33,15 +26,14 @@ Object.keys( con ).forEach( m => org[m] = con[m] );

if ( checkLogLevel( config, method ) ) {
customConsole.log.apply( context, args );
stream.write( `${generatePrefix( method, config, customConsoleStream.last_msg )} ` );
if ( config.preventDefaultMessage || /:msg\b/.test( config.format ) ) {
stream.write('\n');
}else if(method === 'table'){
stream.write('\n');
// Normaly table calls log to write to stream, so we need to prevent double prefix
helperConsole.log.apply( context, args );
// TODO: custom msg vs table will not work
let outputMessage = `${generatePrefix( method, config, helperConsoleStream.last_msg )} `;
if(method === 'table'){
outputMessage += '\n';
helperConsole.table.apply( context, args);
}else if( !isCustom && options.stdout){
stream.write(`${customConsoleStream.last_msg}\n`);
} else {
target.apply( context, args );
outputMessage += helperConsoleStream.last_msg;
}else if(!( config.preventDefaultMessage || /:msg\b/.test( config.format ) )){
outputMessage += `${helperConsoleStream.last_msg}`;
}
outputMessage += '\n';
stream.write( outputMessage );
}

@@ -56,3 +48,4 @@ }

// Normaly table calls log to write to stream, we need to prevent prefix when table is not included
con.table = helperConsole.table;
const tableConsole = new console.Console( config.stdout, config.stderr );
con.table = tableConsole.table;
}

@@ -68,3 +61,3 @@

delete con.reset;
customConsoleStream.end();
helperConsoleStream.end();
};

@@ -76,1 +69,2 @@

module.exports.default = consoleStamp;

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

const date = require( '../tokens/date.js' );
const { label } = require( '../tokens/label.js' );
const date = require( '../tokens/date' );
const label = require( '../tokens/label' );
const msg = require( '../tokens/msg' );

@@ -4,0 +4,0 @@

{
"name": "console-stamp",
"main": "index.js",
"version": "3.0.6",
"version": "3.1.0",
"scripts": {

@@ -13,3 +13,3 @@ "test": "tap --no-check-coverage -R spec test/*.js",

"engines": {
"node": ">=10"
"node": ">=12"
},

@@ -82,3 +82,2 @@ "author": {

"@types/node": "^17.0.31",
"moment": "^2.29.3",
"nodemon": "^2.0.16",

@@ -85,0 +84,0 @@ "tap": "^16.1.0"

const dateformat = require( 'dateformat' );
// noinspection JSUnusedLocalSymbols
module.exports = ( { params: [format, utc = false, date = new Date] } ) => {
return `[${dateformat( date, format, utc )}]`;
}

@@ -1,12 +0,3 @@

function padRight ( str, len = 0 ) {
return str + ' '.repeat( Math.max( len - str.length, 0 ) );
}
function label( { method, params: [len] } ) {
return padRight( `[${method.toUpperCase()}]`, len );
}
module.exports = {
padRight,
label
};
module.exports = ( { method, params: [len] } ) => {
return `[${method.toUpperCase()}]`.padEnd(len);
}
SocketSocket SOC 2 Logo

Product

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

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc