/myanmar-notation

Node.js module and a library which converts the given number into words in Myanmar

Primary LanguageJavaScriptMIT LicenseMIT

myanmar-notation

A Node.js module and a library which converts the given number into words in Myanmar. Following written rule and add the creaky tone on number places 10^5, 10^6 and 10^7. Check live Demo is available...

workflows-badge travis-badge npm-badge webpack-badge test-mocha

Normally "ပေါင်း" in Myanmar translated "plus", however the same word using in a large number of amount dedicate multiply. For example သိန်းတစ်သောင်း is 1 0000 00000 and can also/usually pronounced သိန်းပေါင်း တစ်သောင်း which mean "(100000*10000)", therefor "သိန်းတစ်သောင်း" and "သိန်းပေါင်း တစ်သောင်း" has dedicated the same amount. This module is using "ပေါင်း" when the dedicated amount is larger than the subsequent scale name "ခု", "ဆယ်", "ရာ", "ထောင်", "သောင်း", "သိန်း", "သန်း" and "ကု​ဋေ​".

It can be a bit confusing between "သိန်းတစ်သိန်း" and "တစ်သိန်း" as of spoken usually does

"ငွေ သိန်းတစ်သိန်းလောက် ချေးပေးလို့ရမလား ခင်ဗျာ"

they probabbly just wanted "100000", but it is entirely different as "သိန်းတစ်သိန်း" mean "10000 000000" and "တစ်သိန်း" mean "100000".

There are also difference positioning scale name, primarly it is followed by the given number

10: "တစ်ဆယ်" 20: "နှစ်ဆယ်" 10000000: "တစ်ကု​ဋေ​"

However using this primarly structure in large amount seem very weird, eg.100000000: "တစ်ထောင်သိန်း", "တစ်ရာသန်း", "တစ်ဆယ်ကု​ဋေ​", therefore in such amount the scale name lead the number to take away this weirdness.

100000000: "သိန်းတစ်ထောင်", "သန်းတစ်ရာ", "ကု​ဋေ​တစ်ဆယ်"

Feature

  • Decimals are rounded (floor)
  • Query get(2700), get('၂၇၀၀'), get('27,000,000.00') ,get('5.23e+8') is flexible
  • Demo
  • mocha
  • webpack

Usage

Node.JS

Oops: myanmar-notation export ES module from CommonJS built version.

export * from "./index.js";

import * as e from "./index.js";
export default e;

npm i myanmar-notation can be require or import from your Node.JS application. However myanmar-notation is assuming that one day npm might force us to seperate ES module and CommonJS. Therefore, it is a good practice to start coding Node.JS application using ES module.

// ES6
import myanmarNotation from 'myanmar-notation';
import {get} from 'myanmar-notation';

myanmarNotation.get(2700);
// myanmarNotation.multiplication(5);
// myanmarNotation.keep(123);
// myanmarNotation.turn('၄၅၆');
get(12345678);

// CommonJS
const myanmarNotation = require('myanmar-notation');
const {get} = require('myanmar-notation');

myanmarNotation.get(2700);
get(12345678);

Browser

Include the file myanmar-notation@latest/min.js in your web application. It is available on UNPKG and jsDelivr.

Now let's assume that you have picked the jsDelivr one...

<script src="https://cdn.jsdelivr.net/npm/ttfmeta@latest/min.js"></script>
<script>
let notation = window.myanmarNotation;
</script>

API

You may assure that the APIs are not going to change without a good reason for end user. So any exported methods and classes name will stays the same as the last updates.

Multiplication

the notation.multiplication() construct the given len to zero ending, it takes 2 arguments (len, head='1'), second argument is optional and return the result as string.

notation.multiplication(5,'10');
> "100000"

Keep

the notation.keep() convert the given string(number) to Burmese number and return the result as string.

notation.keep(1234567);
> "၁၂၃၄၅၆၇"

notation.keep('a567');
> "a၅၆၇"

Turn

the notation.turn() convert the given string(number) to English number and return the result as string.

notation.turn('၁၂၃၄၅၆၇');
> "1234567"

notation.turn('123၅၆၇');
> "123567"

get

the notation.get() return an object if there is a sense in get query, otherwise empty Object return.

notation.get(2700);
// return
>  {
    "number": "၂၇၀၀",
    "digit": "2700",
    "notation": [
      {
        "sense": "နှစ်ထောင့်ခုနစ်ရာ"
      }
    ]
  }

notation.get(12345678);
// return
>  {
    "number": "၁၂၃၄၅၆၇၈",
    "digit": "12345678",
    "notation": [
      {
        "sense": "သိန်းတစ်ရာ့နှစ်ဆယ့်သုံး လေးသောင်းငါးထောင့်ခြောက်ရာ့ခုနစ်ဆယ့်ရှစ်",
        "rule": 5,
        "size": 8,
        "list": [
          "123",
          "45678"
        ]
      },
      {
        "sense": "သန်းတစ်ဆယ့်နှစ် သုံးသိန်းလေးသောင်းငါးထောင့်ခြောက်ရာ့ခုနစ်ဆယ့်ရှစ်",
        "rule": 6,
        "size": 8,
        "list": [
          "12",
          "345678"
        ]
      },
      {
        "sense": "တစ်ကု​ဋေ​ နှစ်သန်းသုံးသိန်းလေးသောင်းငါးထောင့်ခြောက်ရာ့ခုနစ်ဆယ့်ရှစ်",
        "rule": 7,
        "size": 8,
        "list": [
          "1",
          "2345678"
        ]
      }
    ]
  }

License

shield-license