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

summary-words

v0.1.1

Published

Summarize repeated words and phrases in text.

Readme

summary-words

统计文本中重复出现的词语和短语。支持中英文混合文本,自动识别 URL、数字、标点符号等,并过滤被更长短语包含的重复结果。

安装

npm install summary-words

快速开始

const { summary } = require('summary-words');

const result = summary({ content: '你好你好' });
// { words: [{ word: '你好', count: 2 }] }
const result = summary({
  content: 'abc def abc def abc def',
  min: 2,
  max: 3,
});
// {
//   words: [
//     { word: 'abc def', count: 3 },
//     { word: 'abc def abc', count: 2 },
//     { word: 'def abc def', count: 2 },
//   ],
// }

API

summary(options)

返回一个 SummaryResult 对象,包含按出现次数降序(次数相同时按首次出现位置)排列的重复短语列表。

interface SummaryOptions {
  /** 待分析的文本内容(必填) */
  content: string;
  /** 短语包含的最小"最小词"数量,默认为 2 */
  min?: number;
  /** 短语包含的最大"最小词"数量,默认为 10 */
  max?: number;
  /** 是否忽略非标点符号(标点始终作为短语边界),默认为 true */
  ignoreSymbols?: boolean;
  /** 短语被返回所需的最小出现次数,默认为 2 */
  minCount?: number;
}

interface SummaryWord {
  word: string;
  count: number;
}

interface SummaryResult {
  words: SummaryWord[];
}

参数说明

  • content:要分析的文本。
  • min / max:短语由连续若干个"最小词"组成(英文字母序列、数字各算一个最小词;中文等文字每个字符算一个最小词),minmax 限定短语长度的范围。min 不能大于 max,两者都必须是正整数。
  • ignoreSymbols:为 true 时忽略 emoji 等非标点符号;标点符号无论如何都会结束当前短语。
  • minCount:只有出现次数达到该值的短语才会被返回。

处理规则

  • 空格只作为分隔符,不计入最小词数量。
  • 标点符号和换行、制表等控制字符是短语边界,短语不会跨越它们。
  • 完整的 URL(http://https://www. 开头)会被整体跳过,不参与统计。
  • 如果一个较短短语被另一个出现次数不少于它的更长短语包含,较短短语会被过滤掉,只保留更有信息量的长短语。

示例

// 中文
summary({ content: '你好你好' });
// { words: [{ word: '你好', count: 2 }] }

// 英文(空格不计入词数)
summary({ content: 'a b a b', min: 2, max: 2 });
// { words: [{ word: 'a b', count: 2 }] }

// 包含小数与英文
summary({ content: 'abc12.5abc12.5', min: 2, max: 2 });
// { words: [{ word: 'abc 12.5', count: 2 }] }

// URL 被跳过,不参与统计
summary({ content: '见 https://example.com 和 https://example.com', min: 1, minCount: 1 });
// { words: [{ word: '见', count: 1 }, { word: '和', count: 1 }] }

开发

npm run build   # 编译 TypeScript 到 dist/
npm test        # 运行 jest 测试

License

MIT