caseforge 0.2.1 → 0.3.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/LICENSE CHANGED
@@ -1,6 +1,6 @@
1
1
  MIT License
2
2
 
3
- Copyright (c) 2025 Chikada Hiroki
3
+ Copyright (c) 2026 Chikada Hiroki
4
4
 
5
5
  Permission is hereby granted, free of charge, to any person obtaining a copy
6
6
  of this software and associated documentation files (the "Software"), to deal
package/README.md CHANGED
@@ -9,7 +9,8 @@
9
9
 
10
10
  - ðŸŽŊ Type-safe conversions with full TypeScript support
11
11
  - ðŸŠķ Zero dependencies
12
- - 🔄 Supports camelCase, snake_case, kebab-case, and PascalCase
12
+ - 🔄 Supports camelCase, snake_case, kebab-case, PascalCase, and UPPER_CASE
13
+ - 🔍 Case format detection functions
13
14
  - ðŸŒģ Deep object and array transformation
14
15
  - ðŸ“Ķ Works with Bun, Node.js, and browsers
15
16
 
@@ -20,7 +21,18 @@ npm install caseforge
20
21
  ```
21
22
 
22
23
  ```ts
23
- import { toCamelCase, toSnakeCase, toKebabCase, toPascalCase, toUpperCase } from "caseforge";
24
+ import {
25
+ toCamelCase,
26
+ toSnakeCase,
27
+ toKebabCase,
28
+ toPascalCase,
29
+ toUpperCase,
30
+ isCamelCase,
31
+ isSnakeCase,
32
+ isKebabCase,
33
+ isPascalCase,
34
+ isUpperCase
35
+ } from "caseforge";
24
36
 
25
37
  // String conversion
26
38
  toCamelCase("user_name"); // => "userName"
@@ -29,6 +41,13 @@ toKebabCase("userName"); // => "user-name"
29
41
  toPascalCase("user_name"); // => "UserName"
30
42
  toUpperCase("userName"); // => "USER_NAME"
31
43
 
44
+ // Case format detection
45
+ isCamelCase("userName"); // => true
46
+ isSnakeCase("user_name"); // => true
47
+ isKebabCase("user-name"); // => true
48
+ isPascalCase("UserName"); // => true
49
+ isUpperCase("USER_NAME"); // => true
50
+
32
51
  // Object conversion with type inference
