DEV Community

Cover image for An utility library for converting English numerals and dates to Bengali
TriptoAfsin
TriptoAfsin

Posted on

An utility library for converting English numerals and dates to Bengali

Logo

Made in 🇧🇩(Bangladesh) with 💖

Description

bang-utils is a lightweight utility library for converting English numerals and dates to Bengali in TypeScript/ JavaScript. It provides functions to convert numbers, dates, and months from English to Bengali script.

Features -

  1. Full TypeScript Support
  2. English Number to Bangla Number(21.21 -> ২১.২১)
  3. English Date to Bangla Date(2-5-2024 -> ৫ ফেব্রুয়ারি, ২০২৪)
  4. English Time to Bangla Time (15:48 -> দুপুর ৩ টা ৪৮ মিনিট)
  5. English Number to Bangla In Words(50.25 -> পঞ্চাশ দশমিক দুই পাঁচ)
  6. Currency Number to Bangla Currency(125.58 -> ১২৫ টাকা ৫৮ পয়সা)

Installation

You can install bang-utils via npm or yarn:

npm install bang-utils
Enter fullscreen mode Exit fullscreen mode

or

yarn add bang-utils
Enter fullscreen mode Exit fullscreen mode

Usage

Importing

You can import the functions from bang-utils using ES6 import syntax:

import {
  numBang,
  dateBang,
  monthBang,
  numToBanglaWords,
  dayBang,
  currencyToBang,
  timeBang,
} from "bang-utils";
Enter fullscreen mode Exit fullscreen mode

Converting English Numerals to Bengali

console.log("number: ", numBang(21)); // Output: number: ২১
console.log("decimal number: ", numBang(21.21)); // Output: decimal number: ২১.২১
Enter fullscreen mode Exit fullscreen mode

Converting Dates to Bengali

console.log("month: ", monthBang("2024-05-02")); // Output: month: মে
console.log("day: ", dayBang("2024-02-26")); //day: সোমবার
console.log("date: ", dateBang("2-5-2024", ",", "D M, YYYY")); // Output: date: ৫ ফেব্রুয়ারি, ২০২৪
Enter fullscreen mode Exit fullscreen mode

Converting Numbers to Bengali Words

console.log("to Bangla words: ", numToBanglaWords(50.25)); // Output: to Bangla words: পঞ্চাশ দশমিক দুই পাঁচ
Enter fullscreen mode Exit fullscreen mode

Converting Currency Numbers to Bengali Currency

console.log("currency: ", currencyToBang(50)); //currency: ৫০ টাকা
console.log("currency: ", currencyToBang(125.58)); //currency: ১২৫ টাকা ৫৮ পয়সা
Enter fullscreen mode Exit fullscreen mode

Converting Date Time to Bengali Time

console.log("detailed time: ", timeBang(new Date())); //দুপুর ৩ টা ৪৮ মিনিট
console.log("normal time: ", timeBang(new Date(), "normal")); // দুপুর ৩.৫০ মিনিট
console.log("short time: ", timeBang(new Date(), "short")); //৩.৫০ মিনিট
Enter fullscreen mode Exit fullscreen mode

Inspirations & Credits

The numToBanglaWords() was based on a open source project by MAHMUDUL HASSAN named number-to-bengali-words

📌 Github : https://github.com/TriptoAfsin/bang-utils
📌 NPM: https://www.npmjs.com/package/bang-utils?activeTab=readme

Top comments (0)