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

glost-frequency

v0.4.0

Published

Word frequency extension for GLOST - generates and formats frequency data

Readme

glost-frequency

Word frequency extension for GLOST - generates and formats frequency data.

Overview

This package provides frequency analysis for GLOST documents. It separates frequency generation (determining word frequencies) from frequency enhancement (formatting for display).

Philosophy: No Data > Bad Data

This package intentionally does NOT include fallback/heuristic providers. Inaccurate frequency data is worse than no data, especially for language learning applications. You must provide a real frequency provider based on:

  • Corpus frequency data (e.g., Thai National Corpus, BCCWJ for Japanese)
  • Dictionary frequency rankings
  • Other validated language resources

Architecture

  • Generator: Populates frequency data using a provider (language-specific)
  • Enhancer: Formats frequency data with colors, labels, priorities (language-agnostic)
  • Provider Pattern: Pluggable frequency sources (corpus data, word lists)

Installation

pnpm add glost-frequency

Usage

With Language-Specific Provider (Required)

import { createFrequencyGeneratorExtension, createFrequencyEnhancerExtension } from "glost-frequency";
import { createThaiFrequencyProvider } from "glost-th/extensions";

// Create language-specific provider
const thaiProvider = createThaiFrequencyProvider(datasource);

// Create extensions
const generator = createFrequencyGeneratorExtension({
  targetLanguage: "th",
  provider: thaiProvider
});

const enhancer = createFrequencyEnhancerExtension({
  normalize: true
});

// Process
const result = await processGLOSTWithExtensionsAsync(doc, [generator, enhancer]);

Enhancer Only (Data Already Present)

If your documents already have frequency data, you can use just the enhancer:

import { FrequencyEnhancerExtension } from "glost-frequency";
import { processGLOSTWithExtensions } from "glost-extensions";

// Synchronous processing (no generator needed)
const result = processGLOSTWithExtensions(document, [FrequencyEnhancerExtension]);

Frequency Levels

The extension uses four standard frequency levels:

  • rare - Infrequently used words
  • uncommon - Less common words
  • common - Commonly used words
  • very-common - Very frequently used words

Provider Pattern Benefits

  1. Data Integrity: Only real corpus data, no guessing
  2. Language-Specific: Each language can have optimized providers
  3. Data Source Flexibility: Use different corpora or validated resources
  4. Composability: Mix and match providers and enhancers
  5. Testability: Mock providers for testing
  6. Graceful Degradation: Returns undefined when no data available

API

createFrequencyGeneratorExtension(options)

Creates extension that populates frequency data.

Options:

  • targetLanguage - ISO-639-1 language code
  • provider - FrequencyProvider instance
  • skipExisting - Skip words with existing frequency (default: true)

createFrequencyEnhancerExtension(options)

Creates extension that formats frequency data.

Options:

  • normalize - Normalize frequency values (default: true)
  • customMapping - Word → frequency mappings

Creating Custom Providers

Implement the FrequencyProvider interface with real corpus data:

import type { FrequencyProvider, FrequencyLevel } from "glost-frequency";

export function createMyFrequencyProvider(corpusData: Map<string, number>): FrequencyProvider {
  return {
    async getFrequency(word, language) {
      const count = corpusData.get(word);
      if (!count) return undefined; // No data? Return undefined, don't guess!
      
      // Map corpus counts to frequency levels based on your data
      if (count > 10000) return "very-common";
      if (count > 1000) return "common";
      if (count > 100) return "uncommon";
      return "rare";
    }
  };
}

createFrequencyExtension(options)

Convenience function that creates both generator and enhancer.

Returns: [generator, enhancer]

Migration from glost-extensions

Before (v0.1.x):

import { FrequencyExtension } from "glost-extensions";
processGLOSTWithExtensions(doc, [FrequencyExtension]);

After (v0.2.0+):

import { createFrequencyExtension } from "glost-frequency";
import { createThaiFrequencyProvider } from "glost-th/extensions";

// Use real corpus data provider
const provider = createThaiFrequencyProvider({
  corpusData: thaiNationalCorpusFrequencies
});

const [generator, enhancer] = createFrequencyExtension({
  targetLanguage: "th",
  provider
});

await processGLOSTWithExtensionsAsync(doc, [generator, enhancer]);

License

MIT