npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

normalize-text

v2.5.0

Published

Provides a simple API to normalize texts, white-spaces, paragraphs & diacritics.

Downloads

65,841

Readme

Normalize Text

Build Status License Package tree-shaking Package minified & gzipped size Package dependency count

Provides a simple API to normalize texts, white-spaces, names, paragraphs & diacritics (accents).

  • 📦 Distributions in ESM, CommonJS, UMD and UMD minified formats.

    • Supports NodeJS ESM and CommonJS;
  • ⚡ Lightweight:

    • It's bundled with Rollup and Bublé.
    • Smaller than 1KB (min + gzip).
    • Supports tree shaking.
  • 🔋 Bateries included:

    • Its not based on newer browser's APIs or es2015+ features.
    • Only needs String.prototype.normalize polyfill for older browsers, and don't crashes without it.
  • 🏷 Safe:

    • Type declarations for IDEs and editor's autocomplete/intellisense.
    • Made with TypeScript as strict as possible.
    • Unit tests with Jest.
    • Travis CI that keeps tests running.

Install

normalize-text is published under NPM registry, so you can install using any Node.js package manager.

npm install normalize-text --save

# If you're using Yarn.
yarn add normalize-text

Install from CDN

The bundles of this module are also available on JSDelivr and UNPKG CDNs.

In both you can import just the bundle you want or use default one, UMD.

<!-- Using default bundle from JSDelivr -->
<script src="https://cdn.jsdelivr.net/npm/normalize-text"></script>

<!-- Using default bundle from UNPKG -->
<script src="https://unpkg.com/normalize-text"></script>

<script>
  /**
   * UMD bundle expose brazilian-values through `normalizeText` object.
   */
  normalizeText.capitalizeFirstLetter('vitor');
  //=> "Vitor"
</script>

Usage

All the functions are named exported from module.

import { normalizeText } from 'normalize-text';

normalizeText([
  'Olá\r\n',
  '  como  está a   senhorita?'
]);
//=> "ola como esta a senhorita?"

API

capitalizeFirstLetter

Capitalize first character of received text.

capitalizeFirstLetter('vitorLuizC');
//=> "VitorLuizC"

normalizeDiacritics

If String.prototype.normalize is supported it normalizes diacritics by replacing them with "clean" character from received text.

It doesn't normalize special characters.

normalizeDiacritics('Olá, você aí');
//=> 'Ola, voce ai'

normalizeDiacritics('àáãâäéèêëíìîïóòõôöúùûüñçÀÁÃÂÄÉÈÊËÍÌÎÏÓÒÕÔÖÚÙÛÜÑÇ');
//=> "aaaaaeeeeiiiiooooouuuuncAAAAAEEEEIIIIOOOOOUUUUNC"

normalizeDiacritics('@_$><=-#!,.`\'"');
//=> "@_$><=-#!,.`'\"";

normalizeName

Normalize received name by normalizing it's white-spaces and capitalizing first letter of every word but exceptions (received in lower-case).

normalizeName(' fernanDA  MONTENEGRO');
//=> "Fernanda Montenegro"

normalizeName(' wilson da costa', ['da']);
//=> "Wilson da Costa"

normalizeParagraph

Normalize a paragraph by normalizing its white-spaces, capitalizing first letter and adding a period at end.

normalizeParagraph(' once upon a time');
//=> "Once upon a time."

normalizeParagraph('hello world, my friend\r\n');
// => 'Hello world, my friend.'

normalizeText

Resolve received texts (when receives an Array) by normalizing its white-spaces and its diacritics and transforming to lower-case.

normalizeText(' so there\'s  a  Way to NORMALIZE ');
//=> "so there\'s a way to normalize"

normalizeText(['Olá\r\n', 'como está a   senhorita?']);
//=> "ola como esta a senhorita?"

normalizeWhiteSpaces

Normalize all white-space characters and remove trailing ones received text.

normalizeWhiteSpaces(' What exactly is it?   ');
//=> "What exactly is it?"

normalizeWhiteSpaces('Hi,   how is \r\n everything  \t?');
//=> 'Hi, how is everything ?'

normalizeWhiteSpaces`It is ${temperature}\n  degree\r outside.  `
//=> 'It is 25 degree outside.'

License

Released under MIT license. You can see it here.