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 🙏

© 2026 – Pkg Stats / Ryan Hefner

@nhatdev94/util

v1.2.5

Published

**Package Name:** `@nhatdev94/util`\ **Document Version:** 1.2\ **Last Updated:** \ **Owner:** \ **Status:**

Readme

📦 Common UI Library

Package Name: @nhatdev94/util
Document Version: 1.2
Last Updated:
Owner:
Status:


Bộ công cụ tiện ích (Utility) dùng chung cho hệ sinh thái sản phẩm của nhatdev94. Được xây dựng với tư duy: Stateless, Business-agnostic và Type-safe.

🚀 Cài đặt

npm install @nhatdev94/util

📦 Các module chính

Tài liệu được chia thành 2 nhóm tính năng chính: Data FormattingHTTP Client.

Data Formatting

Hỗ trợ định dạng dữ liệu chuẩn hóa trên toàn hệ thống.

Date Formatting

import { formatDate } from '@nhatdev94/util';

formatDate(new Date(), 'DD/MM/YYYY'); // 05/03/2026

Number & String

  • Number: Định dạng tiền tệ, số thập phân.
  • String: Truncate, capitalize, slugify.

HTTP Client & API Handling

Dựa trên nền tảng axios, cung cấp các công cụ để chuẩn hóa việc gọi API.

Khởi tạo Http Client

Sử dụng createHttp để tạo instance với cấu hình mặc định (interceptor, timeout...).

import { createHttp } from '@nhatdev94/util';

const api = createHttp({
  baseURL: 'https://api.example.com',
  timeout: 10000,
});

HTTP Constants & Types

Thư viện cung cấp sẵn danh sách mã lỗi và các Type hỗ trợ TypeScript:

import { HTTP_CODE, ApiError, ApiResponse } from '@nhatdev94/util';

if (error.code === HTTP_CODE.UNAUTHORIZED) {
  // Xử lý khi hết hạn phiên làm việc
}

Interceptors

Cung cấp các interceptor may-đo sẵn cho việc đính kèm Token hoặc xử lý lỗi tập trung:

  • requestTokenInterceptor: Tự động lấy token từ storage gắn vào Header.
  • responseErrorInterceptor: Format lại lỗi trả về theo chuẩn ApiError.

📏 Nguyên tắc thiết kế (Design Principles)

Tuân thủ nghiêm ngặt bộ tiêu chuẩn đã đề ra:

  • Stateless by default: Các hàm format không lưu trữ trạng thái, luôn trả về giá trị mới dựa trên input.
  • Business-agnostic: Không chứa logic nghiệp vụ cụ thể. Ví dụ: hàm format tiền tệ không mặc định là "VND", bạn phải truyền currency vào.
  • Type-safe: 100% viết bằng TypeScript, hỗ trợ gợi ý code (IntelliSense) tối đa.
  • Backward-compatible: Đảm bảo các hàm core không thay đổi interface đột ngột giữa các phiên bản patch/minor.