mcpField
R
recommend

recommend

github.com/toss开发11.4k708 次安装2 天前更新
代码仓库

关于 recommend

这项技能根据需求描述或代码片段推荐 es-toolkit 函数,并通过项目已安装包的导出、声明、实现和官方文档核实依据。

主要功能

  1. 01分析操作需求与数据类型
  2. 02核实已安装版本及导出项
  3. 03检查声明与实现
  4. 04链接官方函数文档
  5. 05推荐多个函数时比较候选项

适用场景

  1. 01为具体任务查找 es-toolkit 函数
  2. 02核验项目安装版本中的函数
  3. 03确认函数行为与签名
  4. 04在多个候选函数间选择

安装

复制下面的命令,在终端中运行。

$npx skills add https://github.com/toss/es-toolkit --skill recommend

安装后在 Claude Code 中输入/recommend确认已加载。

详细介绍

函数推荐

根据源代码和官方文档,为用户的需求推荐最合适的 es-toolkit 函数。

输入

$ARGUMENTS — 对用户需求的描述,或待分析的代码片段。

为什么需要以事实为依据

es-toolkit 的发展速度远超任何训练数据所能跟上的速度。请务必根据用户项目中安装的版本,验证函数是否存在、入口点及其行为。此技能可能以独立目录的形式安装,因此切勿假设 es-toolkit 仓库或同级 docs 目录可用。

工作流程

1. 理解需求

解析 $ARGUMENTS,确定:

  • 用户想执行什么操作
  • 涉及哪些数据类型(数组、对象、字符串等)
  • 用户是否可能需要 lodash 迁移帮助(如果需要,建议使用 /es-toolkit:migrate)
2. 在已安装的包中查找候选函数

从依赖 es-toolkit 的包中运行命令。在 monorepo 中,这通常是某个工作区包,而非仓库根目录。如果项目使用 Yarn Plug'n'Play,请使用 yarn node,而不是 node。

运行以下命令搜索运行时入口点,并将 merge|assign 替换为与需求相关的词语:

node --input-type=module -e "
import { createRequire } from 'node:module';

const require = createRequire(import.meta.url);
const pattern = /merge|assign/i;
const pkg = require('es-toolkit/package.json');
const entries = Object.keys(pkg.exports)
  .filter(subpath => subpath !== './package.json' && !subpath.includes('*'))
  .map(subpath => subpath === '.' ? 'es-toolkit' : 'es-toolkit/' + subpath.slice(2));
const modules = await Promise.all(entries.map(entry => import(entry).catch(() => null)));
if (modules.every(module => module == null)) {
  console.error('es-toolkit is not resolvable from ' + process.cwd());
  process.exit(1);
}
const matches = new Map();
for (let index = 0; index < modules.length; index++) {
  const module = modules[index];
  if (module == null) continue;
  for (const name of Object.keys(module)) {
    if (!pattern.test(name)) continue;
    matches.set(name, [...(matches.get(name) ?? []), entries[index]]);
  }
}
for (const [name, entryPoints] of [...matches].sort()) {
  console.log(name.padEnd(24), entryPoints.join(', '));
}
"

输出是已安装版本的权威依据。一个函数可能存在于多个入口点,因此请考虑所有匹配结果。es-toolkit/types 仅包含类型,无法在运行时导入;请改为检查其声明文件。

如果无法解析 es-toolkit,请说明无法验证已安装的版本。不要臆造函数名称。

如果当前项目本身就是 es-toolkit 源代码仓库,请直接搜索 src/ 及其测试规范,而不是要求使用已构建的包。

3. 阅读真实的声明

解析已安装包的元数据:

node -e "console.log(require.resolve('es-toolkit/package.json'))"

阅读包的 dist/ 目录下对应的声明,确认准确的签名、JSDoc 和示例。不要假定路径遵循常见的 node_modules 布局;请使用解析出的路径。如果实现可用,也请检查实现,尤其是变更和错误行为。

4. 构造官方文档 URL

es-toolkit 的文档 URL 遵循固定模式——请直接构造,而不是通过抓取获取:

  • strict:https://es-toolkit.dev/reference/{category}/{functionName}.html
  • compat:https://es-toolkit.dev/compat/reference/{category}/{functionName}.html
  • fp:https://es-toolkit.dev/fp/reference/{functionName}.html

如果不确定页面是否存在,请省略页面链接,不要猜测。

5. 按以下结构作答

对于每个推荐的函数,请提供:

  • 函数名称和类别
  • 导入路径:import { fn } from 'es-toolkit';
  • 文档链接:https://es-toolkit.dev/reference/{category}/{fn}
  • 函数的作用(根据源代码中的 JSDoc)
  • 代码示例(来自测试规范文件或官方文档)
  • 它为何适合用户的需求

推荐多个函数时,始终包含对比表:

函数输入类型行为性能返回类型
(每个候选函数)............

添加一个 “如何选择” 部分,并给出清晰的判断标准,例如:“使用 groupBy 进行分类,使用 countBy 统计数量,使用 keyBy 创建查找映射。”

如果没有合适的匹配项,请明确说明,并建议使用现代 JavaScript 替代方案。对于 lodash 兼容替代方案,请引导用户使用 /es-toolkit:migrate 技能。

评论

支持 Markdown