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

ai-text-summariser

v1.0.14

Published

Wrapper around the Summarizer API — streaming & non-streaming summaries (headline, key-points, teaser, tldr).

Readme

ai-text-summariser

ai-text-summariser is a JavaScript wrapper for the browser's Summarizer API, providing streaming and non-streaming AI-powered text summarization in a consistent, developer-friendly way.

Supports:

  • Types: headline, key-points, teaser, tldr
  • Formats: plain-text, markdown
  • Lengths: short, medium, long
  • Streaming and non-streaming modes
  • Automatic availability check
  • Chrome v138+ compatibility check
  • Custom progress monitoring and AbortController support

Installation

npm install ai-text-summariser

Requirements

  • Browser: Chrome v138 or newer (due to dependency on the built-in Summarizer API introduced in Chrome 138)

  • JavaScript environment: Browser context (Node is supported only for testing availability and config validation; summarization will not work in Node without a polyfill).

  • Experimental AI APIs enabled (in Chrome flags, depending on your build):

    • chrome://flags/#enable-ai-features
    • chrome://flags/#summarizer-api

Importing

import Summariser from 'ai-text-summariser';
// or
const Summariser = require('ai-text-summariser').default;

Configuration

The constructor accepts a config object:

{
  type?: 'headline' | 'key-points' | 'teaser' | 'tldr'; // default: 'headline'
  format?: 'plain-text' | 'markdown';                   // default: 'plain-text'
  length?: 'short' | 'medium' | 'long';                  // default: 'medium'
  expectedInputLanguages?: string[];                     // default: ['en']
  expectedContextLanguages?: string[];                   // default: ['en']
  outputLanguage?: string;                               // default: 'en'
  streaming?: boolean;                                   // default: false
  sharedContext?: string | null;                         // default: null
  monitor?: (monitorObj: any) => void;                   // optional
  signal?: AbortSignal;                                  // optional
}

Defaults

If you omit a property, the default will be applied automatically.

API Reference

Class: Summariser

constructor(config?: SummariserConfig)

Create a new summariser instance with optional config.

async checkAvailability(): Promise<boolean>

Checks:

  • Chrome version (throws error if <138)
  • Summarizer API availability for given config

async summarise(text: string, context?: string): Promise<string>

Performs non-streaming summarisation and returns the full result as a string.

async *summariseStream(text: string, context?: string): AsyncIterable<string>

Performs streaming summarisation, yielding chunks as they arrive.

Example Usage

1. Non-streaming headline

import Summariser from 'ai-text-summariser';

(async () => {
  const summariser = new Summariser({
    type: 'headline',
    format: 'plain-text',
    length: 'short'
  });

  if (!(await summariser.checkAvailability())) {
    console.error('Summarizer not available in this browser.');
    return;
  }

  const result = await summariser.summarise(
    'Your long article text goes here...',
    'Story'
  );
  
  console.log('Summary:', result);
})();

2. Streaming key-points

import Summariser from 'ai-text-summariser';

(async () => {
  const summariser = new Summariser({
    type: 'key-points',
    format: 'markdown',
    length: 'long',
    streaming: true,
    monitor(m) {
      m.addEventListener('downloadprogress', (e) => {
        console.log(`Downloaded ${(e.loaded * 100).toFixed(2)}%`);
      });
    }
  });

  if (!(await summariser.checkAvailability())) {
    console.error('Summarizer not available.');
    return;
  }

  let output = '';
  for await (const chunk of summariser.summariseStream(
    'Your long text here...',
    'Article'
  )) {
    output += chunk;
    process.stdout.write(chunk); // live output
  }

  console.log('\nFinal summary:', output);
})();

3. Aborting a request

const abortController = new AbortController();

const summariser = new Summariser({
  type: 'tldr',
  streaming: false,
  signal: abortController.signal
});

setTimeout(() => abortController.abort(), 2000); // cancel after 2s

Availability Check

Before calling summarise or summariseStream, always do:

if (!(await summariser.checkAvailability())) {
  console.error('Summarizer not available for this config.');
  return;
}

If the API is not available, you can:

  • Show a fallback UI
  • Use a server-based summarisation API
  • Ask user to upgrade Chrome to v138+

Error Handling

ai-text-summariser throws descriptive errors for:

  • Invalid config: Unsupported type, format, length
  • Browser compatibility: Chrome version < 138
  • API unavailability: Summarizer API not exposed
  • Summarisation failures: Errors from Summarizer.create() or during summarization

Example:

try {
  const result = await summariser.summarise(text);
} catch (err) {
  console.error('Summarisation failed:', err.message);
}

Chrome v138+ Requirement

ai-text-summariser will not work in:

  • Older versions of Chrome (<138)
  • Non-Chromium browsers (unless they implement Summarizer API)
  • Headless Chrome without AI APIs enabled

To check your Chrome version:

  1. Go to chrome://version/
  2. Ensure "Google Chrome" shows 138.x.x.x or newer.

Further Notes

  • For developers: This package assumes a modern JS environment and does not polyfill the Summarizer API.
  • For Node.js: You can import and use checkAvailability() and config validation, but summarisation methods require a browser.