@e18e/web-features-codemods

中文文档
0.3.0发布于 2026/07/06MITTypeScriptES Module构建来源已验证近 30 天下载 1.4万

网络特性的代码集

中文使用文档
文档目录6 节
  1. 安装
  2. 可用的代码
  3. 使用量
  4. 基本示例
  5. 发起人
  6. 许可证

@e18e/web-features-codemods (英语)

这个项目包含了一套用于转换代码的代码集以使用更新的网页特性和语法.

例如,从 array[array.length - 1] 改为 array.at(-1)。 。 。 .

安装

您可以使用 npm 或 纱线安装代码 :

npm install @e18e/web-features-codemods --save-dev

可用的代码

代码说明示例
arrayAt将基于长的数组索引转换为 at() 方法array[array.length - 1] → array.at(-1)
arrayFill优化数组填充模式各种填充模式优化
arrayIncludes转换 indexOf 检查到 includes()array.indexOf(item) !== -1 → array.includes(item)
arrayToReversed将复制和反向模式转换为 toReversed()array.slice().reverse() → array.toReversed()
arrayToSorted将复制和类型模式转换为 toSorted()array.slice().sort() → array.toSorted()
arrayToSpliced将复制和切换模式转换为 toSpliced()const copy = arr.slice(); copy.splice(0, 1); → const copy = arr.toSpliced(0, 1);
exponentiation转换 Math.pow() 以表示责任运算符Math.pow(base, exp) → base ** exp
nullishCoalescing将无效/ 未定义的检查转换为无效连接value != null ? value : default → value ?? default
objectHasOwn转换 hasOwnProperty 改为 Object.hasOwn()obj.hasOwnProperty(prop) → Object.hasOwn(obj, prop)
postcssSignFunctions删除导入 postcss-sign-functions 多边填充取消过时的多填充进口
spreadSyntax转换数组/对象方法以传播语法array.concat(other) → [...array, ...other]
stringIncludes转换 indexOf 检查到 includes()string.indexOf(substr) !== -1 → string.includes(substr)
urlCanParse将 URL 验证尝试捕获到 URL.canParse()try { new URL(url) } catch { } → URL.canParse(url)

使用量

每个编码器都可以在程序上被导入和使用. 所有代码模块执行相同的接口 test() 财务报告和审定财务报表 apply() 方法。 。 .

基本示例

import {arrayAt} from '@e18e/web-features-codemods';

const sourceCode = `
const lastItem = myArray[myArray.length - 1];
const firstItem = myArray[0];
`;

// Optionally check if the codemod applies to this source.
// You can also skip this step and directly call apply() as non-matching
// codemods will simply return the original source.
if (arrayAt.test({source: sourceCode})) {
  // Apply the transformation
  const transformed = arrayAt.apply({source: sourceCode});
  console.log(transformed);
  // Output:
  // const lastItem = myArray.at(-1);
  // const firstItem = myArray[0];
}

发起人

e18e community sponsors

许可证

麻省理工学院

版本与发布记录

@e18e/web-features-codemods 共发布 6 个版本,首次发布于 2025/11/25;过去 12 个月发布了 6 个版本。最新版本附带 npm provenance 构建来源证明,可追溯到公开的 CI 构建记录。

版本发布日期距今
0.3.0latest2026/07/064 个月前
0.2.22026/06/154 个月前
0.2.12026/06/085 个月前
0.2.02025/12/0111 个月前
0.1.02025/11/3011 个月前
0.0.12025/11/2511 个月前

关于 @e18e/web-features-codemods 的常见问题

@e18e/web-features-codemods 是什么?

网络特性的代码集

如何安装 @e18e/web-features-codemods?

在项目目录运行 npm install @e18e/web-features-codemods,或使用 pnpm add / yarn add / bun add。

@e18e/web-features-codemods 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

@e18e/web-features-codemods 支持 ESM 还是 CommonJS?

以 ES Module 形式发布,推荐使用 import 引入。在 CommonJS 项目中,Node.js 20.19+ / 22.12+ 可以直接 require() 不含顶层 await 的 ES Module,更早的版本需要改用动态 import()。

@e18e/web-features-codemods 可以商用吗?

@e18e/web-features-codemods 使用 MIT 许可。宽松许可:允许商业使用、修改和再分发,通常只需在分发时保留原版权与许可声明。以上为概括,不构成法律意见,请以许可原文为准。

@e18e/web-features-codemods 的下载量有多少?

根据 npm 官方下载统计,@e18e/web-features-codemods 在 2026/10/13 – 2026/11/11 这 30 天内被下载 14,090 次,日均约 470 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@e18e/web-features-codemods 还在维护吗?

最新版本 0.3.0 发布于 2026/07/06(4 个月前);至今共发布 6 个版本,其中过去 12 个月发布了 6 个;首次发布于 2025/11/25。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。