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

spur-monocle-manager

v3.1.1

Published

Wrapper for the Monocle SDK (Spur)

Readme

spur-monocle-manager

Note: This is not an official package. For the official Monocle documentation, please visit: https://docs.spur.us/monocle

CI Release npm version License: MIT

spur-monocle-manager is a lightweight TypeScript wrapper for loading and interacting with Spur's Monocle SDK.

Key Features of this SDK:

  • Flexible loading: Allows you to manually call init() at any point (e.g., page load) or automatically inject the script on-demand when you call getAssessment() (e.g., form submission).
  • Emits lifecycle events: Provides hooks (load, assessment, error) for each stage of loading and fetching.

Table of Contents

Installation

npm install spur-monocle-manager

Quick Start

import Monocle from 'spur-monocle-manager'

async function main() {
  const monocle = new Monocle({ token: 'YOUR_TOKEN_HERE' })

  try {
    await monocle.init()
  } catch (err) {
    console.error('Unable to initialize Monocle (SSR or already loaded):', err)
  }

  // Listen for events
  monocle.on('assessment', (data) => {
    console.log('Assessment data:', data)
  })

  // Retrieve the assessment and trigger the 'assessment' event
  const assessment = await monocle.getAssessment()
  console.log(assessment)

  const assessment2 = await monocle.getAssessment() // you can call it again to get fresh assessment

  // Clean up when done (optional)
  // monocle.destroy()
}

main().catch(console.error)

API

new Monocle(options)

Creates a new Monocle loader instance.

  • options.token: string — Required Monocle authentication token.
  • options.initTimeout: number — Optional timeout in milliseconds for the script to load (default: 5000 ms).
  • options.debug: boolean — Optional flag to enable debug logging (default: false).
  • Throws if no token is provided.

init(): Promise<void>

Injects the Monocle script into the page and initializes global callbacks.

  • Calling init() multiple times is safe: it returns the same promise and logs a warning.

getAssessment(): Promise<string>

Refreshes Monocle data and returns a signed JWT assessment as a string.

  • Automatically calls init() if not already initialized.
  • Triggers a 'assessment' event with the assessment content on success.
  • Triggers a 'error' event on failure (e.g., if no assessment is returned).
  • Throws if called in server-side context or if the assessment is unavailable.

on(event: MonocleEvents, handler: (detail: any) => void): void

Subscribes to Monocle-specific events.

  • event: One of 'assessment', 'error', 'load'.
  • handler: Function that receives the event detail as its only parameter.

off(event: MonocleEvents, handler: (detail: any) => void): void

Unsubscribes a previously registered event listener.

  • Requires the exact same function reference used in .on().

destroy(): void

Cleans up the injected script, global callbacks, and internal state.

  • Can be re-initialized later with another call to init().

Monocle Events

The Monocle class dispatches events through an internal EventTarget. You can subscribe to these using .on() and .off():

| Event Name | Description | | ----------------- | --------------------------------------------------------------------------- | | assessment | Emitted when the Monocle assessment is successfully retrieved. Payload: string. | | error | Emitted when there is an error loading or fetching the assessment. | | load | Emitted once the Monocle script has been successfully loaded. |

Tests & CI

  • Unit tests & coverage via Vitest
  • Linting & type-checking using ESLint + TypeScript
  • Automated releases via GitHub Actions + Semantic Release
# Install dependencies
npm ci

# Run everything
npm run build        # Compile
npm run lint         # Lint
npm run type-check   # Type checking
npm run test:ci      # Tests + coverage

# Manual publishing (usually handled via GitHub Actions)
npm run release

Contributing

See CONTRIBUTING.md for contribution guidelines, bug reports, and feature requests.

License

This project is licensed under the MIT license. See LICENSE for more details.