UNPKG

hangul-util

Version:
68 lines (67 loc) 4.63 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.formatNumber = formatNumber; exports.formatNumberAll = formatNumberAll; var _utils = require("./utils"); var _constant = require("./constant"); function formatNumber() { var _format$toString, _format$toString$spli, _parts$map, _parts$map$join, _parts$map$join$trim; var format = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : ""; var formatter = function formatter() { var format = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : ""; if (!(0, _utils.isNumber)(Number(format))) { return ""; } return (0, _utils.chunkAtEnd)(String(format), 4).reduce(function (acc, item, index) { var _thousandUnits$index; var unit = (_thousandUnits$index = _constant.thousandUnits[index]) !== null && _thousandUnits$index !== void 0 ? _thousandUnits$index : ""; if (!Number(item)) { return acc; } return "".concat(Number(item)).concat(unit, " ").concat(acc); }, "").trim(); }; if (String(format).length > _constant.OVER_DIGIT) { return "범위초과"; } var parts = (format === null || format === void 0 || (_format$toString = format.toString) === null || _format$toString === void 0 || (_format$toString = _format$toString.call(format)) === null || _format$toString === void 0 || (_format$toString = _format$toString.replace(/,/g, "")) === null || _format$toString === void 0 || (_format$toString$spli = _format$toString.split) === null || _format$toString$spli === void 0 ? void 0 : _format$toString$spli.call(_format$toString, ".")) || []; var result = []; for (var i = 0; i < parts.length; i++) { result.push(formatter(parts[i])); } return (parts === null || parts === void 0 || (_parts$map = parts.map) === null || _parts$map === void 0 || (_parts$map = _parts$map.call(parts, formatter)) === null || _parts$map === void 0 || (_parts$map$join = _parts$map.join) === null || _parts$map$join === void 0 || (_parts$map$join = _parts$map$join.call(_parts$map, " 점 ")) === null || _parts$map$join === void 0 || (_parts$map$join$trim = _parts$map$join.trim) === null || _parts$map$join$trim === void 0 ? void 0 : _parts$map$join$trim.call(_parts$map$join)) || ""; } function formatNumberAll() { var _format$toString2, _format$toString2$spl, _parts$map2, _parts$map2$join, _parts$map2$join$trim; var format = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : ""; var formatter = function formatter() { var format = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : ""; if (!(0, _utils.isNumber)(Number(format))) { return ""; } return (0, _utils.chunkAtEnd)(String(format), 4).reduce(function (acc, item, index) { var _thousandUnits$index2; if (!Number(item)) { return acc; } var numberUnit = ""; var zeroItem = (0, _utils.zeroPad)(item, 4); for (var i = 0; i < 4; i++) { var number = Number(zeroItem[i]); if (number) { var unit = _constant.tenUnits[3 - i]; numberUnit += "".concat(unit && number === 1 ? "" : _constant.numberUnits[number]).concat(unit); } } var thousandUnit = (_thousandUnits$index2 = _constant.thousandUnits[index]) !== null && _thousandUnits$index2 !== void 0 ? _thousandUnits$index2 : ""; return "".concat(numberUnit).concat(numberUnit ? thousandUnit : "", " ").concat(acc); }, "").trim(); }; if (String(format).length > _constant.OVER_DIGIT) { return "범위초과"; } var parts = (format === null || format === void 0 || (_format$toString2 = format.toString) === null || _format$toString2 === void 0 || (_format$toString2 = _format$toString2.call(format)) === null || _format$toString2 === void 0 || (_format$toString2 = _format$toString2.replace(/,/g, "")) === null || _format$toString2 === void 0 || (_format$toString2$spl = _format$toString2.split) === null || _format$toString2$spl === void 0 ? void 0 : _format$toString2$spl.call(_format$toString2, ".")) || []; return (parts === null || parts === void 0 || (_parts$map2 = parts.map) === null || _parts$map2 === void 0 || (_parts$map2 = _parts$map2.call(parts, formatter)) === null || _parts$map2 === void 0 || (_parts$map2$join = _parts$map2.join) === null || _parts$map2$join === void 0 || (_parts$map2$join = _parts$map2$join.call(_parts$map2, " 점 ")) === null || _parts$map2$join === void 0 || (_parts$map2$join$trim = _parts$map2$join.trim) === null || _parts$map2$join$trim === void 0 ? void 0 : _parts$map2$join$trim.call(_parts$map2$join)) || ""; }