1.0.2 • Published 9 months ago
extract-alphanumeric v1.0.2
extract-alphanumeric
extract-alphanumeric is a small utility designed to extract alphanumeric characters from a given string.
Installation
npm install extract-alphanumericFunction Signature
const extract = (
input: string,
options?: Options
): stringParameters
input (string)
The input string from which alphanumeric characters will be extracted.
options (Options)
An object containing configuration options.
| Option | Type | Default | Description |
|---|---|---|---|
include | string | "" | A string of characters to explicitly include in the extracted output, even if they aren't alphanumeric. |
exclude | string | "" | A string of characters to exclude from the extracted output. |
Notes
- White spaces are filtered out of an input string by default.
includecan be used if you wish to retain whitespaces (although it may be necessary to trim the output afterwards manually) includeandexcludewill treat each character individually. This means that it is not possible to whitelist or blacklist specific words or phrases.- If the same characters appear in both
includeandexclude,excludewill take priority
Example Usage
import { extract } from "extract-alphanumeric";
console.log(extract("Hello Everyone"));
// Output: "HelloEveryone"
console.log(extract("I'll have two number 9s, and a large soda.", { include: "'. " }));
// Output: "I'll have two number 9s and a large soda." -> Missing comma
console.log(extract("I'll have two number 9s, and a large soda.", { include: " ", exclude: "123456789" }));
// Output: "Ill have two number s and a large soda" -> other numbers ignored, punctuation all removed
console.log(extract("some input", { include: "some input", exclude: "some input" }));
// Output: ""