Skip to content
← Back to rules

unicorn/prefer-code-point 철이 쌓인

An auto-fix is available for this rule.

작동 방식

String.prototype.charCodeAt보다 String.prototype.codePointAt 사용을 선호합니다.
String.fromCharCode보다 String.fromCodePoint 사용을 선호합니다.

왜 문제가 될까요?

String#codePointAt()String.fromCodePoint()는 유니코드를 더 잘 지원합니다.

String.fromCodePoint()String.fromCharCode()의 차이점

예시

이 규칙에 적합하지 않은 코드 예시:

javascript
"🦄".charCodeAt(0);
String.fromCharCode(0x1f984);

이 규칙에 적합한 코드 예시:

javascript
"🦄".codePointAt(0);
String.fromCodePoint(0x1f984);

사용 방법

설정 파일 또는 명령줄 인터페이스를 통해 이 규칙을 활성화하려면 다음을 사용할 수 있습니다:

json
{
  "rules": {
    "unicorn/prefer-code-point": "error"
  }
}
bash
oxlint --deny unicorn/prefer-code-point

참고 자료