Socket
Book a DemoInstallSign in
Socket

@e18e/web-features-codemods

Package Overview
Dependencies
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@e18e/web-features-codemods

A collection of codemods for web features

latest
Source
npmnpm
Version
0.2.0
Version published
Weekly downloads
5
-16.67%
Maintainers
1
Weekly downloads
 
Created
Source

@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) !== -1array.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 : defaultvalue ?? 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) !== -1string.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];
}

License

MIT

FAQs

Package last updated on 30 Nov 2025

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts