deep-case-crafter 0.0.4 → 0.0.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +24 -1
- package/readme.md +98 -39
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "deep-case-crafter",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.5",
|
|
4
4
|
"description": "Transforms deeply nested object, array, Map, and Set keys between common case formats while preserving TypeScript type safety",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"module": "dist/index.esm.js",
|
|
@@ -23,6 +23,29 @@
|
|
|
23
23
|
"author": "gyrgy",
|
|
24
24
|
"license": "MIT",
|
|
25
25
|
"private": false,
|
|
26
|
+
"keywords": [
|
|
27
|
+
"camelcase",
|
|
28
|
+
"pascalcase",
|
|
29
|
+
"snakecase",
|
|
30
|
+
"kebabcase",
|
|
31
|
+
"case-conversion",
|
|
32
|
+
"deep-conversion",
|
|
33
|
+
"object-transform",
|
|
34
|
+
"key-transform",
|
|
35
|
+
"typescript",
|
|
36
|
+
"typescript-utils",
|
|
37
|
+
"deep-map",
|
|
38
|
+
"map-keys",
|
|
39
|
+
"case-utils",
|
|
40
|
+
"case-changer",
|
|
41
|
+
"json-utils",
|
|
42
|
+
"case-format",
|
|
43
|
+
"deep-case",
|
|
44
|
+
"convert-case",
|
|
45
|
+
"string-utils",
|
|
46
|
+
"key-mapper",
|
|
47
|
+
"key-converter"
|
|
48
|
+
],
|
|
26
49
|
"scripts": {
|
|
27
50
|
"build": "rollup -c",
|
|
28
51
|
"prepare": "husky",
|
package/readme.md
CHANGED
|
@@ -1,30 +1,67 @@
|
|
|
1
1
|
# DeepCaseCrafter
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
🚀 **DeepCaseCrafter** is a TypeScript utility that **transforms deeply nested object keys** into different case formats while maintaining **type safety**. It supports **objects, arrays, Maps, and Sets** and allows **custom recursion depth**.
|
|
4
|
+
|
|
5
|
+
[](https://www.npmjs.com/package/deep-case-crafter)
|
|
6
|
+
[](https://github.com/your-repo/deep-case-crafter/blob/main/LICENSE)
|
|
7
|
+
[](https://www.typescriptlang.org/)
|
|
4
8
|
|
|
5
9
|
## Features
|
|
6
10
|
|
|
7
|
-
-
|
|
8
|
-
-
|
|
9
|
-
- ✅
|
|
10
|
-
- 🔍
|
|
11
|
-
- ⚡
|
|
12
|
-
-
|
|
13
|
-
- 📦 Lightweight bundle size (~27.33 KB).
|
|
11
|
+
- 🔄 **Automatically converts keys** to `camelCase`, `PascalCase`, `snake_case`, and `kebab-case`.
|
|
12
|
+
- 🌍 **Works with deeply nested structures**, including objects, arrays, Maps, and Sets.
|
|
13
|
+
- ✅ **Maintains TypeScript type inference** for better auto-completion.
|
|
14
|
+
- 🔍 **Preserves special keys** (`__`, `--`, leading numbers, special characters).
|
|
15
|
+
- ⚡ **Performance-optimized** with minimal overhead.
|
|
16
|
+
- 🎛 **Configurable recursion depth** (default: `3`).
|
|
14
17
|
|
|
15
|
-
## Installation
|
|
18
|
+
## 📦 Installation
|
|
16
19
|
|
|
17
20
|
```bash
|
|
18
21
|
npm install deep-case-crafter
|
|
19
22
|
```
|
|
20
23
|
|
|
21
|
-
|
|
24
|
+
---
|
|
25
|
+
|
|
26
|
+
## 🚀 Quick Start
|
|
22
27
|
|
|
23
|
-
###
|
|
28
|
+
### 1️⃣ **Basic Usage – Just Call `transform`**
|
|
24
29
|
|
|
25
30
|
```typescript
|
|
26
31
|
import transform from 'deep-case-crafter';
|
|
27
32
|
|
|
33
|
+
const input = { user_id: 1, first_name: 'John' };
|
|
34
|
+
const result = transform(input);
|
|
35
|
+
|
|
36
|
+
console.log(result);
|
|
37
|
+
// Output: { userId: 1, firstName: 'John' }
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
_(Automatically converts from `snake_case` to `camelCase`)_
|
|
41
|
+
|
|
42
|
+
---
|
|
43
|
+
|
|
44
|
+
### 2️⃣ **Specify the `targetCase`**
|
|
45
|
+
|
|
46
|
+
```typescript
|
|
47
|
+
const input = { user_id: 1, first_name: 'John' };
|
|
48
|
+
|
|
49
|
+
const pascalCaseResult = transform(input, { targetCase: 'pascal' });
|
|
50
|
+
console.log(pascalCaseResult);
|
|
51
|
+
// Output: { UserId: 1, FirstName: 'John' }
|
|
52
|
+
|
|
53
|
+
const kebabCaseResult = transform(input, { targetCase: 'kebab' });
|
|
54
|
+
console.log(kebabCaseResult);
|
|
55
|
+
// Output: { "user-id": 1, "first-name": "John" }
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
---
|
|
59
|
+
|
|
60
|
+
### 3️⃣ **Explicitly Define `sourceCase` for TypeScript Benefits**
|
|
61
|
+
|
|
62
|
+
_TypeScript automatically infers key changes when `sourceCase` is set._
|
|
63
|
+
|
|
64
|
+
```typescript
|
|
28
65
|
const input = { user_id: 1, first_name: 'John' };
|
|
29
66
|
const result = transform(input, { targetCase: 'camel', sourceCase: 'snake' });
|
|
30
67
|
|
|
@@ -32,7 +69,9 @@ console.log(result);
|
|
|
32
69
|
// Output: { userId: 1, firstName: 'John' }
|
|
33
70
|
```
|
|
34
71
|
|
|
35
|
-
|
|
72
|
+
---
|
|
73
|
+
|
|
74
|
+
### 4️⃣ **Transform Deeply Nested Structures**
|
|
36
75
|
|
|
37
76
|
```typescript
|
|
38
77
|
const nestedInput = {
|
|
@@ -40,8 +79,12 @@ const nestedInput = {
|
|
|
40
79
|
posts: [{ post_id: 1, post_title: 'Hello' }],
|
|
41
80
|
};
|
|
42
81
|
|
|
43
|
-
const transformed = transform(nestedInput, {
|
|
82
|
+
const transformed = transform(nestedInput, {
|
|
83
|
+
targetCase: 'camel',
|
|
84
|
+
sourceCase: 'snake',
|
|
85
|
+
});
|
|
44
86
|
|
|
87
|
+
console.log(transformed);
|
|
45
88
|
// Output:
|
|
46
89
|
// {
|
|
47
90
|
// userInfo: { firstName: 'John', lastName: 'Doe' },
|
|
@@ -49,7 +92,9 @@ const transformed = transform(nestedInput, { targetCase: 'camel' });
|
|
|
49
92
|
// }
|
|
50
93
|
```
|
|
51
94
|
|
|
52
|
-
|
|
95
|
+
---
|
|
96
|
+
|
|
97
|
+
### 5️⃣ **Transforming a `Map`**
|
|
53
98
|
|
|
54
99
|
```typescript
|
|
55
100
|
const mapInput = new Map([
|
|
@@ -66,7 +111,9 @@ console.log(result.get('userId')); // 1
|
|
|
66
111
|
console.log(result.get('firstName')); // 'John'
|
|
67
112
|
```
|
|
68
113
|
|
|
69
|
-
|
|
114
|
+
---
|
|
115
|
+
|
|
116
|
+
### 6️⃣ **Transforming a `Set`**
|
|
70
117
|
|
|
71
118
|
```typescript
|
|
72
119
|
const setInput = new Set(['user_id', 'first_name']);
|
|
@@ -78,44 +125,56 @@ const result = transform(setInput, {
|
|
|
78
125
|
console.log(result); // Set { 'userId', 'firstName' }
|
|
79
126
|
```
|
|
80
127
|
|
|
81
|
-
|
|
128
|
+
---
|
|
129
|
+
|
|
130
|
+
## 📖 API
|
|
82
131
|
|
|
83
132
|
### `transform(data, options)`
|
|
84
133
|
|
|
85
134
|
- **data**: The data structure to transform (`object`, `array`, `Map`, or `Set`).
|
|
86
135
|
- **options**:
|
|
87
|
-
- `targetCase` (optional): `'camel' | 'snake' | 'pascal' | 'kebab'`
|
|
88
|
-
- `sourceCase` (optional):
|
|
89
|
-
- `depth` (optional):
|
|
136
|
+
- `targetCase` (optional): `'camel' | 'snake' | 'pascal' | 'kebab'` (default: `'camel'`)
|
|
137
|
+
- `sourceCase` (optional): **Required for TypeScript inference** (`'snake' | 'camel' | 'pascal' | 'kebab'`).
|
|
138
|
+
- `depth` (optional): **Recursion depth** (default: `3`, use `Infinity` for full recursion).
|
|
139
|
+
|
|
140
|
+
---
|
|
141
|
+
|
|
142
|
+
## 🚨 Key Preservation Rules
|
|
90
143
|
|
|
91
|
-
|
|
144
|
+
- **Keys that start with special characters or numbers** are **not transformed**.
|
|
145
|
+
- **Keys with `__` or `--` remain unchanged**.
|
|
146
|
+
- **Numbers at the end of keys** are preserved.
|
|
92
147
|
|
|
93
|
-
|
|
148
|
+
---
|
|
94
149
|
|
|
95
|
-
|
|
96
|
-
- They contain `__` or `--`.
|
|
97
|
-
- Numbers at the end are allowed.
|
|
150
|
+
## ⚡ Performance & Benchmarks
|
|
98
151
|
|
|
99
|
-
|
|
152
|
+
DeepCaseCrafter is optimized for speed and efficiency:
|
|
100
153
|
|
|
101
|
-
|
|
102
|
-
|
|
154
|
+
```plaintext
|
|
155
|
+
Transform Deep Object (Depth 5, Width 10)
|
|
156
|
+
x 361,538 ops/sec ±0.12% (91 runs sampled)
|
|
157
|
+
```
|
|
103
158
|
|
|
104
|
-
|
|
159
|
+
---
|
|
105
160
|
|
|
106
|
-
|
|
107
|
-
- **Custom Depth**: Set `depth` to control recursion. Use `Infinity` for full recursion.
|
|
108
|
-
- **Lightweight**: Optimized for performance with minimal package size.
|
|
109
|
-
- **Benchmarks**: Transform Deep Object (Depth 5, Width 10) x 361,538 ops/sec ±0.12% (91 runs sampled)
|
|
110
|
-
Fastest is Transform Deep Object (Depth 5, Width 10)
|
|
161
|
+
## 💡 Contributing
|
|
111
162
|
|
|
112
|
-
|
|
163
|
+
1. **Fork** the repository.
|
|
164
|
+
2. **Create a new branch** (`feature/my-feature`).
|
|
165
|
+
3. **Commit your changes** (`git commit -m "Add new feature"`).
|
|
166
|
+
4. **Submit a pull request** 🚀.
|
|
113
167
|
|
|
114
|
-
|
|
115
|
-
2. Create a new branch.
|
|
116
|
-
3. Commit your changes.
|
|
117
|
-
4. Submit a pull request.
|
|
168
|
+
---
|
|
118
169
|
|
|
119
|
-
## License
|
|
170
|
+
## 📜 License
|
|
120
171
|
|
|
121
172
|
MIT
|
|
173
|
+
|
|
174
|
+
---
|
|
175
|
+
|
|
176
|
+
## 🔗 Links
|
|
177
|
+
|
|
178
|
+
- [NPM Package](https://www.npmjs.com/package/deep-case-crafter)
|
|
179
|
+
- [GitHub Repository](https://github.com/your-repo/deep-case-crafter)
|
|
180
|
+
- [TypeScript Docs](https://www.typescriptlang.org/)
|