Remove or Replace Hyphens In Strings – Hyphen Sanitizer

Category: Javascript , Text | July 7, 2024
Author:palashmon
Views Total:1 view
Official Page:Go to website
Last Update:July 7, 2024
License:MIT

Preview:

Remove or Replace Hyphens In Strings – Hyphen Sanitizer

Description:

hyphen-sanitizer is a straightforward JavaScript library designed to help developers clean up strings by removing or replacing hyphens.

It can be useful in environments where string format consistency is crucial, such as database entries, URL slugs, or user input processing. For instance, converting hyphens to spaces can make concatenated words more readable, while swapping them for underscores might better suit coding standards or aesthetic preferences in technical contexts.

How to use it:

1. Install the Hyphen Sanitizer library with NPM.

# NPM
$ npm install hyphen-sanitizer

2. Import the hyphenSanitizer component into your project.

import hyphenSanitizer from "hyphen-sanitizer";

3. The library offers a user-friendly API with a single function: hyphenSanitizer(input, replacement). The input argument is the string you want to sanitize, and the optional replacement argument lets you specify what you want to replace hyphens with. Leave it blank, and spaces will be used by default.

const text = "CSS-Script";
// Remove hyphens
const sanitizedText = hyphenSanitizer(text);
// => "CSS Script"
console.log(sanitizedText);
// Replace hyphens
const replacement = "+";
const sanitizedText = hyphenSanitizer(text);
// => "CSS+Script"
console.log(sanitizedText);

Changelog:

v1.0.2 (07/07/2024)

  • Update dependencies

You Might Be Interested In:


Leave a Reply