Socket
Socket
Sign inDemoInstall

levelheaded

Package Overview
Dependencies
0
Maintainers
1
Versions
4
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    levelheaded

⚖️ Generate object containing functions deemed operational by level


Version published
0
Maintainers
1
Install size
5.47 kB
Created
Weekly downloads
 

Readme

Source

levelheaded

⚖️ Generate object containing functions deemed operational by level

Assigns functions by level. Functions lower than the minimal level will be assigned with no operation, while minimal level and above are assigned the desired operation.

OptionTypeMeaningDefault
levelsArray[String]Levels will become functions[ 'debug', 'verbose', 'info', 'warn', 'error', 'critical' ]
minimalStringMinimal level to executelevels[0]
actionFunctionThe action to execute when minimal level was matchedconsole.log
objectObjectAn object to assign the functions on{}
noopFunctionFunction to call when event should not be triggered()=>undefined

ℹ️ All options are optional

import levelheaded from 'levelheaded';

const logger = levelheaded({
	minimal: isDevelopment() ? 'debug' : 'warn',
	action: function (message) {
		fetch(
			'https://error.logger.com',
			{
				method: 'POST',
				body: JSON.stringify({
					message,
					url: document.location.href,
					level: this.level,
				})
			}
		);
	}
})

logger.debug('Something trivial'); // ⛔️ Won't fire
logger.error('Something I need to know'); // ✅ Will fire

Custom levels

const logger = levelheaded({
	levels: ['a', 'b', 'c'],
	minimal: 'b',
});

logger.a('Something'); // ⛔️ Won't fire
logger.b('Something'); // ✅ Will fire

Transpiled version

Environments which exclude node_modules from the transpiling pipeline should include the "browser" entry instead of "main". This exposes an ES5 commonjs module.

Also available for explicit import:

const reduce = require('levelheaded/dist');

Keywords

FAQs

Last updated on 15 Jan 2019

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

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