Keeps specific character types or substring(s) in a string. See also: strip()
keep(str: string, options: KeepOptions = {}): string
type CharacterType =
| "letters"
| "numbers"
| "spaces"
| "special"
| "lowercase"
| "uppercase"
| "punctuation"
interface StripOptions {
types?: CharacterType[]
custom?: string[]
}
// Example:
keep("hello1234", { type: ["numbers"] }) //=> "1234"
keep("hello1234", { type: ["letters"] }) //=> "hello"
keep("hello, newman!", { type: ["punctuation"] }) //=> ",!"
keep("hello@#$%^", { type: ["special"] }) //=> "@#$%^"
keep("hello newman", { type: ["spaces"] }) //=> " "
keep("hello newman", { custom : ["new", "man"] }) //=> "newman"