UNPKG

currency-in-words

Version:

A light-weight, fast and efficient lib that converts currency or any numbers to corresponding words

56 lines 1.8 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.handleTens = exports.handleTeens = exports.handleOnes = exports.isSecondCharZero = exports.isFirstCharZero = void 0; var lang_1 = __importDefault(require("../lang")); var globalConfig_1 = require("../lib/globalConfig"); var lang = (0, globalConfig_1.getGlobalConfig)().lang; var _a = lang_1.default[lang], singleDigit = _a.singleDigit, caseOne = _a.caseOne, twoDigit = _a.twoDigit; function isFirstCharZero(value) { return +value[0] === 0; } exports.isFirstCharZero = isFirstCharZero; function isSecondCharZero(value) { return +value[1] === 0; } exports.isSecondCharZero = isSecondCharZero; /** * handles 0-9 * * @param value the value to be translated to words * @returns translated value */ function handleOnes(value) { return singleDigit[+value]; } exports.handleOnes = handleOnes; /** * handles 11-19 * * @param value the value to be translated to words * @returns translated value */ function handleTeens(value) { if (+value[0] === 1) return caseOne[+value.slice(-1)]; else return "".concat(twoDigit[+value[0]], " ").concat(singleDigit[+value.slice(-1)]); } exports.handleTeens = handleTeens; /** * handles all two-digit values except 11-19 * * @param value the value to be translated to words * @returns translated value */ function handleTens(value) { if (isFirstCharZero(value)) return "".concat(singleDigit[+value[1]]); if (isSecondCharZero(value)) return "".concat(twoDigit[+value[0]]); return handleTeens(value); } exports.handleTens = handleTens; //# sourceMappingURL=common.js.map