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

@simon_he/translate

v0.0.13

Published

A fast, robust, and lightweight translation library supporting 5 translation services (Google, Bing, DeepL, MyMemory, Lingva) with automatic fallback, batch processing, caching, and full TypeScript support.

Readme

@simon_he/translate

🚀 A fast, robust, and lightweight translation library supporting 6 translation services with automatic fallback, batch processing, intelligent caching, and full TypeScript support.

✨ Features

  • 🌐 Multiple Translation Providers: Google, Bing, DeepL, MyMemory, Lingva
  • 🔄 Automatic Fallback: If one service fails, automatically tries others
  • Batch Processing: Translate multiple texts concurrently
  • 🧠 Smart Caching: LRU cache to avoid repeated API calls
  • 🎯 Promise.any Racing: Uses the fastest available service
  • 📦 Zero Dependencies: Lightweight and fast
  • 🔒 TypeScript Support: Full type safety
  • 🆓 Free Options: Includes free translation services

🌍 Supported Translation Services

| Service | Type | Status | Free Tier | API Key Required | |---------|------|--------|-----------|------------------| | MyMemory | Free | ✅ Working | 1000 requests/day | No | | Bing Translator | Commercial | ✅ Working | 2M chars/month | No* | | Google Translate | Commercial | ⚠️ Limited | 500K chars/month | No* | | DeepL | Commercial | ⚠️ Rate Limited | 500K chars/month | No* | | Lingva | Free Proxy | ⚠️ Blocked | Unlimited | No |

* These services use unofficial APIs and may have limitations or availability issues

✅ Recommended for Production: MyMemory, Bing ⚠️ Use with Caution: Google (timeouts), DeepL (rate limits), Lingva (blocked)

📦 Installation

npm install @simon_he/translate
# or
pnpm add @simon_he/translate
# or
yarn add @simon_he/translate

🚀 Quick Start

import translateLoader from '@simon_he/translate'

const translate = translateLoader()

// Translate single text
const result = await translate('Hello world', 'zh')
console.log(result) // ['世界您好']

// Translate multiple texts (batch processing)
const results = await translate(['Hello', 'Good morning'], 'zh')
console.log(results) // ['你好', '早上好']

// English to Chinese (default)
const zhResult = await translate('Hello')
console.log(zhResult) // ['你好']

// Chinese to English
const enResult = await translate('你好', 'en')
console.log(enResult) // ['Hello']

🔧 Advanced Usage

Individual Service Usage

import {
  bingTranslate,
  googleTranslate,
  lingvaTranslate,
  mymemoryTranslate
} from '@simon_he/translate'

// Use specific service
const google = googleTranslate()
const result = await google('Hello', 'zh')
console.log(result.text) // '你好'

Custom Cache Configuration

import translateLoader from '@simon_he/translate'

// Create translator with custom cache size
const translate = translateLoader(createLimitedCache(500))

🎯 API Reference

translateLoader(cacheMap?)

Creates a translation function with automatic service fallback.

Parameters:

  • cacheMap (optional): Custom cache implementation

Returns: (texts: string | string[], to?: 'en' | 'zh') => Promise<string[]>

Individual Services

Each service exports a fanyi() function:

type TranslateFunction = (text: string, to?: string, from?: string) => Promise<{ text: string }>

🧪 Testing

# Run main tests
npm test

# Run performance tests
npm run test:performance

# Run stress tests
npm run test:stress

# Run benchmark tests
npm run test:benchmark

# Run all tests
npm run test:all

License

MIT License © 2022 Simon He

sponsors