npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

universal-console-manager

v1.0.1

Published

A lightweight, framework-agnostic utility for managing console output with fine-grained control. Easily disable or restore any console method conditionally.

Downloads

5

Readme

Universal JavaScript Console Manager

npm version License: MIT TypeScript

A lightweight, framework-agnostic utility for managing your console output with fine-grained control. Easily disable or restore any console method (log, info, warn, error, debug) conditionally — ideal for cleaning up production logs, controlling debug output, or enhancing app performance.

✨ Features

  • 🎯 Selective Control - Disable specific console methods or all at once
  • Instant Restoration - Restore original console methods instantly
  • 🌍 Environment Aware - Auto-disable in production environments
  • 🔧 Zero Dependencies - Works in Node.js, browsers, React, Next.js, Vue, or any JS runtime
  • 🚀 Simple API - Intuitive methods for seamless integration
  • 📘 TypeScript Support - Built-in type declarations included
  • 🔄 Chainable Methods - Fluent API for method chaining

📦 Installation

npm install universal-console-manager
yarn add universal-console-manager
pnpm add universal-console-manager

🚀 Quick Start

Basic Usage

import { consoleManager } from 'universal-console-manager';
// or const { consoleManager } = require('universal-console-manager');

// Disable specific console methods
consoleManager.disable(['log', 'info']);

console.log('This will not appear'); // Silent
console.warn('This will still appear'); // Shows warning
console.error('This will still appear'); // Shows error

// Restore methods
consoleManager.restore(['log', 'info']);
console.log('This will appear again'); // Shows log

Auto-Production Mode

import { consoleManager } from 'universal-console-manager';

// Configure for automatic production handling
consoleManager.configure({
  disableInProduction: true,
  preserveErrors: true, // Keep error/warn methods active
  methodsToDisable: ['log', 'info', 'debug']
});

// In production: log/info/debug are disabled
// In development: all methods work normally
console.log('Debug info'); // Silent in production
console.error('Critical error'); // Always visible

📚 API Reference

Core Methods

disable(methods)

Disable specific console methods.

consoleManager.disable('log');           // Disable single method
consoleManager.disable(['log', 'info']); // Disable multiple methods

restore(methods)

Restore console methods to their original state.

consoleManager.restore('log');           // Restore single method
consoleManager.restore(['log', 'info']); // Restore multiple methods

disableAll() / restoreAll()

Control all console methods at once.

consoleManager.disableAll();  // Disable all console methods
consoleManager.restoreAll();  // Restore all console methods

toggle(methods)

Toggle methods between enabled/disabled state.

consoleManager.toggle('log');           // Toggle single method
consoleManager.toggle(['log', 'info']); // Toggle multiple methods

Configuration

configure(options)

Set up console manager behavior.

consoleManager.configure({
  disableInProduction: true,    // Auto-disable in production
  preserveErrors: true,         // Keep error/warn active
  methodsToDisable: ['debug'],  // Default methods to disable
  silentMode: true             // Suppress manager warnings
});

Utility Methods

isDisabled(method)

Check if a method is currently disabled.

console.log(consoleManager.isDisabled('log')); // true/false

getDisabledMethods()

Get list of currently disabled methods.

console.log(consoleManager.getDisabledMethods()); // ['log', 'info']

getEnvironment()

Get current environment information.

console.log(consoleManager.getEnvironment());
// {
//   isProduction: false,
//   platform: 'browser',
//   disabledMethods: ['log']
// }

Advanced Features

createScopedConsole(methodsToDisable)

Create a console object with specific methods disabled.

const quietConsole = consoleManager.createScopedConsole(['log', 'info']);
quietConsole.log('Silent'); // No output
quietConsole.error('Visible'); // Shows error

disableTemporarily(methods, duration)

Disable methods for a specific time period.

consoleManager.disableTemporarily(['log'], 5000); // Disable for 5 seconds

conditionalDisable(predicate, methods)

