---
title: 'Naming conventions'
description: How NAPI-RS converts Rust snake_case identifiers to JavaScript camelCase.
---

# Naming conventions

## `snake_case` to `camelCase`

The code styles are very different between Rust and JavaScript. The Rust community prefers the `snake_case` style while the JavaScript community prefers the `camelCase` style. **NAPI-RS** will change the case of the Rust code to the `camelCase` style automatically.

**lib.rs**

```rust
#[napi]
pub fn a_function(a_arg: u32) -> u32 {
  a_arg + 1
}
```

⬇️ ⬇️ ⬇️ ⬇️ ⬇️ ⬇️ ⬇️ ⬇️ ⬇️

**index.d.ts**

```ts
export function aFunction(aArg: number): number
```

## `js_name`

You can use the `js_name` attribute in `#[napi]` to rename the JavaScript function.

**lib.rs**

```rust {1}
#[napi(js_name = "coolFunction")]
pub fn a_function(a_arg: u32) -> u32 {
  a_arg + 1
}
```

⬇️ ⬇️ ⬇️ ⬇️ ⬇️ ⬇️ ⬇️ ⬇️ ⬇️

**index.d.ts**

```ts
export function coolFunction(aArg: number): number
```

The JavaScript function name will be `coolFunction`, both in the generated TypeScript definition and in the JavaScript runtime:

**test.mjs**

```js {1}
import { coolFunction } from './index.js'

console.log(coolFunction(1)) // 2
```
