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

tiny_dict

v0.1.2

Published

A tiny english dictionary

Readme

tiny_dict

一个轻量级的英语词典查询工具,基于高效的字典树(Trie)数据结构实现。该项目旨在提供快速、精准的英语单词查询服务,支持单词的中文释义、英美音标、发音音频URL等功能。通过字典树的实现,确保了查询性能的优化,特别适合需要频繁查询操作的场景。

特性

  • 基于Trie字典树的高效查询
  • 支持英语单词的中文释义
  • 提供英美音标和发音音频URL
  • 轻量级,易于集成
  • 支持离线使用
  • 支持字典树压缩,优化存储空间
  • 支持句子分词和单词查找

安装

通过 NPM 安装

npm install tiny_dict

通过 CDN 引入

<script src="https://i.gsxcdn.com/ai-english/static/tiny_dict/dist/tiny_dict.min.js"></script>

使用方法

1. 创建字典实例

const Trie = require('tiny_dict');

// 创建字典实例
const dict = new Trie();

2. 加载字典数据

// 方式1:从URL加载
await dict.loadFromURL('https://i.gsxcdn.com/ai-english/static/tiny_dict/data/word_tree_data.json');

// 方式2:从本地文件加载
await dict.loadFile('./data/word_tree_data.json');

// 方式3:直接加载JSON数据
dict.load(jsonData);

3. 基本操作

// 搜索单词
const result = dict.search('hello');
console.log(result); // 返回单词信息或0(不存在)

// 插入单词
dict.insert('newword');

// 删除单词
dict.delete('newword');

// 分析句子中的单词
const text = "I need to book a flight to Paris.";
const { tokens, words } = dict.split(text);
console.log(tokens); // 分词结果
console.log(words);  // 识别出的单词集合

4. 高级功能

// 获取所有单词列表
const allWords = dict.getAllWords();

// 按搜索频率获取单词
const frequentWords = dict.getWordsByFrequency(10); // 获取前10个高频词

// 获取特定前缀的单词
const prefixWords = dict.getWordsByPrefix('pre');

// 压缩字典树以节省空间
const compactedDict = dict.compact();

// 解压字典树
const unpackedDict = compactedDict.unpack();

API文档

核心方法

search(word: string): number

查询单词是否存在

  • 参数:word - 要查询的英文单词
  • 返回值:存在返回1,不存在返回0

insert(word: string): boolean

插入新单词

  • 参数:word - 要插入的单词
  • 返回值:插入成功返回true,单词已存在返回false

delete(word: string): boolean

删除单词

  • 参数:word - 要删除的单词
  • 返回值:删除成功返回true,单词不存在返回false

split(text: string): { tokens: string[], words: Set }

分析文本中的单词

  • 参数:text - 要分析的文本
  • 返回值:包含分词结果和识别出的单词集合

数据加载

loadFromURL(url: string, retries?: number): Promise

从URL加载字典数据

loadFile(file: string): Promise

从本地文件加载字典数据

load(json: object): void

直接加载JSON格式的字典数据

压缩相关

compact(): Trie

压缩字典树,返回新的压缩后的字典树实例

unpack(): Trie

解压字典树,返回新的解压后的字典树实例

开源协议

ISC