npm package: @lmwoo0327/case-tools
Description: [![npm version](https://img.shields.io/npm/v/@lmwoo0327/case-tools.svg?logo=npm&color=cb0000)](https://www.npmjs.com/package/@lmwoo0327/case-tools) [![license](https://img.shields.io/github/license/lmwoo0327/case-tools.svg?logo=github&color=blue)](LICENS
Latest version: 0.1.5


# @lmwoo0327/case-tools 🧰  

[![npm version](https://img.shields.io/npm/v/@lmwoo0327/case-tools.svg?logo=npm&color=cb0000)](https://www.npmjs.com/package/@lmwoo0327/case-tools)
[![license](https://img.shields.io/github/license/lmwoo0327/case-tools.svg?logo=github&color=blue)](LICENSE)
[![build](https://img.shields.io/github/actions/workflow/status/lmwoo0327/case-tools/ci.yml?label=build&logo=githubactions&logoColor=white)](https://github.com/lmwoo0327/case-tools/actions)

> 🪄 A lightweight TypeScript utility for converting between `snake_case` ↔ `camelCase`,  
> including deep object key mapping and seamless Axios integration.

---

## 🚀 Installation

```bash
npm install @lmwoo0327/case-tools
# or
yarn add @lmwoo0327/case-tools
````

---

## ✨ Features

* 🔁 Convert between `snake_case` and `camelCase`
* 🧩 Deep key transformation for nested objects, arrays, maps
* 🧠 Enum & constant object conversion (`USER_ID` → `userID`)
* 🌐 Axios integration for automatic case conversion
* ⚙️ Full TypeScript support — no extra types needed

---

## 📘 Basic Usage

### 🔸 String Conversion

```ts
import { toCamelCase, toSnakeCase } from '@lmwoo0327/case-tools'

toCamelCase('user_id')        // "userId"
toSnakeCase('userId')         // "user_id"
toCamelCase('__api_response') // "__apiResponse"
```

---

### 🔸 Object Key Conversion

```ts
import { camelKeys, snakeKeys } from '@lmwoo0327/case-tools'

const snake = {
  user_id: 1,
  profile_info: {
    created_at: '2025-10-13',
  },
}

const camel = camelKeys(snake)
// → { userId: 1, profileInfo: { createdAt: '2025-10-13' } }

const backToSnake = snakeKeys(camel)
// → { user_id: 1, profile_info: { created_at: '2025-10-13' } }
```

---

### 🔸 Enum / Constant Conversion

```ts
import { enumCamel, enumSnake } from '@lmwoo0327/case-tools'

const API_ENUM = {
  USER_ID: 'uid',
  CREATED_AT: 'created_at',
}

const camelEnum = enumCamel(API_ENUM, { acronyms: ['ID'] })
// → { userID: 'uid', createdAt: 'created_at' }

const backToSnake = enumSnake(camelEnum)
// → { user_id: 'uid', created_at: 'created_at' }
```

> 🧠 `acronyms` 옵션은 `ID`, `URL`, `API` 같은 약어를 대문자로 유지합니다.

---

## 🌐 Axios Integration

자동으로 요청은 `camel → snake`, 응답은 `snake → camel` 변환합니다.

```ts
import axios from 'axios'
import { createAxiosCase } from '@lmwoo0327/case-tools/axios'

const api = createAxiosCase(axios.create({ baseURL: '/api' }), {
  acronyms: ['ID', 'URL'],  // 약어 유지
})

// Example
const res = await api.post('/users', {
  userName: 'John',
  profileImageURL: 'https://example.com/avatar.png',
})
```

* 요청 전송: `{ user_name, profile_image_url }`
* 응답 수신: `{ userId, profileImageURL }`

---

## 🧠 TypeScript Friendly

```ts
import { camelKeys } from '@lmwoo0327/case-tools'

const data = camelKeys({ user_id: 1, created_at: '2025-10-13' })
// → { userId: number; createdAt: string }
```

> 💡 완전한 타입 추론 지원 — 별도의 `@types` 패키지가 필요 없습니다.

---

## ⚙️ API Overview

| Function                        | Description                      |
| ------------------------------- | -------------------------------- |
| `toCamelCase(str)`              | 문자열을 `camelCase`로 변환             |
| `toSnakeCase(str)`              | 문자열을 `snake_case`로 변환            |
| `camelKeys(obj)`                | 객체의 모든 키를 재귀적으로 `camelCase`로 변환  |
| `snakeKeys(obj)`                | 객체의 모든 키를 재귀적으로 `snake_case`로 변환 |
| `enumCamel(enum)`               | Enum / 상수 객체를 `camelCase`로 변환    |
| `enumSnake(enum)`               | Enum / 상수 객체를 `snake_case`로 변환   |
| `createAxiosCase(client, opts)` | Axios 요청/응답 자동 변환기 생성            |

---

## 🧪 Local Development

개발 중에는 다른 프로젝트에 링크해서 실시간 테스트 가능합니다.

```bash
# case-tools 폴더에서
npm link

# 다른 프로젝트에서
npm link @lmwoo0327/case-tools
```

빌드 후(`npm run build`) 즉시 반영됩니다.

---

## 📦 Example Project Structure

```
my-app/
 ├─ src/
 │   ├─ main.ts
 │   └─ ...
 └─ node_modules/
     └─ @lmwoo0327/case-tools/
```

---

## 📄 License

MIT © 2025 [lmwoo0327](https://github.com/lmwoo0327)

---

> 🧩 **Tip:**
> 이 라이브러리는 백엔드가 `snake_case`, 프론트엔드는 `camelCase`를 쓰는
> API 환경에서 가장 깔끔하고 안정적인 데이터 변환 계층을 제공합니다.