@e18e/web-features-codemods

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

A collection of codemods for web features

原始使用文档
文档目录6 节
  1. Installation
  2. Available Codemods
  3. Usage
  4. Basic Example
  5. Sponsors
  6. License

@e18e/web-features-codemods

This project contains a collection of codemods for transforming code to make use of newer web features and syntax.

For example, converting from array[array.length - 1] to array.at(-1).

Installation

You can install the codemods using npm or yarn:

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

Available Codemods

CodemodDescriptionExample
arrayAtConvert array length-based indexing to at() methodarray[array.length - 1] → array.at(-1)
arrayFillOptimize array fill patternsVarious fill pattern optimizations
arrayIncludesConvert indexOf checks to includes()array.indexOf(item) !== -1 → array.includes(item)
arrayToReversedConvert copy-and-reverse patterns to toReversed()array.slice().reverse() → array.toReversed()
arrayToSortedConvert copy-and-sort patterns to toSorted()array.slice().sort() → array.toSorted()
arrayToSplicedConvert copy-and-splice patterns to toSpliced()const copy = arr.slice(); copy.splice(0, 1); → const copy = arr.toSpliced(0, 1);
exponentiationConvert Math.pow() to exponentiation operatorMath.pow(base, exp) → base ** exp
nullishCoalescingConvert null/undefined checks to nullish coalescingvalue != null ? value : default → value ?? default
objectHasOwnConvert hasOwnProperty to Object.hasOwn()obj.hasOwnProperty(prop) → Object.hasOwn(obj, prop)
postcssSignFunctionsRemove imports for postcss-sign-functions polyfillRemoves obsolete polyfill imports
spreadSyntaxConvert array/object methods to spread syntaxarray.concat(other) → [...array, ...other]
stringIncludesConvert indexOf checks to includes()string.indexOf(substr) !== -1 → string.includes(substr)
urlCanParseConvert URL validation try-catch to URL.canParse()try { new URL(url) } catch { } → URL.canParse(url)

Usage

Each codemod can be imported and used programmatically. All codemods implement the same interface with test() and apply() methods.

Basic Example

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];
}

Sponsors

e18e community sponsors

License

MIT

版本与发布记录

@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 是什么?

A collection of codemods for web features

如何安装 @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 和提交记录判断。