# prefer-code-point

Prefer Unicode code-point operations over UTF-16 code-unit operations

UTF-16 code-unit operations split characters outside the Basic Multilingual Plane into surrogate pairs.
Instead, you SHOULD use `codePointAt` and `String.fromCodePoint` when processing Unicode characters.

- Category: style
- Level: warning
- Fix: suggestion
- Scope: module

## Reported

```ds title="main.ds"
function inspectFirstCharacter(text: string): void {
    text.charCodeAt(0);
}
```

## Accepted

```ds title="main.ds"
function inspectFirstCharacter(text: string): void {
    text.codePointAt(0);
}
```

## Prior art

- [eslint-plugin-unicorn · prefer-code-point](https://github.com/sindresorhus/eslint-plugin-unicorn/blob/main/docs/rules/prefer-code-point.md)

[language/linter/src/rules/style/prefer_code_point.rs:8](https://github.com/destack-sh/destack/blob/main/language/linter/src/rules/style/prefer_code_point.rs#L8)
