Skip to main content

extractLetters

A function that extracts characters from a given string according to the specified options.

By default, it extracts letters only. The following options can be configured:

  • letters: Specifies whether to extract letters from the string.
  • numbers: Specifies whether to extract numbers from the string.
  • specialCharacters: Specifies whether to extract special characters from the string.
  • whiteSpace: Specifies whether to extract whitespace from the string.

Code​

πŸ”— View source code


Interface​

typescript
interface ExtractLettersOptions {
letters?: boolean; // default: true
numbers?: boolean; // default: false
specialCharacters?: boolean; // default: false
whiteSpace?: boolean; // default: false
}

function extractLetters(value: string, options?: ExtractLettersOptions): string

Usage​

typescript
import { extractLetters } from '@modern-kit/utils';

const input = 'Hello, δΈ–η•Œ! μ•ˆλ…•ν•˜μ„Έμš” 123 こんにけは $100 + 200 = 300! πŸ˜„';

const letterOnly = extractLetters(input); // 'HelloδΈ–η•Œμ•ˆλ…•ν•˜μ„Έμš”γ“γ‚“γ«γ‘γ―'

const lettersAndWhiteSpace = extractLetters(input, {
letters: true,
whiteSpace: true,
}); // 'Hello δΈ–η•Œ μ•ˆλ…•ν•˜μ„Έμš” こんにけは '

const numbersAndSpecialCharacters = extractLetters(input, {
numbers: true,
specialCharacters: true,
}); // ',!123$100+200=300!πŸ˜„'

const allCharacters = extractLetters(str, {
letters: true,
numbers: true,
specialCharacters: true,
whiteSpace: true,
}); // 'Hello, δΈ–η•Œ! μ•ˆλ…•ν•˜μ„Έμš” 123 こんにけは $100 + 200 = 300! πŸ˜„'