deep-case-crafter 0.0.5 → 1.0.0
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/dist/transform/transform.d.ts +9 -0
- package/package.json +1 -1
- package/readme.md +21 -0
|
@@ -6,6 +6,15 @@ declare function transform<T, From extends StringCase, To extends StringCase>(da
|
|
|
6
6
|
sourceCase: From;
|
|
7
7
|
targetCase: To;
|
|
8
8
|
}): TransformRecursive<T, From, To>;
|
|
9
|
+
/**
|
|
10
|
+
* Transform data to a specified output type.
|
|
11
|
+
*
|
|
12
|
+
* Note: When using this overload, type safety is not enforced between the input, options, and output type.
|
|
13
|
+
* The 'sourceCase' option is intentionally omitted, as it is not used for type inference here.
|
|
14
|
+
*/
|
|
15
|
+
declare function transform<T, K>(data: T, options?: Omit<TransformOptions, 'sourceCase'> & {
|
|
16
|
+
depth?: number;
|
|
17
|
+
}): K;
|
|
9
18
|
declare function transform<T>(data: T, options?: TransformOptions & {
|
|
10
19
|
depth?: number;
|
|
11
20
|
}): unknown;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "deep-case-crafter",
|
|
3
|
-
"version": "0.0
|
|
3
|
+
"version": "1.0.0",
|
|
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",
|
package/readme.md
CHANGED
|
@@ -139,6 +139,27 @@ console.log(result); // Set { 'userId', 'firstName' }
|
|
|
139
139
|
|
|
140
140
|
---
|
|
141
141
|
|
|
142
|
+
## 🧑💻 Advanced: Explicit Output Type Overload
|
|
143
|
+
|
|
144
|
+
If you want to specify the output type explicitly (for example, when you know the exact shape you want), you can use the following overload:
|
|
145
|
+
|
|
146
|
+
```typescript
|
|
147
|
+
const result = transform<Input, Output>(obj, { targetCase: 'camel' });
|
|
148
|
+
const typedResult: Output = result; // TypeScript will enforce Output type here
|
|
149
|
+
```
|
|
150
|
+
|
|
151
|
+
**Note:**
|
|
152
|
+
- When using this overload, you cannot pass `sourceCase` in the options. If you do, TypeScript will show an error:
|
|
153
|
+
> Object literal may only specify known properties, and 'sourceCase' does not exist in type 'Omit<TransformOptions, "sourceCase"> & { depth?: number }'.
|
|
154
|
+
- This overload is useful when you want to take full control of the output type, but type safety between input, options, and output is not enforced by the library.
|
|
155
|
+
- If you want to use `sourceCase` and benefit from type inference, use the standard overload:
|
|
156
|
+
|
|
157
|
+
```typescript
|
|
158
|
+
const result = transform(obj, { targetCase: 'camel', sourceCase: 'snake' }); // Output type is inferred
|
|
159
|
+
```
|
|
160
|
+
|
|
161
|
+
---
|
|
162
|
+
|
|
142
163
|
## 🚨 Key Preservation Rules
|
|
143
164
|
|
|
144
165
|
- **Keys that start with special characters or numbers** are **not transformed**.
|