Conditionally disable based on a function.

consoleManager.conditionalDisable(
  () => window.location.hostname.includes('prod'),
  ['log', 'debug']
);

🌐 Framework Examples

React/Next.js

// _app.js or layout.js
import { consoleManager } from 'universal-console-manager';

// Configure for Next.js
consoleManager.configure({
  disableInProduction: process.env.NODE_ENV === 'production',
  preserveErrors: true
});

export default function App({ Component, pageProps }) {
  return <Component {...pageProps} />;
}

Vue.js

// main.js
import { consoleManager } from 'universal-console-manager';

consoleManager.configure({
  disableInProduction: import.meta.env.PROD,
  methodsToDisable: ['log', 'info']
});

const app = createApp(App);
app.mount('#app');

Node.js/Express

// server.js
const { consoleManager } = require('universal-console-manager');

consoleManager.configure({
  disableInProduction: process.env.NODE_ENV === 'production',
  preserveErrors: true
});

// Your server code...

Browser Script

<script src="https://unpkg.com/universal-console-manager/index.js"></script>
<script>
  // Available as global: window.consoleManager
  consoleManager.disable(['log', 'info']);
</script>

🔧 Use Cases

1. Clean Production Console

// Automatically disable debug logs in production
consoleManager.configure({
  disableInProduction: true,
  preserveErrors: true
});

2. Demo Mode

// Clean console during demos/presentations
const enableDemoMode = () => {
  consoleManager.disableAll();
};

const disableDemoMode = () => {
  consoleManager.restoreAll();
};

3. Feature Flagging

// Conditional logging based on feature flags
consoleManager.conditionalDisable(
  () => !featureFlags.debugMode,
  ['debug', 'log']
);

4. Performance Optimization

// Disable verbose logging in performance-critical sections
const runPerformanceCriticalCode = () => {
  consoleManager.disable(['log', 'info', 'debug']);
  
  // Performance-critical code here
  performHeavyComputation();
  
  consoleManager.restore(['log', 'info', 'debug']);
};

5. Sensitive Data Protection

// Disable logging when handling sensitive data
const processSensitiveData = (data) => {
  consoleManager.disableTemporarily(['log', 'info'], 10000);
  
  // Process sensitive data without risk of logging
  return processPayment(data);
};

🎨 TypeScript Support

Full TypeScript support with comprehensive type definitions:

import { ConsoleManager, consoleManager, ConsoleMethods } from 'universal-console-manager';

// Type-safe method names
const methods: ConsoleMethods[] = ['log', 'info', 'warn'];
consoleManager.disable(methods);

// Type-safe configuration
consoleManager.configure({
  disableInProduction: true,
  preserveErrors: true,
  methodsToDisable: ['debug'] // Auto-completion available
});

🔍 Supported Console Methods

  • log - General logging
  • info - Informational messages
  • warn - Warning messages
  • error - Error messages
  • debug - Debug messages
  • trace - Stack trace
  • table - Tabular data
  • group / groupEnd / groupCollapsed - Grouped output
  • time / timeEnd - Performance timing
  • clear - Clear console

🌍 Environment Support

  • Browsers - All modern browsers
  • Node.js - Version 8.0.0+
  • React - All versions
  • Next.js - All versions
  • Vue.js - All versions
  • Angular - All versions
  • Electron - Full support
  • React Native - Full support

📄 License

MIT © Your Name

🤝 Contributing

Contributions, issues and feature requests are welcome!

  1. Fork the repository
  2. Create your feature branch (git checkout -b feature/amazing-feature)
  3. Commit your changes (git commit -m 'Add amazing feature')
  4. Push to the branch (git push origin feature/amazing-feature)
  5. Open a Pull Request

📈 Changelog

v1.0.0

  • Initial release
  • Core console management functionality
  • TypeScript support
  • Environment detection
  • Framework-agnostic design

Star this repo if you find it useful!