2.0.0 • Published 3 months ago

console.sticky v2.0.0

Weekly downloads
-
License
Apache-2.0
Repository
github
Last release
3 months ago

📌 console.sticky

Automatically and repeatedly log important console messages like self-XSS warnings.

The logger uses a timer and listens for console log calls. Once the time or call threshold is reached, the sticky messages are logged.

ℹ Usage

Install the package using NPM

npm install console.sticky

In this basic example, we call addConsoleSticky to create a sticky

import { addConsoleSticky } from 'console.sticky'

// addConsoleSticky can be called in the same manner as console.log
addConsoleSticky('Important message!')

// Including full support for message styling
addConsoleSticky('%cImportant %cmessage!', 'color:red', 'color:blue')

Stickies can be styled using Presets

import { addStyledConsoleSticky, StickyPreset } from 'console.sticky'

/* StickyPreset has two options available:
 * ImportantNotice
 * ImportantWarning
 */
addStyledConsoleSticky('Important message!', StickyPreset.ImportantNotice)

The addConsoleSticky function can be attached globally as console.sticky

import {
  addConsoleSticky,
  attachConsoleSticky,
  attachConsoleStickySync,
  AttachmentError,
  AttachmentErrorReason,
} from 'console.sticky'

// You can optionally attach it to the global scope as console.sticky
attachConsoleSticky()
  .then(() => {
    console.sticky('Important message!')
  })
  .catch((e) => {
    // Try again, this time overriding any existing console.sticky
    if (
      e instanceof AttachmentError &&
      e.reason === AttachmentErrorReason.AlreadyExists
    )
      return attachConsoleSticky(true)
  })
  .catch((e) => {
    /* Couldn't attach to global scope, even with override */
  })

// This can also be done synchronously
const attached = attachConsoleStickySync()

if (attached) {
  console.sticky('Important message!')
} else {
  /* Failed to attach */
}

You can also remove stickies later if you no longer need them

import { getAllConsoleStickies } from 'console.sticky'

// Creating a sticky returns a Symbol key that can be used to manage it
const key = addConsoleSticky('Important message!')

// You remove a sticky later
removeConsoleSticky(key)

// Or, you can remove them all with a single call
removeAllConsoleStickies()

// Returns a Map<Symbol, Function> of all active stickies
getAllConsoleStickies()

📄 License

This project has zero dependencies and is permissively licensed.

MIT License

2.0.0

3 months ago

1.2.0

9 months ago

1.3.3

9 months ago

1.3.2

9 months ago

1.3.1

9 months ago

1.3.0

9 months ago

1.1.2

1 year ago

1.1.1

1 year ago

1.1.0

2 years ago

1.0.2

2 years ago

1.0.1

2 years ago

1.0.0

2 years ago