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 🙏

© 2025 – Pkg Stats / Ryan Hefner

deepl-translate-api

v1.1.2

Published

免费的DeepL翻译API,支持自动语言检测和多种语言互译

Readme

deepl-translate-api

免费的 DeepL 网页版翻译 API(非官方)。使用 Playwright 启动本地浏览器,自动打开 DeepL 网页完成翻译。

适用于 Node.js 环境,支持自动检测源语言,仅需指定目标语言。目标语言代码完全遵循 DeepL 官方.

安装

pnpm add deepl-translate-api
# 或
npm i deepl-translate-api
# 或
yarn add deepl-translate-api

首次运行若未安装浏览器,工具将引导安装 Playwright 的 Chromium。

快速开始

import { translate } from "deepl-translate-api";

const res = await translate("Hello world", "ZH-HANS");
console.log(res.data); // 你好,世界

API

| 方法 | 签名 | 返回 | 说明 | |---|---|---|---| | translate | translate(text, targetLang?) | Promise<TranslateResult> | 执行一次翻译,自动检测源语言,仅需指定目标语言 | | cleanup | cleanup() | Promise<void> | 关闭并释放浏览器实例与页面资源 | | findChromePath | findChromePath() | string | null | 查找系统已安装的 Chrome/Chromium 路径 | | askUserToDownloadChrome | askUserToDownloadChrome() | Promise<boolean> | 交互式询问是否自动安装 Playwright 的 Chromium | | launchWithPlaywrightChromium | launchWithPlaywrightChromium() | Promise<{ browser, page }> | 使用 Playwright 内置 Chromium 启动并返回浏览器与页面 | | getSupportedLanguages | getSupportedLanguages() | string[] | 返回 DeepL 官方目标语言代码(大写)列表 |

translate 参数:

| 参数 | 类型 | 必填 | 默认值 | 说明 | |---|---|---|---|---| | text | string | 是 | - | 需要翻译的文本,最大 5000 字符 | | targetLang | string | 否 | "ZH-HANS" | DeepL 官方目标语言代码,如 EN-USEN-GBZH-HANSZH-HANT |

支持的语言

完全使用 DeepL 官方语言代码(大写):

AR, BG, CS, DA, DE, EL, EN, EN-GB, EN-US, ES, ET, FI, FR, HE, HU, ID, IT,
JA, KO, LT, LV, NB, NL, PL, PT, PT-BR, PT-PT, RO, RU, SK, SL, SV, TH, TR,
UK, VI, ZH, ZH-HANS, ZH-HANT

中文建议:ZH-HANS(简体)、ZH-HANT(繁体)。英语建议:EN-GB(英式)、EN-US(美式)。

使用建议与限制

  • 仅限服务端/本地 Node.js 环境,不适用于浏览器端。
  • DeepL 网页版存在速率限制,频繁请求可能被限制;遇到 Too Many Requests 请降低频率或稍后再试。
  • 首次运行如未安装 Chromium,将自动执行安装;也可手动运行:npx playwright install chromium

故障排查

  • 无法找到 Chrome:将提示自动安装 Chromium,或手动安装系统 Chrome 后重试。
  • 结果为空:会自动截图到当前目录 error_screenshot_*.png 以便排查。
  • 进程未退出:调用 cleanup() 释放浏览器资源。

许可

MIT