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

convert-thai

v1.1.9

Published

A package to convert dates and numbers to Thai format

Downloads

273

Readme

convert-thai

This package is used for converting date and number data into Thai format. (แพ็คเกจนี้ใช้สำหรับแปลงข้อมูลวันที่และตัวเลขเป็นรูปแบบภาษาไทย)

npm npm npm npm bundle size

Install (ติดตั้ง)

Using npm

npm i convert-thai

Using Yarn

yarn add convert-thai

Using in HTML (สำหรับการใช้งานใน HTML)

<script src="https://cdn.jsdelivr.net/npm/convert-thai@latest/dist/bundle.js"></script>

Usage (วิธีการใช้งาน)

Typescript

import { dateFormat, numberFormat, bathText, convertThai } from "convert-thai";

// --- convertThai
convertThai.dateFormat(new Date()) // ๑๘/๐๙/๒๕๖๗
convertThai.numberFormat(1000) // ๑๐๐๐
convertThai.bathText(1000) // หนึ่งพันบาทถ้วน

// --- dateFormat
dateFormat(new Date()); // ๑๘/๐๙/๒๕๖๗
dateFormat("2024-9-18"); // ๑๘/๐๙/๒๕๖๗
dateFormat(new Date(), "dd/mm/yyyy"); // ๑๘/๐๙/๒๕๖๗
dateFormat(new Date(), "dd/mm/yyyy HH:MM:ss"); // ๑๘/๐๙/๒๕๖๗ ๐๗:๓๐:๒๕
dateFormat(new Date(), "dd mmm yyyy"); // ๑๘ ก.ย. ๒๕๖๗
dateFormat(new Date(), "dd mmmm yyyy"); // ๑๘ กันยายน ๒๕๖๗
dateFormat(new Date(), "dddd dd mmmm yyyy"); // พุธ ๑๘ กันยายน ๒๕๖๗
dateFormat(new Date(), "yyyy-mm-dd"); // ๒๕๖๗-๐๙-๑๘

dateFormat(new Date(), "dd/mm/yyyy", "BE"); // พ.ศ. ๑๘/๐๙/๒๕๖๗
dateFormat(new Date(), "dd/mm/yyyy", "CE"); // ค.ศ. ๑๘/๐๙/๒๐๒๔
dateFormat(new Date(), "dd/mm/yyyy", "MS"); // ม.ศ ๑๘/๐๙/๒๖๖๒
dateFormat(new Date(), "dd/mm/yyyy", "JE"); // จ.ศ. ๑๘/๐๙/๑๔๘๒
dateFormat(new Date(), "dd/mm/yyyy", "RE"); // ร.ศ. ๑๘/๐๙/๒๔๓
dateFormat(new Date(), "dd/mm/yyyy", "HE"); // ฮ.ศ. ๑๘/๐๙/๑๔๐๒

// --- numberFormat
numberFormat(123456); // ๑๒๓๔๕๖
numberFormat(123.456, 2); // ๑๒๓.๔๕
numberFormat(123456789, 0, ','); // ๑๒๓,๔๕๖,๗๘๙
numberFormat(-1234); // -๑๒๓๔
numberFormat(-1234, 2); // -๑๒๓๔.๐๐
numberFormat(-1234, 2, ','); // -๑,๒๓๔.๐๐

// --- bathText
bathText(1000); // หนึ่งพันบาทถ้วน
bathText(1000000); // หนึ่งล้านบาทถ้วน
bathText(3750.85) // สามพันเจ็ดร้อยห้าสิบบาทแปดสิบห้าสตางค์
bathText(-1000); // ลบหนึ่งพันบาทถ้วน
bathText(-3750.85) // ลบสามพันเจ็ดร้อยห้าสิบบาทแปดสิบห้าสตางค์

Javascript

const { dateFormat, numberFormat, bathText, convertThai } = require('convert-thai');

// --- convertThai
convertThai.dateFormat(new Date()) // ๑๘/๐๙/๒๕๖๗
convertThai.numberFormat(1000) // ๑๐๐๐
convertThai.bathText(1000) // หนึ่งพันบาทถ้วน

