hyphen-sanitizer
TypeScript icon, indicating that this package has built-in type declarations

0.1.0 • Public • Published

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

Package Sidebar

Install

npm i hyphen-sanitizer

Weekly Downloads

3

Version

0.1.0

License

MIT

Unpacked Size

5.19 kB

Total Files

5

Last publish

Collaborators

  • palashmon