# star-events

> use logger.log instead of console.log and you can mute unmute (turn on or off) console.log calls

Latest version **0.0.6** (published 2025-02-24) · MIT license · 0 weekly downloads

## Install

```sh
npm install star-events
pnpm add star-events
yarn add star-events
bun add star-events
```

## Health

**Score 35/100 (D)** — status: maintenance-mode.

Positive: has types; no vulnerabilities; high quality score.

Warnings: low downloads; no esm support; pre 1.0.

Negative: stale; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.0.6 |
| Published | 2025-02-24 |
| First published | 2025-02-24 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 1 |
| Unpacked size | 38.1 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Author | Guillermo Pages |
| Maintainers | guillermo_at |
| Keywords | log |

## Links

- npm: https://www.npmjs.com/package/star-events
- Repository: https://github.com/gbili/saylo
- Homepage: https://github.com/gbili/saylo#readme
- Issues: https://github.com/gbili/saylo/issues
- npm.io page: https://npm.io/package/star-events

## Dependencies (1)

- [saylo](https://npm.io/package/saylo.md) 0.6.2

## Alternatives

- [cli-color](https://npm.io/package/cli-color.md) — 3.4M weekly downloads
- [log](https://npm.io/package/log.md) — 1.3M weekly downloads
- [logstash-client](https://npm.io/package/logstash-client.md) — 4.5K weekly downloads
- [@nocobase/plugin-logger](https://npm.io/package/@nocobase/plugin-logger.md) — 2.0K weekly downloads
- [child-process-debug](https://npm.io/package/child-process-debug.md) — 695 weekly downloads

## Recent versions

- 0.0.6 (latest) — 2025-02-24
- 0.0.5 — 2025-02-24
- 0.0.4 — 2025-02-24
- 0.0.3 — 2025-02-24
- 0.0.2 — 2025-02-24
- 0.0.1 — 2025-02-24

## README

# Star-Events

## Events Emitter Usage

```typescript
import { createEventEmitter } from './utils/createEventEmitter';

// Create an event emitter instance
const emitter = createEventEmitter();

// Subscribe to events
emitter.on('userLoggedIn', (user) => {
  console.log('User logged in:', user);
});

// Subscribe to all events using wildcard
emitter.on('*', (data) => {
  console.log('Any event occurred:', data);
});

// Emit events
emitter.emit('userLoggedIn', { id: 1, name: 'John' });

// Unsubscribe from events
const callback = (data) => console.log(data);
emitter.on('notification', callback);
emitter.off('notification', callback);

// Remove all callbacks for an event
emitter.offAll('notification');
```

## Custom Logging

```typescript
import { createLogger } from './utils/logger';
import { createEventEmitter } from './utils/createEventEmitter';

// Create a logger with custom settings
const logger = createLogger({
  LOGGER_DEBUG: true, // Enable debug logs
  LOGGER_LOG: true    // Enable warning and error logs
});

// Create an event emitter with custom logger
const emitter = createEventEmitter({ logger });

// Now all events will be logged according to your settings
emitter.emit('test', 'Hello, World!');
// [2023-07-20T10:00:00.000Z] [LOG] Emitting event "test" with params: Hello, World!
```

## Error Handling

The event emitter automatically catches and logs errors in event handlers:

```typescript
const emitter = createEventEmitter();

// This handler will throw an error
emitter.on('buggy', () => {
  throw new Error('Something went wrong!');
});

// The error will be caught and logged, other handlers will still execute
emitter.emit('buggy');
```

## Type Safety

TypeScript interfaces ensure type safety:

```typescript
interface UserEvents {
  userLoggedIn: { id: number; name: string };
  userLoggedOut: { id: number };
}

// Create a type-safe event emitter
const emitter = createEventEmitter<UserEvents>();

// TypeScript will ensure correct event names and payload types
emitter.on('userLoggedIn', (user) => {
  console.log(user.name); // TypeScript knows `name` exists
});

// This would cause a type error
emitter.emit('userLoggedIn', { id: 1 }); // Error: missing 'name' property
```

---
_Source: https://npm.io/package/star-events · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
