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

debugger_js

Package Overview
Dependencies
Maintainers
1
Versions
9
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

debugger_js - npm Package Compare versions

Comparing version 1.0.1 to 1.0.2

67

debugger.js

@@ -1,22 +0,34 @@

//Check for valid hexadecimal color
/**
* @function {checkHexColor} - A function to determine if a string is a valid hexadecimal color
* @param {string} color - A hexadecimal color value.
* @returns {boolean} - Returns true if the color parameter is a valid 3 or 6 digit hexadecimal color, false otherwise
*/
const checkHexColor = (color)=>/(^#[0-9A-F]{6}$)|(^#[0-9A-F]{3}$)/i.test(color);
//Make a log type
/**
* @function {logType} - A function to create a valid logType to be used when making a logger
* @param {object} opts - An object containg the possible options for this function
* @param {string} opts.logStyle - The style of logging this logType will generate. Possible values: log, warn, error, info. Default value: 'log'
* @param {string} opts.textColor - The text color this logType will generate. Default value: '#000' (Black)
* @param {string} opts.backgroundColor - The background color this logType will generate. Default value: '#fff' (white)
*/
const logType = (opts)=>{
let backgroundColor, logStyle, textColor;
//Values to be returned
let logStyle, textColor, backgroundColor;
if(['log', 'warn', 'error', 'info'].includes(opts.logStyle)) logStyle = opts.logStyle;
else{
logStyle = 'log';
console.warn('Invalid logStyle given as an options to function "logType". Defaulting to style "log" for logtype ' + opts.name + '.');
}
//Check if the logstyle is valid, default to 'log' if invalid
['log', 'warn', 'error', 'info'].includes(opts.logStyle) ? logStyle = opts.logStyle : logStyle = 'log';
//Check if the text color is a valid hex color, or default to black
checkHexColor(opts.textColor) ? textColor = opts.textColor : textColor = '#000';
//Check if the background color is a valid hex color, or default to white
checkHexColor(opts.backgroundColor) ? backgroundColor = opts.backgroundColor : backgroundColor = '#fff';
if(checkHexColor(opts.backgroundColor)) backgroundColor = opts.backgroundColor;
else backgroundColor = '#fff';
if(checkHexColor(opts.textColor)) textColor = opts.textColor;
else textColor = '#000';
return { backgroundColor, logStyle, textColor };
}
//Make a debug logger
/**
* @function {logType} - A function to create a debug logger
* @param {object} opts - An object containg the possible options for this function
* @param {object} opts.logTypes - A collection of logTypes created by the logType function
* @param {string} opts.debugModes - A collection of key value pairs where every key is a logType, and every value is a boolean whether or not that logType is being displayed. If no debugModes are provided, opts.logging will automatically be set to 'logNone'.
* @param {string} opts.logging - An optional parameter to set what will be logged. Possible values include 'logAll', 'logNone'. All other values will default to using the debugModes. logAll will log all debug messages, regardless of debugMode. logNone will log no debug messages, regardless of debugMode.
*/
const makeLogger = (opts)=>{

@@ -29,18 +41,26 @@ let logger = {};

else logger.logTypes = opts.logTypes;
logger.logTypes.log = logType({ name: 'log', logStyle: 'log' });
logger.logTypes.warn = logType({ name: 'warn', logStyle: 'warn' });
logger.logTypes.error = logType({ name: 'error', logStyle: 'error' });
logger.logTypes.info = logType({ name: 'info', logStyle: 'info' });
if(!opts.debugModes || typeof opts.debugModes !== 'object'){
console.warn('Missing or invalid parameter "debugModes" in function makeDebugger', opts);
opts.logging = 'logNone';
}
//Make default logging types
logger.logTypes.log = logType({ logStyle: 'log' });
logger.logTypes.warn = logType({ logStyle: 'warn' });
logger.logTypes.error = logType({ logStyle: 'error' });
logger.logTypes.info = logType({ logStyle: 'info' });
//If no debugModes are provided, or they are invalid, don't log anything
if(!opts.debugModes || typeof opts.debugModes !== 'object') opts.logging = 'logNone';
//Handle if all, none, or some logs are being displayed
switch(opts.logging){
//No logs displayed
case 'logAll':
for (var k in logger.logTypes) logger.logTypes[k].debugOn = true;
break;
//All logs displayed
case 'logNone':
console.warn('Logger (' + (opts.name || 'No Name Provided') + ') is displaying debug messages...');
for (var k in logger.logTypes) logger.logTypes[k].debugOn = false;
break;
//Some logs displayed
default:
console.warn('Logger (' + (opts.name || 'No Name Provided') + ') is displaying debug messages...');
for (var k in logger.logTypes){

@@ -52,2 +72,3 @@ if(opts.debugModes[k]) logger.logTypes[k].debugOn = opts.debugModes[k];

}
//The logging function exposed by this object
logger.log = (type, message, data)=>{

@@ -54,0 +75,0 @@ if (logger.logTypes[type]){

{
"name": "debugger_js",
"version": "1.0.1",
"version": "1.0.2",
"description": "A library for debug logging in javascript",

@@ -5,0 +5,0 @@ "main": "debugger.js",

# debugger_js
A small utility library for debugging front end javascript code. Details in progress.
A small utility library for logging front end javascript code.
<dl>
<dt><a href="#{checkHexColor} - A function to determine if a string is a valid hexadecimal color">{checkHexColor} - A function to determine if a string is a valid hexadecimal color(color)<
/a> ⇒ <code>boolean</code></dt>
<dd></dd>
<dt><a href="#{logType} - A function to create a valid logType to be used when making a logger">{logType} - A function to create a valid logType to be used when making a logger(opts)</a></
dt>
<dd></dd>
<dt><a href="#{logType} - A function to create a debug logger">{logType} - A function to create a debug logger(opts)</a></dt>
<dd></dd>
</dl>
<a name="{checkHexColor} - A function to determine if a string is a valid hexadecimal color"></a>
## {checkHexColor} - A function to determine if a string is a valid hexadecimal color(color) ⇒ <code>boolean</code>
**Kind**: global function
**Returns**: <code>boolean</code> - - Returns true if the color parameter is a valid 3 or 6 digit hexadecimal color, false otherwise
| Param | Type | Description |
| --- | --- | --- |
| color | <code>string</code> | A hexadecimal color value. |
<a name="{logType} - A function to create a valid logType to be used when making a logger"></a>
## {logType} - A function to create a valid logType to be used when making a logger(opts)
**Kind**: global function
| Param | Type | Description |
| --- | --- | --- |
| opts | <code>object</code> | An object containg the possible options for this function |
| opts.logStyle | <code>string</code> | The style of logging this logType will generate. Possible values: log, warn, error, info. Default value: 'log' |
| opts.textColor | <code>string</code> | The text color this logType will generate. Default value: '#000' (Black) |
| opts.backgroundColor | <code>string</code> | The background color this logType will generate. Default value: '#fff' (white) |
<a name="{logType} - A function to create a debug logger"></a>
## {logType} - A function to create a debug logger(opts)
**Kind**: global function
| Param | Type | Description |
| --- | --- | --- |
| opts | <code>object</code> | An object containg the possible options for this function |
| opts.logTypes | <code>object</code> | A collection of logTypes created by the logType function |
| opts.debugModes | <code>string</code> | A collection of key value pairs where every key is a logType, and every value is a boolean whether or not that logType is being displayed. If no d
ebugModes are provided, opts.logging will automatically be set to 'logNone'. |
| opts.logging | <code>string</code> | An optional parameter to set what will be logged. Possible values include 'logAll', 'logNone'. All other values will default to using the debugModes.
logAll will log all debug messages, regardless of debugMode. logNone will log no debug messages, regardless of debugMode. |
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