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

@happyvertical/translator

v0.80.2

Published

Standardized translation interface supporting Google Translate, DeepL, and LibreTranslate

Readme

@happyvertical/translator

Standardized translation interface supporting Google Translate, DeepL, and LibreTranslate. Uses a factory/adapter pattern with a unified Translator interface across all providers. Google and DeepL providers include automatic in-memory caching via @happyvertical/cache.

Installation

pnpm add @happyvertical/translator

Quick Start

Environment Variables

export HAVE_TRANSLATOR_PROVIDER=deepl
export DEEPL_API_KEY=your_key
import { getTranslator } from '@happyvertical/translator';

const translator = await getTranslator();
const result = await translator.translate('Hello, world!', 'es');
console.log(result.translatedText); // "¡Hola, mundo!"

Explicit Options

// Google Translate
const translator = await getTranslator({
  provider: 'google',
  apiKey: process.env.GOOGLE_TRANSLATE_API_KEY!,
});

// DeepL
const translator = await getTranslator({
  provider: 'deepl',
  apiKey: process.env.DEEPL_API_KEY!,
  freeApi: true,
});

// LibreTranslate (no API key required for public instances)
const translator = await getTranslator({
  provider: 'libretranslate',
  apiUrl: 'https://libretranslate.com',
});

Template Function

Create pre-configured translation functions for repeated use:

const t = translator.templateFunction('en', 'es');

const greeting = await t('Hello, world!'); // "¡Hola, mundo!"
const farewell = await t('Goodbye!');       // "¡Adiós!"

API

getTranslator(options?): Promise<Translator>

Factory function. Reads HAVE_TRANSLATOR_* environment variables, merged with explicit options (explicit wins).

Translator Interface

interface Translator {
  translate(text: string, targetLang: string, sourceLang?: string): Promise<TranslationResult>;
  detectLanguage(text: string): Promise<LanguageDetectionResult>;
  getSupportedLanguages(): Promise<SupportedLanguage[]>;
  translateBatch(texts: string[], targetLang: string, sourceLang?: string): Promise<TranslationResult[]>;
  templateFunction(sourceLang?: string, targetLang?: string): (text: string) => Promise<string>;
}

TranslationResult

interface TranslationResult {
  translatedText: string;
  sourceText: string;
  sourceLanguage: string;
  targetLanguage: string;
  confidence?: number;
  alternatives?: string[];
  detectedSourceLanguage: boolean;
  raw: any;
}

LanguageDetectionResult

interface LanguageDetectionResult {
  language: string;
  confidence: number;
  alternatives?: Array<{ language: string; confidence: number }>;
  raw: any;
}

Error Classes

All extend TranslationError:

  • TranslationError — base error with code and provider fields
  • UnsupportedLanguageError — invalid language code
  • QuotaExceededError — provider quota limit hit
  • AuthenticationError — bad or missing API key
  • InvalidTextError — empty or invalid input text

Environment Variables

| Variable | Description | |----------|-------------| | HAVE_TRANSLATOR_PROVIDER | google, deepl, or libretranslate | | HAVE_TRANSLATOR_TIMEOUT | Request timeout in ms | | HAVE_TRANSLATOR_MAX_RETRIES | Max retry attempts | | HAVE_TRANSLATOR_API_URL | LibreTranslate instance URL | | HAVE_TRANSLATOR_FREE_API | DeepL free tier (true/false) | | HAVE_TRANSLATOR_PROJECT_ID | Google Cloud project ID | | GOOGLE_TRANSLATE_API_KEY | Google Translate API key | | DEEPL_API_KEY | DeepL API key |

Utility Exports

  • LANGUAGE_NAMES — map of ISO 639-1 codes to English names
  • isValidLanguageCode(code) — validates 2-letter language codes
  • getLanguageName(code) — looks up language name from code
  • normalizeConfidence(score) — normalizes scores to 0–1 range
  • isValidText(text) — checks text is non-empty
  • truncateText(text, maxLength) — truncates with ellipsis

License

ISC