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

read-vietnamese-number

v2.3.0

Published

Convert numbers to text in Vietnamese

Readme

read-vietnamese-number-js

Check Code Publish Package Deploy Site

Thư viện đọc số thành chữ trong Tiếng Việt, với các tính năng:

  • Hỗ trợ số âm, số thập phân, số lớn tùy ý
  • Có nhiều tùy chọn: đơn vị tính, dấu phân tách,...
  • Hoạt động tốt trong trình duyệt và Node.js

Hỗ trợ TypeScript, tương thích với JavaScript từ ES6 trở lên. Hoạt động với các module system như ESM và CommonJS.

Live demo tại https://tonghoangvu.github.io/read-vietnamese-number-js/.

Bạn cũng có thể test nhanh thư viện với npx command mà không cần cài đặt.

npx read-vietnamese-number 3.14
# ba chấm mười bốn đơn vị

Installation

Cài đặt thư viện với NPM, Yarn hoặc các package manager khác.

# NPM
npm install read-vietnamese-number

# Yarn
yarn add read-vietnamese-number

Hoặc sử dụng trực tiếp trong browser thông qua CDN (hoặc tự host). Chú ý nên kèm theo version cố định trong CDN URL, ví dụ như https://cdn.jsdelivr.net/npm/[email protected]/+esm (đây không phải version mới nhất).

<script type="module">
  import {} from 'https://cdn.jsdelivr.net/npm/read-vietnamese-number/+esm'
  // ...
</script>

Usage

Cách sử dụng gồm 3 bước:

  • Tạo cấu hình đọc số và điều chỉnh phù hợp
  • Đọc chuỗi số với cấu hình đã tạo
  • Xử lý lỗi phát sinh

Code example

import { InvalidNumberError, ReadingConfig, doReadNumber } from 'read-vietnamese-number' // or CDN URL

// Config reading options
const config = new ReadingConfig()
config.unit = ['đồng']

try {
  // Start reading
  const number = '-12345.6789'
  const result = doReadNumber(number, config)
  console.log(result)
} catch (err) {
  // Handle errors
  if (err instanceof InvalidNumberError) {
    console.error('Số không hợp lệ')
  } else {
    console.error(err)
  }
}

Error handling

Thư viện ném ra 2 loại ReadVietnameseNumberError sau nếu có lỗi trong quá trình đọc số:

  • TypeError khi input không hợp lệ
  • InvalidNumberError khi số chứa ký tự không hợp lệ

Hàm doReadNumber() chấp nhận input là stringbigint, ném TypeError với các trường hợp khác. Hành vi này liên quan đến các vấn đề định dạng số của JavaScript (tràn số, mất độ chính xác,...). Đây là error hoàn toàn tránh được ở runtime nếu type của input là string hoặc bigint.

Từ version 2.2.0, thư viện hỗ trợ đọc số với độ lớn không giới hạn. Nên nâng cấp lên version này để tránh các vấn đề khi đọc số lớn (issue #38).

Với các version cũ hơn, thư viện sẽ ném NotEnoughUnitError nếu cấu hình đọc số không có đủ số lượng đơn vị phù hợp. Nên giới hạn độ lớn số nhập vào cho phù hợp với các đơn vị hiện có (mặc định hỗ trợ đến tỉ tỉ). Ngoài ra có thể xử lý bằng cách thêm các đơn vị lớn hơn vào cấu hình (không khuyến khích).