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

emit-io-core

v2.0.0

Published

A flexible and type-safe logging system for JavaScript/TypeScript applications

Readme

emit-io-core

Core logging + analytics library for TypeScript — Node, browser, edge, React Native.

Install

npm install emit-io-core

Quick Start

import {
  EmitIoStrategy,
  ConsoleTransport,
  JSONTransport,
  HTTPTransport,
  redact,
  sample,
  LogLevelEnum,
} from 'emit-io-core'

const emit = new EmitIoStrategy({
  transports: [
    new ConsoleTransport({ minLevel: LogLevelEnum.DEBUG, pretty: true }),
    new JSONTransport({ minLevel: LogLevelEnum.INFO }),
  ],
  plugins: [
    redact({ paths: ['password', '*.secret'] }),
    sample({ rate: 0.1, levels: [LogLevelEnum.DEBUG] }),
  ],
  consent: { analytics: true, errors: true },
})

// Structured log levels
emit.debug('query executed', { sql: 'SELECT 1', ms: 3 })
emit.info('server started', { port: 3000 })
emit.warn('slow response', { ms: 1200 })
emit.error('db connection lost', { host: 'pg-primary' })
emit.fatal('out of memory')

// Analytics error — writes to transport AND dispatches to providers
emit.captureError('Auth', 'login_failed', true, new Error('bad token'), { userId: 'u-1' })

// Analytics event
emit.event('purchase', { orderId: 'x', total: 99 })

// Feature info (analytics + transport)
emit.logFeature('Checkout', 'step_completed', { step: 2 })

API

new EmitIoStrategy(config?)

interface EmitIoStrategyConfig {
  transports?: Transport[]
  providers?: AnalyticsProvider[]
  plugins?: Plugin[]
  consent?: { analytics?: boolean; errors?: boolean }
  preInitBuffer?: { size?: number }
  emitAppOpenOnInit?: boolean
}

Log level methods

| Method | Level | Description | |---|---|---| | debug(msg, ctx?) | DEBUG | Verbose debug output | | info(msg, ctx?) | INFO | Informational | | warn(msg, ctx?) | WARN | Warning | | error(msg, ctx?) | ERROR | Structured error log | | fatal(msg, ctx?) | FATAL | Fatal / process-ending |

Analytics methods

| Method | Description | |---|---| | captureError(feature, name, critical, err, extra?) | Error to transports + providers | | event(name, properties?) | Custom analytics event | | logFeature(feature, name, properties?) | Analytics + transport info | | logScreen(name, params?) | Screen / page view | | setUser(user) | Identify user (requires id) | | setUserId(id) | Set user ID only | | setUserProperty(name, value) | Set one user property | | setUserProperties(props) | Set multiple user properties | | logBeginCheckout(checkoutId, params) | E-commerce checkout start | | logPaymentSuccess(checkoutId, params) | E-commerce payment |

Other methods

| Method | Description | |---|---| | child(bindings) | Returns a new logger that merges bindings into every entry | | addTransport(t) | Add a transport at runtime | | addPlugin(p) | Add a plugin at runtime | | addProvider(p) | Add a provider at runtime | | setConsent(state) | Update consent flags | | getConsent() | Read current consent state | | init() | Initialize providers + flush pre-init buffer | | flush() | Sync flush all transports | | close() | Async flush then stop | | reset() | Reset user state on all providers |

Transports

All transports accept enabled?: boolean (default true). Set to false at construction or toggle at runtime to control delivery via feature flags.

ConsoleTransport

new ConsoleTransport({ minLevel: LogLevelEnum.DEBUG, pretty: true })
// Disable console logging in production:
new ConsoleTransport({ enabled: process.env.NODE_ENV !== 'production' })

JSONTransport

new JSONTransport({ minLevel: LogLevelEnum.INFO })
// Custom write (e.g. file stream):
new JSONTransport({ write: (line) => fs.appendFileSync('app.log', line) })

HTTPTransport

new HTTPTransport({
  url: 'https://logs.example.com/ingest',
  minLevel: LogLevelEnum.WARN,
  enabled: process.env.NODE_ENV === 'production',
  batchSize: 50,
  flushIntervalMs: 5000,
  maxRetries: 3,
  retryBackoffMs: 1000,
  headers: { Authorization: 'Bearer token' },
})

DevToolsTransport

new DevToolsTransport({ url: 'ws://localhost:9999' })
// Only active in development:
new DevToolsTransport({ enabled: __DEV__ })

Connects via WebSocket to a devtools panel. Buffers entries while disconnected and drains on reconnect.

Plugins

Built-in plugins are plain (entry: LogEntry) => LogEntry | null functions.

import { redact, sample, rateLimit, normalizeStack } from 'emit-io-core'

redact({ paths: ['password', 'user.token', '*.secret'] })
sample({ rate: 0.05, levels: [LogLevelEnum.DEBUG] })
rateLimit({ maxPerSecond: 100 })
normalizeStack({ maxFrames: 10 })

Type-Safe Events

declare module 'emit-io-core' {
  interface EventRegistry {
    'purchase': { orderId: string; total: number }
    'page-view': { path: string }
  }
}

emit.event('purchase', { orderId: 'x', total: 99 })  // typed
emit.event('unknown', {})  // TS error

Child Loggers + ALS Context

const reqLog = emit.child({ requestId: 'abc-123' })
reqLog.info('request received')  // logs include requestId

import { runWithContext } from 'emit-io-core'
await runWithContext({ traceId: 'tx-1' }, async () => {
  reqLog.info('in trace')  // merges traceId from ALS + requestId from binding
})

runWithContext uses AsyncLocalStorage on Node/edge; falls back to a no-op on environments without it.

Consent Gate

emit.setConsent({ analytics: false })   // block events/identify/screen
emit.setConsent({ analytics: true })    // re-enable after user consent
// errors: false → transport still receives the entry; providers do not

Circuit Breaker

import { circuitBreaker } from 'emit-io-core'

const safe = circuitBreaker(myProvider, {
  failureThreshold: 5,
  cooldownMs: 30_000,
  onStateChange: (state, name) => emit.warn('circuit', { state, name }),
})
new EmitIoStrategy({ providers: [safe] })

Pre-Init Buffer

const emit = new EmitIoStrategy({
  preInitBuffer: { size: 100 },
})

emit.event('app-open')   // buffered

// Later, after async config is loaded:
emit.init()              // flushes buffer → providers

Test Helpers

import { createTestEmitter } from 'emit-io-core/test'

const { emit, entries } = createTestEmitter()
emit.info('hello', { x: 1 })
// entries() returns all LogEntry objects captured so far

License

MIT