base/format
표기 유틸.
- 재화 / 점수 표기처럼 어느 게임에서나 반복되는 숫자 문자열 처리를 모았다.
Formatting utility.
- Gathers number-string handling that repeats in every game, such as currency / score display.
import { Format } from "./build/vanilla.js";
console.log(Format.formatNumber(12480));
console.log(Format.formatCompactNumber(5600000));
console.log(Format.formatPaddedNumber(7, 3));
console.log(Format.formatMinutesSeconds(75));함수Functions
천 단위 구분 기호를 붙여 반환. (12480 -> "12,480")
Returns with thousands separators. (12480 -> "12,480")
- valuenumber
- 표기할 수.Number to display.
- localestring
- 로케일. (기본 "en-US")Locale. (default "en-US")
반환Returnsstring 천 단위 구분 기호를 붙인 문자열. (toLocaleString 을 따른다)A string with thousands separators. (follows toLocaleString)
짝Counterpart: vanilla-engine format_number
천 단위 구분 + 단위 접미사. (1200000, "원" -> "1,200,000원")
Thousands separators + unit suffix. (1200000, "won" -> "1,200,000won")
- valuenumber
- 표기할 수.Number to display.
- unitSuffixstring
- 뒤에 붙일 단위.Unit to append.
- localestring
- 로케일. (기본 "ko-KR")Locale. (default "ko-KR")
반환Returnsstring 천 단위 구분 기호와 단위를 붙인 문자열.A string with thousands separators and the unit.
짝Counterpart: vanilla-engine format_number_with_unit
큰 수를 짧게 줄여 반환. (1234 -> "1.2K", 5600000 -> "5.6M")
Returns a large number abbreviated. (1234 -> "1.2K", 5600000 -> "5.6M")
- valuenumber
- 표기할 수. (절대값이 1000 미만이면 줄이지 않고, 음수는 앞에 - 를 붙인다)Number to display. (not shortened if its absolute value is under 1000, negatives get a leading -)
- fractionDigitsnumber
- 소수 자릿수. (기본 1, 끝의 0 은 뺀다)Number of decimal places. (default 1, trailing zeros are removed)
반환Returnsstring K, M, B 를 붙여 줄인 문자열. (반올림해 1000 이 되면 다음 단위로 올린다, 999999 는 "1M")String shortened with K, M or B. (moves up to the next unit when rounding reaches 1000; 999999 is "1M")
짝Counterpart: vanilla-engine format_compact_number
값을 범위로 자르고 자릿수를 0 으로 채워 반환. (7세그먼트 카운터 표기 등)
- formatPaddedNumber(7, 3) -> "007", formatPaddedNumber(-5, 3) -> "-05"
Returns the value clamped to a range and zero-padded to the digit count. (7-segment counter display, etc.)
- formatPaddedNumber(7, 3) -> "007", formatPaddedNumber(-5, 3) -> "-05"
- valuenumber
- 표기할 수.Number to display.
- digitCountnumber
- 전체 자릿수. (음수면 - 기호도 한 자리로 센다)Total number of digits. (for negatives the - sign counts as one digit)
- minValuenumber
- 아래 끝. (기본 -Infinity)Lower bound. (default -Infinity)
- maxValuenumber
- 위 끝. (기본 Infinity)Upper bound. (default Infinity)
반환Returnsstring 범위로 자르고 앞을 0 으로 채운 문자열. (자릿수보다 길면 자르지 않는다)A string clamped to the range and padded with leading zeros. (not cut if longer than the digit count)
짝Counterpart: vanilla-engine format_padded_number
초를 "분:초" 표기로 반환. (75 -> "1:15")
Returns seconds as "min:sec". (75 -> "1:15")
- totalSecondsnumber
- 전체 초. (소수는 버리고 음수는 0 으로 친다)Total seconds. (fractions are dropped, negatives count as 0)
반환Returnsstring "분:초" 문자열. (초는 두 자리, 분은 60 을 넘어도 그대로)A "minutes:seconds" string. (seconds have two digits, minutes stay as is even past 60)
짝Counterpart: vanilla-engine format_minutes_seconds