Skip to main content

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​

πŸ”— View source 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,
}); // ''