# @e18e/web-features-codemods 中文文档

规范地址：https://npmcn.com/package/%40e18e/web-features-codemods/

版本：0\.3\.0
npm 元数据更新时间：2026-07-06T14:32:10.540Z
中文译文更新时间：2026-11-13T03:09:59.909Z
软件包许可：MIT

本文由上游 README 翻译，可能存在偏差，请结合原文核对 API、命令与配置。版权与许可归原作者所有。

原始 npm 页面：https://www.npmjs.com/package/%40e18e/web-features-codemods
原文对照：https://npmcn.com/package/%40e18e/web-features-codemods/?lang=original
项目主页：https://github.com/e18e/web-features-codemods#readme
源码仓库：https://github.com/e18e/web-features-codemods

## 关键信息（来自 npm 元数据）

- 包体积（解压后）：38.9 kB，35 个文件
- 模块格式：ES Module
- TypeScript 类型：包内自带
- 运行依赖：1 个
- 首次发布：2025-11-25T13:15:44.853Z
- 最新版本发布：2026-07-06T14:32:10.254Z
- 近 30 天下载量：14090（2026-10-13 至 2026-11-11，npm 官方下载统计）
- 已发布版本数：6（近 12 个月 6 个）

## 中文简介

网络特性的代码集

## 安装

```sh
npm install @e18e/web-features-codemods
```

也可以使用：`pnpm add @e18e/web-features-codemods`、`yarn add @e18e/web-features-codemods`、`bun add @e18e/web-features-codemods`

## README

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

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

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

## 安装

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

```bash
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()` 方法。 。 .

### 基本示例

```javascript
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](https://e18e.dev/sponsors.svg)](https://e18e.dev/sponsor)

## 许可证

麻省理工学院

## 常见问题

### @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 和提交记录判断。

