UNPKG

@greenlabs/rescript-korean-numeral

Version:
117 lines (107 loc) 2.93 kB
// Generated by ReScript, PLEASE EDIT WITH CARE import * as Js_array from "rescript/lib/es6/Js_array.js"; import * as Belt_List from "rescript/lib/es6/Belt_List.js"; import * as Belt_Option from "rescript/lib/es6/Belt_Option.js"; import * as Primitive_bigint from "rescript/lib/es6/Primitive_bigint.js"; let unitsInKorean = { hd: "", tl: { hd: "만", tl: { hd: "억", tl: { hd: "조", tl: { hd: "경", tl: { hd: "해", tl: { hd: "자", tl: { hd: "양", tl: { hd: "구", tl: { hd: "간", tl: { hd: "정", tl: { hd: "재", tl: { hd: "극", tl: { hd: "항하사", tl: { hd: "아승기", tl: { hd: "나유타", tl: { hd: "불가사의", tl: { hd: "무량대수", tl: /* [] */0 } } } } } } } } } } } } } } } } } }; function split(divided) { if (divided === 0n) { return /* [] */0; } else { return { hd: Primitive_bigint.mod_(divided, 10000n), tl: split(Primitive_bigint.div(divided, 10000n)) }; } } function fromBigInt(num, dropOpt) { let drop = dropOpt !== undefined ? dropOpt : 0; return Js_array.joinWith(" ", Belt_List.toArray(Belt_List.reverse(Belt_List.keep(Belt_Option.getWithDefault(Belt_List.drop(Belt_List.zipBy(split(num), unitsInKorean, (num, unit) => { if (num === 0n) { return ""; } else { return num.toLocaleString() + unit; } }), drop), /* [] */0), i => i !== "")))); } function fromInt(num, dropOpt) { let drop = dropOpt !== undefined ? dropOpt : 0; return fromBigInt(BigInt(String(num)), drop); } function fromFloat(num, dropOpt) { let drop = dropOpt !== undefined ? dropOpt : 0; return fromBigInt(BigInt(String(Math.ceil(num))), drop); } function fromString(num, dropOpt) { let drop = dropOpt !== undefined ? dropOpt : 0; try { return fromBigInt(BigInt(num), drop); } catch (exn) { return; } } let mann = 10000n; export { unitsInKorean, mann, split, fromBigInt, fromInt, fromFloat, fromString, } /* No side effect */