caseforge 0.1.6 → 0.2.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/README.md CHANGED
@@ -20,13 +20,14 @@ npm install caseforge
20
20
  ```
21
21
 
22
22
  ```ts
23
- import { toCamelCase, toSnakeCase, toKebabCase, toPascalCase } from "caseforge";
23
+ import { toCamelCase, toSnakeCase, toKebabCase, toPascalCase, toUpperCase } from "caseforge";
24
24
 
25
25
  // String conversion
26
26
  toCamelCase("user_name"); // => "userName"
27
27
  toSnakeCase("userName"); // => "user_name"
28
28
  toKebabCase("userName"); // => "user-name"
29
29
  toPascalCase("user_name"); // => "UserName"
30
+ toUpperCase("userName"); // => "USER_NAME"
30
31
 
31
32
  // Object conversion with type inference
32
33
  const apiResponse = {
@@ -0,0 +1,21 @@
1
+ /**
2
+ * Converts a string to UPPER_SNAKE_CASE format at the type level.
3
+ * @example "userName" -> "USER_NAME"
4
+ */
5
+ type UpperCase<S extends string, First extends boolean = true> = S extends `${infer C}${infer R}` ? C extends "_" | "-" ? `_${UpperCase<R, false>}` : C extends Uppercase<C> ? First extends true ? `${Uppercase<C>}${UpperCase<R, false>}` : `_${Uppercase<C>}${UpperCase<R, false>}` : `${Uppercase<C>}${UpperCase<R, false>}` : Uppercase<S>;
6
+ /**
7
+ * Converts all object keys to UPPER_SNAKE_CASE format at the type level.
8
+ * @example { userName: "John Doe" } -> { USER_NAME: "John Doe" }
9
+ */
10
+ type UpperCaseKeys<T> = {
11
+ [K in keyof T as UpperCase<K & string>]: T[K] extends Array<infer U> ? U extends Record<string, unknown> ? Array<UpperCaseKeys<U>> : T[K] : T[K] extends Record<string, unknown> ? UpperCaseKeys<T[K]> : T[K];
12
+ };
13
+ /**
14
+ * Converts strings or object keys to UPPER_SNAKE_CASE format.
15
+ * @param input - A string or object to convert.
16
+ * @returns The UPPER_SNAKE_CASE string or object.
17
+ */
18
+ export declare function toUpperCase<T extends string>(input: T): UpperCase<T>;
19
+ export declare function toUpperCase<T extends Record<string, unknown>>(input: T): UpperCaseKeys<T>;
20
+ export declare function toUpperCase<T>(input: T): T;
21
+ export {};
package/dist/index.d.ts CHANGED
@@ -2,3 +2,4 @@ export { toCamelCase } from "./core/toCamelCase";
2
2
  export { toKebabCase } from "./core/toKebabCase";
3
3
  export { toPascalCase } from "./core/toPascalCase";
4
4
  export { toSnakeCase } from "./core/toSnakeCase";
5
+ export { toUpperCase } from "./core/toUpperCase";
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 L(x){return typeof x==="string"}function W(x){return Array.isArray(x)}function D(x){return typeof x==="object"&&x!==null&&!W(x)}function X(x){return x instanceof Date||x instanceof RegExp||typeof x==="function"}function H(x,z){let J={};for(let[F,Q]of Object.entries(x)){let U=z(F);if(X(Q))J[U]=Q;else if(W(Q))J[U]=Q.map((V)=>D(V)&&!W(V)?H(V,z):V);else if(D(Q))J[U]=H(Q,z);else J[U]=Q}return J}function Y(x){return x.replace(q.LEADING_UPPER,(z)=>z.toLowerCase()).replace(q.SEPARATOR_WITH_CHAR,(z,J)=>J.toUpperCase()).replace(q.EDGE_SEPARATORS,"")}function I(x){if(L(x))return Y(x);if(D(x))return H(x,Y);return x}function Z(x){return x.replace(q.UPPERCASE,(z)=>`-${z.toLowerCase()}`).replace(q.CONSECUTIVE_SEPARATORS,"-").replace(q.EDGE_SEPARATORS,"")}function M(x){if(L(x))return Z(x);if(D(x))return H(x,Z);return x}function $(x){return x.replace(q.SEPARATOR_WITH_CHAR,(z,J)=>J.toUpperCase()).replace(q.EDGE_SEPARATORS,"").replace(q.LEADING_LOWER,(z)=>z.toUpperCase())}function _(x){if(L(x))return $(x);if(D(x))return H(x,$);return x}function B(x){return x.replace(q.UPPERCASE,(z)=>`_${z.toLowerCase()}`).replace(q.CONSECUTIVE_SEPARATORS,"_").replace(q.EDGE_SEPARATORS,"")}function w(x){if(L(x))return B(x);if(D(x))return H(x,B);return x}export{w as toSnakeCase,_ as toPascalCase,M as toKebabCase,I 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};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};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "caseforge",
3
- "version": "0.1.6",
3
+ "version": "0.2.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",