1.0.2 • Published 3 months ago

extract-alphanumeric v1.0.2

Weekly downloads
-
License
MIT
Repository
github
Last release
3 months ago

extract-alphanumeric

extract-alphanumeric is a small utility designed to extract alphanumeric characters from a given string.


Installation

npm install extract-alphanumeric

Function Signature

const extract = (
  input: string,
  options?: Options
): string

Parameters

input (string)

The input string from which alphanumeric characters will be extracted.

options (Options)

An object containing configuration options.

OptionTypeDefaultDescription
includestring""A string of characters to explicitly include in the extracted output, even if they aren't alphanumeric.
excludestring""A string of characters to exclude from the extracted output.

Notes

  • White spaces are filtered out of an input string by default. include can be used if you wish to retain whitespaces (although it may be necessary to trim the output afterwards manually)
  • include and exclude will 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 include and exclude, exclude will 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: ""
1.0.2

3 months ago

1.0.1

4 months ago

1.0.0

4 months ago