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 🙏

© 2025 – Pkg Stats / Ryan Hefner

normalize-vietnamese

v1.0.2

Published

A TypeScript library for Vietnamese text processing including accent normalization, text masking, and string utilities

Readme

Normalize Vietnamese

A TypeScript library for Vietnamese text processing including accent normalization, text masking, and string utilities.

Features

  • Vietnamese Accent Normalization: Automatically correct Vietnamese accent placement according to grammar rules
  • Text Masking: Mask sensitive information in strings
  • Text Normalization: Convert text to lowercase, remove special characters
  • TypeScript Support: Full TypeScript definitions included
  • Zero Dependencies: Only requires slugify for text normalization

Installation

# use npm
npm install normalize-vietnamese
# use yarn
yarn add normalize-vietnamese

Usage

Import

import Str from "normalize-vietnamese";
// or
import { Str } from "normalize-vietnamese";

Vietnamese Accent Normalization

The normalizeVietnameseAccent method corrects Vietnamese accent placement according to Vietnamese grammar rules:

// Correct diphthongs (2 vowels) - accent on first vowel
Str.normalizeVietnameseAccent("toà"); // returns 'tòa'
Str.normalizeVietnameseAccent("thuỷ"); // returns 'thủy'

// Correct triphthongs (3 vowels) - accent on second vowel
Str.normalizeVietnameseAccent("tòan"); // returns 'toàn'
Str.normalizeVietnameseAccent("khủyu"); // returns 'khuỷu'

// Exception: ê and ơ have priority regardless of position
Str.normalizeVietnameseAccent("thủơ"); // returns 'thuở'
Str.normalizeVietnameseAccent("chuỵên"); // returns 'chuyện'

// Handle special consonant clusters (gi, qu)
Str.normalizeVietnameseAccent("gìa"); // returns 'già'
Str.normalizeVietnameseAccent("qủa"); // returns 'quả'

// Process multiple words
Str.normalizeVietnameseAccent("tòa nhà toàn"); // returns 'tòa nhà toàn'

Vietnamese Accent Rules

  1. Single vowel: Accent stays on the vowel
  2. Two vowels (diphthong): Accent on first vowel
  3. Three vowels (triphthong): Accent on second vowel
  4. Exception: ê and ơ have priority regardless of position
  5. Special consonants: gi and qu are treated as single consonants

Text Masking

// Mask entire string
Str.mask("hello"); // returns '*****'

// Mask with start and end positions
Str.mask("hello", 1, 4); // returns 'h***o'

// Negative positions (from end)
Str.mask("hello", -2, 4); // returns 'hel*o'
Str.mask("hello", 1, -1); // returns 'h***o'

Text Normalization

// Convert to lowercase, remove special characters
Str.normalize("Hello World!"); // returns 'hello world'

// Handles Vietnamese characters
Str.normalize("Xin chào thế giới!"); // returns 'xin chao the gioi'

API Reference

Str.normalizeVietnameseAccent(text: string): string

Normalizes Vietnamese accent marks according to Vietnamese grammar rules.

  • Parameters: text - The text to normalize
  • Returns: The normalized text with proper accent placement
  • Throws: Returns original input if not a string

Str.mask(text: string, start?: number, end?: number): string

Masks part of a string with asterisks.

  • Parameters:
    • text - The text to mask
    • start - Start position (default: 0, supports negative values)
    • end - End position (default: 0, supports negative values)
  • Returns: The masked string
  • Throws: Returns original text for invalid parameters

Str.normalize(text: string): string

Normalizes text by converting to lowercase and removing special characters.

  • Parameters: text - The text to normalize
  • Returns: The normalized text
  • Throws: Returns original input if not a string

Development

Setup

git clone https://github.com/nvminh461/normalize-vietnamese
cd normalize-vietnamese
npm install

Scripts

# Build the library
npm run build

# Run tests
npm test

# Run tests in watch mode
npm run test:watch

# Generate test coverage
npm run test:coverage

# Development mode (watch for changes)
npm run dev

Testing

The library includes comprehensive tests covering all functionality:

npm test

Requirements

  • Node.js >= 14.0.0
  • TypeScript >= 4.0.0 (for development)

License

MIT

Contributing

  1. Fork the repository
  2. Create your feature branch (git checkout -b feature/amazing-feature)
  3. Commit your changes (git commit -m 'Add some amazing feature')
  4. Push to the branch (git push origin feature/amazing-feature)
  5. Open a Pull Request

Changelog

1.0.0

  • Initial release
  • Vietnamese accent normalization
  • Text masking functionality
  • Text normalization utilities
  • Full TypeScript support