// --- dateFormat
dateFormat(new Date()); // ๑๘/๐๙/๒๕๖๗
dateFormat("2024-9-18"); // ๑๘/๐๙/๒๕๖๗
dateFormat(new Date(), "dd/mm/yyyy"); // ๑๘/๐๙/๒๕๖๗
dateFormat(new Date(), "dd/mm/yyyy HH:MM:ss"); // ๑๘/๐๙/๒๕๖๗ ๐๗:๓๐:๒๕
dateFormat(new Date(), "dd mmm yyyy"); // ๑๘ ก.ย. ๒๕๖๗
dateFormat(new Date(), "dd mmmm yyyy"); // ๑๘ กันยายน ๒๕๖๗
dateFormat(new Date(), "dddd dd mmmm yyyy"); // พุธ ๑๘ กันยายน ๒๕๖๗
dateFormat(new Date(), "yyyy-mm-dd"); // ๒๕๖๗-๐๙-๑๘

dateFormat(new Date(), "dd/mm/yyyy", "BE"); // พ.ศ. ๑๘/๐๙/๒๕๖๗
dateFormat(new Date(), "dd/mm/yyyy", "CE"); // ค.ศ. ๑๘/๐๙/๒๐๒๔
dateFormat(new Date(), "dd/mm/yyyy", "MS"); // ม.ศ ๑๘/๐๙/๒๖๖๒
dateFormat(new Date(), "dd/mm/yyyy", "JE"); // จ.ศ. ๑๘/๐๙/๑๔๘๒
dateFormat(new Date(), "dd/mm/yyyy", "RE"); // ร.ศ. ๑๘/๐๙/๒๔๓
dateFormat(new Date(), "dd/mm/yyyy", "HE"); // ฮ.ศ. ๑๘/๐๙/๑๔๐๒

// --- numberFormat
numberFormat(123456); // ๑๒๓๔๕๖
numberFormat(123.456, 2); // ๑๒๓.๔๕
numberFormat(123456789, 0, ','); // ๑๒๓,๔๕๖,๗๘๙
numberFormat(-1234); // -๑๒๓๔
numberFormat(-1234, 2); // -๑๒๓๔.๐๐
numberFormat(-1234, 2, ','); // -๑,๒๓๔.๐๐

// --- bathText
bathText(1000); // หนึ่งพันบาทถ้วน
bathText(1000000); // หนึ่งล้านบาทถ้วน
bathText(3750.85) // สามพันเจ็ดร้อยห้าสิบบาทแปดสิบห้าสตางค์
bathText(-1000); // ลบหนึ่งพันบาทถ้วน
bathText(-3750.85) // ลบสามพันเจ็ดร้อยห้าสิบบาทแปดสิบห้าสตางค์

HTML

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Convert Thai Test</title>
</head>

<body>
    <script src="https://cdn.jsdelivr.net/npm/convert-thai@latest/dist/bundle.js"></script>
    <script>
        console.log(convertThai.dateFormat(new Date())); // ๑๘/๐๙/๒๕๖๗
        console.log(convertThai.numberFormat(123456)); // ๑๒๓๔๕๖
        console.log(convertThai.bathText(1000)); // หนึ่งพันบาทถ้วน

        const { dateFormat, numberFormat, bathText } = convertThai;

        console.log(dateFormat(new Date(), "dd/mm/yyyy", "CE")); // ๑๘/๐๙/๒๐๒๔
        console.log(numberFormat(123456));  // ๑๒๓๔๕๖
        console.log(bathText(1000)); // หนึ่งพันบาทถ้วน
    </script>
</body>
</html>

Description (คำอธิบาย)

dateFormat

  • dateFormat(date, format, type, era)
    • date (ค่าวันที่) - [จำเป็น]
      • new Date()
      • "2024-6-21"
    • format (รูปแบบวันที่) - [ไม่บังคับ] - (default - "dd/mm/yyyy")
    • era (ศักราช) - [ไม่บังคับ] - (default - "BE")
Meaning of variables (ความหมายของตัวแปร)

