Skip to Content
Docs menu

Packages / normalizer

@kaab/normalizer

Clean up text: trim it, lowercase it, and collapse repeated whitespace.

MITv0.1.0experimental
New to Kaab? Every package installs the same way. Read the installation guide first.

Installation

Add the package with the package manager you use.

$ npm i @kaab/normalizer

Usage

Import normalize and pass it a string.

import { normalize } from "@kaab/normalizer";

const clean = normalize("SOO   dhawoow");
// "soo dhawoow"

normalize does three things:

  1. Removes whitespace from the start and the end.
  2. Replaces every run of whitespace (spaces, tabs, line breaks) with one space.
  3. Converts the text to lowercase.

API

NameTypeDescription
normalize(text)functionReturns the cleaned text as a string.
textstringThe text to clean up.

Licence

Released under the MIT licence. You can use it in personal and commercial projects. Keep the licence notice in your copy.

On this page

Found a problem?

Open an issue or send a fix. First-time contributors are welcome.

Contribute