recommend
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseFunction Recommendation
函数推荐
Recommend the most suitable es-toolkit function for the user's needs, grounded in source code and official documentation.
根据用户需求推荐最合适的es-toolkit函数,推荐依据为源代码和官方文档。
Input
输入
$ARGUMENTS — A description of what the user needs, or a code snippet to analyze.
$ARGUMENTS — 用户需求描述或待分析的代码片段。
Why grounding matters
为什么依据重要
es-toolkit evolves faster than any training data can track. Always verify function existence and behavior from the actual source code in this repository, rather than relying on memorized knowledge. This prevents recommending functions that don't exist or have changed signatures.
es-toolkit的更新速度快于任何训练数据的跟踪速度。请始终通过本仓库中的实际源代码验证函数的存在和行为,而非依赖记忆中的知识。这可以避免推荐不存在或签名已变更的函数。
Workflow
工作流程
1. Understand the requirement
1. 理解需求
Parse $ARGUMENTS to identify:
- What operation the user wants to perform
- What data types are involved (array, object, string, etc.)
- Whether they might need lodash migration help (if so, suggest )
/es-toolkit:migrate
解析$ARGUMENTS以确定:
- 用户想要执行的操作
- 涉及的数据类型(数组、对象、字符串等)
- 是否可能需要lodash迁移帮助(如果是,建议使用)
/es-toolkit:migrate
2. Search the local source code first
2. 优先搜索本地源代码
This is the fastest and most accurate way to find functions. Search across es-toolkit's categories:
undefined这是查找函数最快、最准确的方式。在es-toolkit的各个分类中进行搜索:
undefinedSearch in src/ for matching function names or descriptions
在src/目录下搜索匹配的函数名称或描述
Grep for keywords in src/{category}/*.ts
List subdirectories under `src/` (excluding `_internal` and `compat`) to discover the current categories dynamically. You can also browse `docs/reference/` to discover the full function index — each subdirectory is a category, and each `.md` file is a function.
Read the implementation file to get the exact signature, and the spec file for real usage examples.Grep for keywords in src/{category}/*.ts
动态查看`src/`下的子目录(排除`_internal`和`compat`)以了解当前的分类。你也可以浏览`docs/reference/`来查看完整的函数索引——每个子目录对应一个分类,每个`.md`文件对应一个函数。
阅读实现文件以获取确切的签名,查看测试文件以获取实际使用示例。3. Construct the official doc URL
3. 构建官方文档URL
es-toolkit's documentation URLs follow a predictable pattern — construct them directly instead of fetching:
https://es-toolkit.dev/reference/{category}/{functionName}
es-toolkit的文档URL遵循可预测的模式——直接构建即可,无需获取:
https://es-toolkit.dev/reference/{category}/{functionName}
4. Search local docs when you're unsure
4. 不确定时搜索本地文档
If you can't find a matching function locally or want to discover functions you might be missing:
- Browse by category: to list all functions in a category
Glob docs/reference/{category}/*.md - Search by keyword: for the keyword across
Grepdocs/reference/**/*.md - Available categories: array, error, function, map, math, object, predicate, promise, set, string, util
如果在本地找不到匹配的函数,或想要发现可能遗漏的函数:
- 按分类浏览:使用列出某一分类下的所有函数
Glob docs/reference/{category}/*.md - 按关键词搜索:使用在
Grep中搜索关键词docs/reference/**/*.md - 可用分类:array、error、function、map、math、object、predicate、promise、set、string、util
5. Respond with this structure
5. 按以下结构回复
For each recommended function, include:
- Function name and category
- Import path:
import { fn } from 'es-toolkit'; - Doc link:
https://es-toolkit.dev/reference/{category}/{fn} - What it does (from JSDoc in source)
- A code example (from spec file or official docs)
- Why it fits the user's need
When recommending multiple functions, always include a comparison table:
| Function | Input type | Behavior | Performance | Return type |
|---|---|---|---|---|
| (each candidate) | ... | ... | ... | ... |
Add a "When to choose which" section with clear decision criteria — e.g., "Use for categorizing, for tallying, for lookup maps."
groupBycountBykeyByIf no match exists, say so clearly and suggest modern JS alternatives. For lodash-compatible replacements, point users to the skill.
/es-toolkit:migrate对于每个推荐的函数,需包含:
- 函数名称和分类
- 导入路径:
import { fn } from 'es-toolkit'; - 文档链接:
https://es-toolkit.dev/reference/{category}/{fn} - 功能说明(来自源代码中的JSDoc)
- 代码示例(来自测试文件或官方文档)
- 适配用户需求的原因
当推荐多个函数时,务必包含对比表格:
| 函数名称 | 输入类型 | 行为 | 性能 | 返回类型 |
|---|---|---|---|---|
| (每个候选函数) | ... | ... | ... | ... |
添加**“如何选择”**部分,明确决策标准——例如:“使用进行分类,进行计数,创建查找映射。”
groupBycountBykeyBy如果没有匹配的函数,请明确告知用户并推荐现代JavaScript替代方案。对于lodash兼容的替代方案,请引导用户使用技能。
/es-toolkit:migrate