| Variable (ตัวแปร) | Description (คำอธิบาย) | | --- | --- | | d | วันที่หลักเดี่ยวไม่เติมเลข ๐ นำหน้า | | dd | วันที่หลักเดี่ยวเติมเลข ๐ นำหน้า | | ddd | วันตัวย่อ เช่น อา, จ, อ, พ, พฤ, ศ, ส | | dddd | วันตัวเต็ม เช่น อาทิตย์, จันทร์, อังคาร, พุธ, พฤหัสบดี, ศุกร์, เสาร์ | | m | เดือนหลักเดี่ยวไม่เติมเลข ๐ นำหน้า | | mm | เดือนหลักเดี่ยวเติมเลข ๐ นำหน้า | | mmm | เดือนตัวย่อ เช่น ม.ค., ก.พ., มี.ค., เม.ย., พ.ค, มิ.ย., ก.ค., ส.ค., ก.ย., ต.ค., พ.ย., ธ.ค. | | mmmm | เดือนตัวเต็ม เช่น มกราคม, กุมภาพันธ์, มีนาคม, เมษายน, พฤษภาคม, มิถุนายน, กรกฎาคม, สิงหาคม, กันยายน, ตุลาคม , พฤศจิกายน , ธันวาคม | | yy | ปีสองหลัก เช่น ๖๗ | | yyyy | ปีตัวเต็ม เช่น ๒๕๖๗ | | H | ชั่วโมงหลักเดียวไม่เติมเลข ๐ นำหน้า | | HH | ชั่วโมงหลักเดียวเติมเลข ๐ นำหน้า | | M | นาทีหลักเดียวไม่เติมเลข ๐ นำหน้า | | MM | นาทีหลักเดียวเติมเลข ๐ นำหน้า | | s | วินาทีหลักเดียวไม่เติมเลข ๐ นำหน้า | | ss | วินาทีหลักเดียวเติมเลข ๐ นำหน้า |

Format (รูปแบบ)

| Format (รูปแบบ) | Example (ตัวอย่าง) | | --- | --- | | dd/mm/yyyy | ๑๘/๐๙/๒๕๖๗ (default) | | dd/mm/yy | ๑๘/๐๙/๖๗ | | yyyy/mm/dd | ๒๕๖๗/๐๙/๑๘ | | yy/mm/dd | ๖๗/๐๙/๑๘ | | HH:MM:ss | ๐๗:๓๐:๒๕ | | dd mmm yyyy | ๑๘ ก.ย. ๒๕๖๗ | | dd mmmm yyyy | ๑๘ กันยายน ๒๕๖๗ | | ddd dd mmm yyyy | พ ๑๘ ก.ย. ๒๕๖๗ | | dddd dd mmmm yyyy | พุธ ๑๘ กันยายน ๒๕๖๗ | | dd/mm/yyyy HH:MM:ss | ๑๘/๐๙/๒๕๖๗ ๐๗:๓๐:๒๕ | | dddd dd mmmm yyyy HH:MM:ss | พุธ ๑๘ กันยายน ๒๕๖๗ ๐๗:๓๐:๒๕ |

Era (ศักราช)

| Variable (ตัวแปร) | Description (คำอธิบาย) | Example (ตัวอย่าง) | | --- | --- | --- | | BE | พ.ศ. (พุทธศักราช) | ๒๕๖๗ (default) | | CE | ค.ศ. (คริสต์ศักราช) | ๒๐๒๔ | | MS | ม.ศ. (มหาศักราช) | ๒๖๖๒ | | JE | จ.ศ. (จุลศักราช) | ๑๔๘๒ | | RE | ร.ศ. (รัตนโกสินทร์ศักราช) | ๒๔๓ | | HE | ฮ.ศ. (ฮิจเราะห์ศักราช) | ๑๔๐๒ |

numberFormat

  • numberFormat(number, decimals, thousandsSeparator)
    • number (ค่าตัวเลข) - [จำเป็น]
      • 1000, 1000.50, -1000 เป็นต้น
    • decimals (ทศนิยม) - [ไม่บังคับ]
      • 0, 1, 2, 3, ...n (จำนวนเต็มบวก)
    • thousandsSeparator (ตัวคั่นหลักพัน) - [ไม่บังคับ]
      • ","

bathText

  • bathText(number)
    • number (ค่าตัวเลข) - [จำเป็น]
      • -9999999999999 - 9999999999999 (support)

Refer (อ้างอิง)

Date/Time Formats