HomeAboutMeBlogGuest
© 2025 Sejin Cha. All rights reserved.
Built with Next.js, deployed on Vercel
💌
JJong’s Archive
/
🌞
JS
/
Intl

Intl

Status
Done
Tags
날짜
Dec 27, 2024 11:43 PM
: JavaScript의 국제화(Internationalization) API를 위한 전역 객체
: 다양한 언어 및 지역 설정에 따라 텍스트, 숫자, 날짜, 시간 등을 처리하고 포맷팅하는 기능 제공
 

주요 생성자 및 기능

notion image
 

사용예시

  1. Collator
    1. //sort메서드 const collator = new Intl.Collator('ko-KR'); console.log(['가', '다', '나'].sort(collator.compare)); // ["가", "나", "다"]
  1. NumberFormat
    1. //format메서드 => 숫자.toLocaleString()과 동일한듯 const numberFormatter = new Intl.NumberFormat('de-DE', { style: 'currency', currency: 'EUR' }); console.log(numberFormatter.format(1234567.89)); // "1.234.567,89 €"
  1. DateTimeFormat
    1. //format메서드 => Date.toString과 동일한듯 const dateFormatter = new Intl.DateTimeFormat('en-US', { dateStyle: 'full', timeStyle: 'long' }); console.log(dateFormatter.format(new Date())); // "Saturday, December 28, 2024 at 8:00:00 AM GMT+9"
  1. RelativetimeFormat
    1. //format메서드 const relativeFormatter = new Intl.RelativeTimeFormat('ko-KR', { numeric: 'auto' }); console.log(relativeFormatter.format(-1, 'day')); // "어제" console.log(relativeFormatter.format(2, 'day')); // "이틀 후"
  1. ListFormat
    1. const listFormatter = new Intl.ListFormat('en', { style: 'long', type: 'conjunction' }); console.log(listFormatter.format(['Apple', 'Banana', 'Cherry'])); // "Apple, Banana, and Cherry"