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β
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! π'