Skip to content

🚀 Simplifying text by replacing hyphens with ease

License

Notifications You must be signed in to change notification settings

palashmon/hyphen-sanitizer

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

28 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

hyphen-sanitizer

Simplifying text by replacing hyphens with ease

CI npm version npm downloads

Hyphens are commonly used in strings to separate words or denote compound words. However, in certain scenarios, it's necessary to sanitize hyphens by replacing them with another character or removing them entirely. hyphen-sanitizer provides a simple yet powerful solution for sanitizing hyphens within strings, enhancing data consistency and usability.

Key Features

  • Sanitizes hyphens within strings
  • Allows customization of replacement string
  • Defaults to space if no replacement string is provided
  • Versatile and easy to integrate into existing projects

Install

npm install hyphen-sanitizer

Usage

import hyphenSanitizer from "hyphen-sanitizer";

// Example 1 - Default replacement
// Replaces hyphens with spaces
const text = "Hello-world";
const sanitizedText = hyphenSanitizer(text);
console.log(sanitizedText); //=> "Hello world"

// Example 2 - Custom replacement
// Replaces hyphens with underscores
const replacement = "_";
const sanitizedText2 = hyphenSanitizer(text, replacement);
console.log(sanitizedText2); //=> "Hello_world"

API

hyphenSanitizer(input, replacement)

input

Type: string

The input string to sanitize. This string may contain hyphens that need to be replaced.

replacement

Type: string
Default: ' ' (space)

The replacement string to use in place of hyphens. If no replacement string is provided, hyphens will be replaced with spaces.

Related

License

MIT © Palash Mondal