removeLetters
A function that removes characters from a given string according to the specified options.
By default, it removes letters only. The following options can be configured:
letters: Specifies whether to remove letters from the string.numbers: Specifies whether to remove numbers from the string.specialCharacters: Specifies whether to remove special characters from the string.whiteSpace: Specifies whether to remove whitespace from the string.
Codeβ
Interfaceβ
typescript
interface RemoveCharactersOptions {
letters?: boolean; // default: true
numbers?: boolean; // default: false
specialCharacters?: boolean; // default: false
whiteSpace?: boolean; // default: false
}
function removeLetters(value: string, options?: RemoveCharactersOptions): string
Usageβ
typescript
import { removeLetters } from '@modern-kit/utils';
const input = 'Hello, δΈη! μλ
νμΈμ 123 γγγ«γ‘γ― $100 + 200 = 300! π';
const removeLetterOnly = removeLetters(input); // ', ! 123 $100 + 200 = 300! π'
const removeLettersAndWhiteSpace = removeLetters(input, {
letters: true,
whiteSpace: true,
}); // ',!123$100+200=300!π'
const removeNumbersAndSpecialCharacters = removeLetters(input, {
numbers: true,
specialCharacters: true,
}); // 'Hello δΈη μλ
νμΈμ γγγ«γ‘γ― '
const withoutAllCharacters = removeLetters(input, {
letters: true,
numbers: true,
specialCharacters: true,
whiteSpace: true,
}); // ''