Remove Iswhitespace

1.0.2Last update Jul 17, 2024
by@alexbit-codemod

Removes isWhitespace calls and is-whitespace imports and replaces them with trim() calls.

is-whitespace is a small utility that checks if a string contains only whitespace characters. It's not a very performant way to check for whitespace, especially when used in a loop.

Before

//this could be any shape of import statement for is-whitespace
const isWhitespace = require('is-whitespace');
let str = ' ';
let str2 = 'Hello';
console.log(isWhitespace(str1)); // true
console.log(isWhitespace(str2)); // false

After

//remove the import statement related to is-whitespace. and replace isWhitespace with its equivalent implementation as shown below.
let str = ' ';
let str2 = 'Hello';
console.log(str1.trim() === ''); // true
console.log(str2.trim() === ''); // false

Build custom codemods

Use AI-powered codemod studio and automate undifferentiated tasks for yourself, colleagues or the community

background illustrationGet Started Now