33
52
  const apiResponse = {
34
53
  user_id: 123,
@@ -41,10 +60,34 @@ const apiResponse = {
41
60
  const result = toCamelCase(apiResponse);
42
61
  // result.userId (typed!)
43
62
  // result.userName (typed!)
44
- // result.userSettings.notificationEnabled (typed!)## API
63
+ // result.userSettings.notificationEnabled (typed!)
45
64
 
65
+ // Detect API response format and convert accordingly
66
+ const sampleKey = Object.keys(apiResponse)[0];
67
+ if (isSnakeCase(sampleKey)) {
68
+ const converted = toCamelCase(apiResponse);
69
+ // Use converted data
70
+ }
46
71
  ```
47
72
 
73
+ ## API
74
+
75
+ ### Conversion Functions
76
+
77
+ - `toCamelCase(input)` - Converts to camelCase
78
+ - `toSnakeCase(input)` - Converts to snake_case
79
+ - `toKebabCase(input)` - Converts to kebab-case
80
+ - `toPascalCase(input)` - Converts to PascalCase
81
+ - `toUpperCase(input)` - Converts to UPPER_SNAKE_CASE
82
+
83
+ ### Detection Functions
84
+
85
+ - `isCamelCase(value)` - Checks if a string is in camelCase format
86
+ - `isSnakeCase(value)` - Checks if a string is in snake_case format
87
+ - `isKebabCase(value)` - Checks if a string is in kebab-case format
88
+ - `isPascalCase(value)` - Checks if a string is in PascalCase format
89
+ - `isUpperCase(value)` - Checks if a string is in UPPER_SNAKE_CASE format
90
+
48
91
  ## License
49
92
 
50
93
  MIT ÂĐ Chikada Hiroki
@@ -7,7 +7,7 @@ type CamelCase<S extends string> = S extends `${infer A}_${infer B}` ? `${Lowerc
7
7
  * Converts all object keys to camelCase format at the type level.
8
8
  * @example { user_name: "John Doe" } -> { userName: "John Doe" }
9
9
  */
10
- export type CamelCaseKeys<T> = {
10
+ type CamelCaseKeys<T> = {
11
11
  [K in keyof T as CamelCase<K & string>]: T[K] extends readonly (infer U)[] ? U extends object ? readonly CamelCaseKeys<U>[] : T[K] : T[K] extends object ? CamelCaseKeys<T[K]> : T[K];
12
12
  };
13
13
  /**
@@ -7,7 +7,7 @@ type KebabCase<S extends string, First extends boolean = true> = S extends `${in
7
7
  * Converts all object keys to kebab-case format at the type level.
8
8
  * @example { userName: "John Doe" } -> { "user-name": "John Doe" }
9
9
  */
10
- export type KebabCaseKeys<T> = {
10
+ type KebabCaseKeys<T> = {
11
11
  [K in keyof T as KebabCase<K & string>]: T[K] extends readonly (infer U)[] ? U extends object ? readonly KebabCaseKeys<U>[] : T[K] : T[K] extends object ? KebabCaseKeys<T[K]> : T[K];
12
12
  };
13
13
  /**
package/dist/index.d.ts CHANGED
@@ -3,3 +3,4 @@ export { toKebabCase } from "./core/toKebabCase";
3
3
  export { toPascalCase } from "./core/toPascalCase";
4
4
  export { toSnakeCase } from "./core/toSnakeCase";
5
5
  export { toUpperCase } from "./core/toUpperCase";
6
+ export { isCamelCase, isKebabCase, isPascalCase, isSnakeCase, isUpperCase, } from "./utils/caseGuards";
package/dist/index.js CHANGED
@@ -1 +1 @@
1
- var q={LEADING_UPPER:/^[A-Z]/,UPPERCASE:/[A-Z]/g,LEADING_LOWER:/^[a-z]/,SEPARATOR_WITH_CHAR:/[_-]+(.)/g,EDGE_SEPARATORS:/^[_-]+|[_-]+$/g,CONSECUTIVE_SEPARATORS:/[_-]+/g};function J(x){return typeof x==="string"}function X(x){return Array.isArray(x)}function D(x){return typeof x==="object"&&x!==null&&!X(x)}function Y(x){return x instanceof Date||x instanceof RegExp||typeof x==="function"}function H(x,z){let L={};for(let[M,Q]of Object.entries(x)){let V=z(M);if(Y(Q))L[V]=Q;else if(X(Q))L[V]=Q.map((W)=>D(W)&&!X(W)?H(W,z):W);else if(D(Q))L[V]=H(Q,z);else L[V]=Q}return L}function Z(x){return x.replace(q.LEADING_UPPER,(z)=>z.toLowerCase()).replace(q.SEPARATOR_WITH_CHAR,(z,L)=>L.toUpperCase()).replace(q.EDGE_SEPARATORS,"")}function U(x){if(J(x))return Z(x);if(D(x))return H(x,Z);return x}function $(x){return x.replace(q.UPPERCASE,(z)=>`-${z.toLowerCase()}`).replace(q.CONSECUTIVE_SEPARATORS,"-").replace(q.EDGE_SEPARATORS,"")}function w(x){if(J(x))return $(x);if(D(x))return H(x,$);return x}function B(x){return x.replace(q.SEPARATOR_WITH_CHAR,(z,L)=>L.toUpperCase()).replace(q.EDGE_SEPARATORS,"").replace(q.LEADING_LOWER,(z)=>z.toUpperCase())}function _(x){if(J(x))return B(x);if(D(x))return H(x,B);return x}function F(x){return x.replace(q.UPPERCASE,(z)=>`_${z.toLowerCase()}`).replace(q.CONSECUTIVE_SEPARATORS,"_").replace(q.EDGE_SEPARATORS,"")}function d(x){if(J(x))return F(x);if(D(x))return H(x,F);return x}function I(x){return x.replace(q.UPPERCASE,(z)=>`_${z.toLowerCase()}`).replace(q.CONSECUTIVE_SEPARATORS,"_").replace(q.EDGE_SEPARATORS,"").toUpperCase()}function G(x){if(J(x))return I(x);if(D(x))return H(x,I);return x}export{G as toUpperCase,d as toSnakeCase,_ as toPascalCase,w as toKebabCase,U as toCamelCase};
1
+ var q={LEADING_UPPER:/^[A-Z]/,UPPERCASE:/[A-Z]/g,LEADING_LOWER:/^[a-z]/,SEPARATOR_WITH_CHAR:/[_-]+(.)/g,EDGE_SEPARATORS:/^[_-]+|[_-]+$/g,CONSECUTIVE_SEPARATORS:/[_-]+/g,CAMEL_CASE:/^[a-z][a-zA-Z0-9]*$/,KEBAB_CASE:/^[a-z][a-z0-9-]*$/,PASCAL_CASE:/^[A-Z][a-zA-Z0-9]*$/,SNAKE_CASE:/^[a-z][a-z0-9_]*$/,UPPER_SNAKE_CASE:/^[A-Z][A-Z0-9_]*$/};function z(x){return typeof x==="string"}function X(x){return Array.isArray(x)}function H(x){return typeof x==="object"&&x!==null&&!X(x)}function Y(x){return x instanceof Date||x instanceof RegExp||typeof x==="function"}function J(x,D){let L={};for(let[M,Q]of Object.entries(x)){let V=D(M);if(Y(Q))L[V]=Q;else if(X(Q))L[V]=Q.map((W)=>H(W)&&!X(W)?J(W,D):W);else if(H(Q))L[V]=J(Q,D);else L[V]=Q}return L}function Z(x){return x.replace(q.LEADING_UPPER,(D)=>D.toLowerCase()).replace(q.SEPARATOR_WITH_CHAR,(D,L)=>L.toUpperCase()).replace(q.EDGE_SEPARATORS,"")}function U(x){if(z(x))return Z(x);if(H(x))return J(x,Z);return x}function $(x){return x.replace(q.UPPERCASE,(D)=>`-${D.toLowerCase()}`).replace(q.CONSECUTIVE_SEPARATORS,"-").replace(q.EDGE_SEPARATORS,"")}function w(x){if(z(x))return $(x);if(H(x))return J(x,$);return x}function B(x){return x.replace(q.SEPARATOR_WITH_CHAR,(D,L)=>L.toUpperCase()).replace(q.EDGE_SEPARATORS,"").replace(q.LEADING_LOWER,(D)=>D.toUpperCase())}function d(x){if(z(x))return B(x);if(H(x))return J(x,B);return x}function F(x){return x.replace(q.UPPERCASE,(D)=>`_${D.toLowerCase()}`).replace(q.CONSECUTIVE_SEPARATORS,"_").replace(q.EDGE_SEPARATORS,"")}function G(x){if(z(x))return F(x);if(H(x))return J(x,F);return x}function I(x){return x.replace(q.UPPERCASE,(D)=>`_${D.toLowerCase()}`).replace(q.CONSECUTIVE_SEPARATORS,"_").replace(q.EDGE_SEPARATORS,"").toUpperCase()}function _(x){if(z(x))return I(x);if(H(x))return J(x,I);return x}function C(x){if(!z(x))return!1;return q.CAMEL_CASE.test(x)&&!x.includes("_")&&!x.includes("-")}function K(x){if(!z(x))return!1;return q.SNAKE_CASE.test(x)&&!x.includes("-")&&!q.UPPERCASE.test(x)}function O(x){if(!z(x))return!1;return q.KEBAB_CASE.test(x)&&!x.includes("_")&&!q.UPPERCASE.test(x)}function k(x){if(!z(x))return!1;return q.PASCAL_CASE.test(x)&&!x.includes("_")&&!x.includes("-")}function N(x){if(!z(x))return!1;return q.UPPER_SNAKE_CASE.test(x)&&!x.includes("-")}export{_ as toUpperCase,G as toSnakeCase,d as toPascalCase,w as toKebabCase,U as toCamelCase,N as isUpperCase,K as isSnakeCase,k as isPascalCase,O as isKebabCase,C as isCamelCase};
@@ -0,0 +1,30 @@
1
+ /**
2
+ * Checks if a string is in camelCase format.
3
+ * @param value - The value to check.
4
+ * @returns `true` if the value is in camelCase format, `false` otherwise.
5
+ */
6
+ export declare function isCamelCase(value: unknown): boolean;
7
+ /**
8
+ * Checks if a string is in snake_case format.
9
+ * @param value - The value to check.
10
+ * @returns `true` if the value is in snake_case format, `false` otherwise.
11
+ */
12
+ export declare function isSnakeCase(value: unknown): boolean;
13
+ /**
14
+ * Checks if a string is in kebab-case format.
15
+ * @param value - The value to check.
16
+ * @returns `true` if the value is in kebab-case format, `false` otherwise.
17
+ */
18
+ export declare function isKebabCase(value: unknown): boolean;
19
+ /**
20
+ * Checks if a string is in PascalCase format.
21
+ * @param value - The value to check.
22
+ * @returns `true` if the value is in PascalCase format, `false` otherwise.
23
+ */
24
+ export declare function isPascalCase(value: unknown): boolean;
25
+ /**
26
+ * Checks if a string is in UPPER_SNAKE_CASE format.
27
+ * @param value - The value to check.
28
+ * @returns `true` if the value is in UPPER_SNAKE_CASE format, `false` otherwise.
29
+ */
30
+ export declare function isUpperCase(value: unknown): boolean;
@@ -14,4 +14,14 @@ export declare const PATTERNS: {
14
14
  readonly EDGE_SEPARATORS: RegExp;
15
15
  /** Matches consecutive separators */
16
16
  readonly CONSECUTIVE_SEPARATORS: RegExp;
17
+ /** Matches a complete camelCase string */
18
+ readonly CAMEL_CASE: RegExp;
19
+ /** Matches a complete kebab-case string */
20
+ readonly KEBAB_CASE: RegExp;
21
+ /** Matches a complete PascalCase string */
22
+ readonly PASCAL_CASE: RegExp;
23
+ /** Matches a complete snake_case string */
24
+ readonly SNAKE_CASE: RegExp;
25
+ /** Matches a complete UPPER_SNAKE_CASE string */
26
+ readonly UPPER_SNAKE_CASE: RegExp;
17
27
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "caseforge",
3
- "version": "0.2.1",
3
+ "version": "0.3.0",
4
4
  "description": "caseforge - Effortlessly convert between snake_case, camelCase, and more in TypeScript. Zero dependencies, type-safe, and easy to use for any project.",
5
5
  "main": "./dist/index.js",
6
6
  "types": "./dist/index.d.ts",
@@ -52,9 +52,7 @@
52
52
  "license": "MIT",
53
53
  "devDependencies": {
54
54
  "@biomejs/biome": "2.3.6",
55
+ "@types/bun": "^1.3.2",
55
56
  "typescript": "^5.9.3"
56
- },
57
- "dependencies": {
58
- "@types/bun": "^1.3.2"
59
57
  }
60
58
  }