deep-case-crafter 1.0.0 → 2.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/LICENSE +21 -0
- package/dist/index.d.cts +231 -0
- package/dist/index.d.mts +231 -0
- package/dist/index.d.ts +230 -4
- package/dist/index.js +1 -1
- package/dist/index.mjs +1 -0
- package/package.json +33 -23
- package/readme.md +63 -46
- package/dist/constants/formatterMap.d.ts +0 -21
- package/dist/constants/regex.d.ts +0 -9
- package/dist/dataTransformers/primitiveTransformer.d.ts +0 -7
- package/dist/dataTransformers/transformArray.d.ts +0 -19
- package/dist/dataTransformers/transformMap.d.ts +0 -18
- package/dist/dataTransformers/transformObject.d.ts +0 -21
- package/dist/dataTransformers/transformSingleWord.d.ts +0 -8
- package/dist/index.esm.js +0 -1
- package/dist/transform/internalTransform.d.ts +0 -15
- package/dist/transform/transform.d.ts +0 -21
- package/dist/transform/transformCase.d.ts +0 -23
- package/dist/types/helperTypes.d.ts +0 -3
- package/dist/types/stringCaseTypes.d.ts +0 -4
- package/dist/types/transformOptionTypes.d.ts +0 -41
- package/dist/types/transformTypes.d.ts +0 -279
- package/dist/utils/caseDetectors/isCamelCase.d.ts +0 -13
- package/dist/utils/caseDetectors/isKebabCase.d.ts +0 -13
- package/dist/utils/caseDetectors/isPascalCase.d.ts +0 -14
- package/dist/utils/caseDetectors/isSnakeCase.d.ts +0 -14
- package/dist/utils/detectSingleWord.d.ts +0 -37
- package/dist/utils/detectStringCase.d.ts +0 -17
- package/dist/utils/prepareStringTransformation.d.ts +0 -20
- package/dist/utils/stringFormatters/camelToKebabCase.d.ts +0 -14
- package/dist/utils/stringFormatters/camelToPascalCase.d.ts +0 -14
- package/dist/utils/stringFormatters/camelToSnakeCase.d.ts +0 -14
- package/dist/utils/stringFormatters/kebabToCamelCase.d.ts +0 -14
- package/dist/utils/stringFormatters/kebabToPascalCase.d.ts +0 -14
- package/dist/utils/stringFormatters/kebabToSnakeCase.d.ts +0 -14
- package/dist/utils/stringFormatters/pascalToCamelCase.d.ts +0 -14
- package/dist/utils/stringFormatters/pascalToKebabCase.d.ts +0 -15
- package/dist/utils/stringFormatters/pascalToSnakeCase.d.ts +0 -15
- package/dist/utils/stringFormatters/snakeToCamelCase.d.ts +0 -14
- package/dist/utils/stringFormatters/snakeToKebabCase.d.ts +0 -14
- package/dist/utils/stringFormatters/snakeToPascalCase.d.ts +0 -14
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
import { Expand } from '../types/helperTypes';
|
|
2
|
-
import { TransformOptionsInternal } from '../types/transformOptionTypes';
|
|
3
|
-
import { TransformArrayReturn } from '../types/transformTypes';
|
|
4
|
-
/**
|
|
5
|
-
* Transforms all objects and Maps within an array (single level only)
|
|
6
|
-
*
|
|
7
|
-
* @param arr - The array to transform
|
|
8
|
-
* @param options - Transformation options including targetCase (required) and optional sourceCase
|
|
9
|
-
* @returns A new array with transformed items
|
|
10
|
-
*
|
|
11
|
-
* @remarks
|
|
12
|
-
* - This function transforms keys in objects and Maps contained in the array
|
|
13
|
-
* - Only transforms at the current level (not recursive)
|
|
14
|
-
* - Non-object values in the array are kept as-is
|
|
15
|
-
* - When sourceCase is specified, provides more precise type information
|
|
16
|
-
*
|
|
17
|
-
* @internal This function is for internal use by the library
|
|
18
|
-
*/
|
|
19
|
-
export default function transformArray<T extends unknown[], O extends TransformOptionsInternal>(arr: T, options: O): Expand<TransformArrayReturn<T, O>>;
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
import { TransformOptionsInternal } from '../types/transformOptionTypes';
|
|
2
|
-
import { TransformMapReturn } from '../types/transformTypes';
|
|
3
|
-
/**
|
|
4
|
-
* Transforms string keys in a Map (single level only)
|
|
5
|
-
*
|
|
6
|
-
* @param map - The Map to transform
|
|
7
|
-
* @param options - Transformation options including targetCase (required), optional sourceCase and optional preserveSpecialCharacters
|
|
8
|
-
* @returns A new Map with transformed keys
|
|
9
|
-
*
|
|
10
|
-
* @remarks
|
|
11
|
-
* - Only string keys are transformed; other key types remain unchanged
|
|
12
|
-
* - Values are not transformed, only copied to the new Map
|
|
13
|
-
* - When sourceCase is specified, provides precise type transformations
|
|
14
|
-
* - This function does not transform nested structures
|
|
15
|
-
*
|
|
16
|
-
* @internal This function is for internal use by the library
|
|
17
|
-
*/
|
|
18
|
-
export default function transformMap<K, V, O extends TransformOptionsInternal>(map: Map<K, V>, options: O): TransformMapReturn<K, V, O>;
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
import { TransformOptionsInternal } from '../types/transformOptionTypes';
|
|
2
|
-
import { TransformObjectReturn } from '../types/transformTypes';
|
|
3
|
-
/**
|
|
4
|
-
* Transforms an object's keys to the specified case format (single level only)
|
|
5
|
-
* @param obj - The object to transform
|
|
6
|
-
* @param options - Transformation options including targetCase (required), optional sourceCase and optional preserveSpecialCharacters
|
|
7
|
-
* @returns A new object with transformed keys
|
|
8
|
-
*
|
|
9
|
-
* @remarks
|
|
10
|
-
* - Only string keys will be transformed; numeric keys and Symbol keys remain unchanged
|
|
11
|
-
* - When sourceCase is specified:
|
|
12
|
-
* - TypeScript provides precise property type information
|
|
13
|
-
* - Transformation is more efficient (bypasses runtime detection)
|
|
14
|
-
* - When sourceCase is not specified:
|
|
15
|
-
* - Automatic case detection is used for each key
|
|
16
|
-
* - Return type is Record<string, unknown> for type safety
|
|
17
|
-
* - The preserveSpecialCharacters option retains special characters at the beginning and end of keys
|
|
18
|
-
*
|
|
19
|
-
* @internal This function is for internal use by the library
|
|
20
|
-
*/
|
|
21
|
-
export default function transformObject<T extends object, O extends TransformOptionsInternal>(obj: T, options: O): TransformObjectReturn<T, O>;
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
import { StringCase } from '../types/stringCaseTypes';
|
|
2
|
-
/**
|
|
3
|
-
* Transforms a single word to the target case format
|
|
4
|
-
* @param str - The single word to transform
|
|
5
|
-
* @param targetCase - The target case format
|
|
6
|
-
* @returns The transformed string
|
|
7
|
-
*/
|
|
8
|
-
export default function transformSingleWord(str: string, targetCase: StringCase): string;
|
package/dist/index.esm.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
const e={snake:{camel:function(e){return e.toLowerCase().replace(/_([a-z0-9])/g,((e,t)=>t.toUpperCase()))},pascal:function(e){return e.toLowerCase().replace(/_+([a-z0-9])/g,((e,t)=>t.toUpperCase())).replace(/^[a-z]/,(e=>e.toUpperCase()))},kebab:function(e){return e.replace(/_/g,"-")},snake:e=>e},camel:{snake:function(e){if(!e)return e;let t=e.replace(/([a-z0-9])([A-Z])/g,"$1_$2");return t=t.replace(/([A-Z])(?=[A-Z])/g,"$1_"),t.toLowerCase()},pascal:function(e){return e?e.charAt(0).toUpperCase()+e.slice(1):e},kebab:function(e){if(!e)return e;let t=e.replace(/([a-z0-9])([A-Z])/g,"$1-$2");return t=t.replace(/([A-Z])(?=[A-Z])/g,"$1-"),t.toLowerCase()},camel:e=>e},pascal:{snake:function(e){if(!e)return e;let t=e.replace(/([A-Z]{2,})([A-Z][a-z])/g,"$1_$2");return t=t.replace(/([a-z0-9])([A-Z])/g,"$1_$2"),t.toLowerCase()},camel:function(e){return e?e.charAt(0).toLowerCase()+e.slice(1):e},kebab:function(e){if(!e)return e;let t=e.replace(/([A-Z]{2,})([A-Z][a-z])/g,"$1-$2");return t=t.replace(/([a-z0-9])([A-Z])/g,"$1-$2"),t.toLowerCase()},pascal:e=>e},kebab:{snake:function(e){return e.replace(/-/g,"_")},camel:function(e){return e.toLowerCase().replace(/-+([a-z0-9])/g,((e,t)=>t.toUpperCase()))},pascal:function(e){return e.toLowerCase().replace(/-+([a-z0-9])/g,((e,t)=>t.toUpperCase())).replace(/^[a-z]/,(e=>e.toUpperCase()))},kebab:e=>e}};const t=/^[a-z0-9_]+$/,r=/__+/,n=/^[a-z][a-zA-Z0-9]*$/,s=/^[A-Z][a-zA-Z0-9]*$/,a=/^[a-z0-9-]+$/,o=/-{2,}/,c=/[A-Z]/,u=/[a-z]/,i=/^[a-z0-9]+$/;function l(e){return"string"!=typeof e?null:function(e){if(e.includes("_")||e.includes("-")||e.includes(" "))return!1;if(e.length>0&&!/^[A-Za-z0-9]+$/.test(e))return!1;if(e.length<=1)return!0;const t=e[0],r=e.slice(1);return e===e.toLowerCase()||t===t.toUpperCase()&&r===r.toLowerCase()}(e)?"single":function(e){return"string"==typeof e&&t.test(e)&&!r.test(e)&&(e.includes("_")||i.test(e))}(e)?"snake":function(e){return"string"==typeof e&&n.test(e)&&c.test(e)}(e)?"camel":function(e){return"string"==typeof e&&s.test(e)&&u.test(e)}(e)?"pascal":function(e){return"string"==typeof e&&a.test(e)&&!o.test(e)&&(e.includes("-")||i.test(e))}(e)?"kebab":null}function f(t,r){if(!t)return t;const{targetCase:n}=r,{string:s,shouldTransform:a,sourceCase:o,singleWord:c}=function(e){if("string"!=typeof e)throw new Error("Input must be a string");if(0===e.length)return{string:e,shouldTransform:!1,sourceCase:null,singleWord:!1};if(/[^A-Za-z0-9_-]/.test(e)||/^[^A-Za-z]/.test(e)||/[^A-Za-z0-9]$/.test(e))return{string:e,shouldTransform:!1,sourceCase:null,singleWord:!1};const t=l(e);return t?"single"===t?{string:e,shouldTransform:!0,sourceCase:null,singleWord:!0}:{string:e,shouldTransform:!0,sourceCase:t,singleWord:!1}:{string:e,shouldTransform:!1,sourceCase:null,singleWord:!1}}(t);if(!a)return s;if(c)return function(e,t){switch(t){case"pascal":return e.charAt(0).toUpperCase()+e.slice(1).toLowerCase();case"camel":return e.charAt(0).toLowerCase()+e.slice(1);case"snake":case"kebab":return e.toLowerCase();default:return e}}(s,n);if(!o||o===n)return s;const u=e[o];if(!u)return s;const i=u[n];return i?i(s):s}function p(e,t){if(!(e instanceof Map))return e;const r=[];for(const[n,s]of e.entries())if("string"==typeof n){const e=f(n,t);r.push([e,s])}else r.push([n,s]);return new Map(r)}function g(e,t){if(null===e||"object"!=typeof e||Array.isArray(e))return e;const{targetCase:r,sourceCase:n}=t,s={};for(const t in e)if(Object.prototype.hasOwnProperty.call(e,t)){s[!isNaN(Number(t))&&String(Number(t))===t?Number(t):f(t,{targetCase:r,sourceCase:n})]=e[t]}if(Object.getOwnPropertySymbols){const t=Object.getOwnPropertySymbols(e);for(const r of t)s[r]=e[r]}return s}function C(e,t,r=new WeakMap,n=0){var s;if(null==e||"object"!=typeof e)return e;if(r.has(e))return r.get(e);const a=null!==(s=t.depth)&&void 0!==s?s:3;if(n>=a)return e;const o=Object.assign(Object.assign({},t),{depth:a});let c;if(Array.isArray(e))c=function(e,t){return Array.isArray(e)?e.map((e=>null==e?e:e instanceof Map?p(e,t):"object"!=typeof e||Array.isArray(e)||e instanceof Set?e:g(e,t))):e}(e,t),r.set(e,c),n<a&&(c=c.map((e=>C(e,o,r,n+1))));else if(e instanceof Map){if(c=p(e,t),r.set(e,c),n<a){const e=c;for(const[t,s]of e.entries())null!==s&&"object"==typeof s&&e.set(t,C(s,o,r,n+1))}}else if(e instanceof Set){if(c=new Set(e),r.set(e,c),n<a){const e=c,t=Array.from(e);e.clear();for(const s of t)null!==s&&"object"==typeof s?e.add(C(s,o,r,n+1)):e.add(s)}}else if(c=g(e,t),r.set(e,c),n<a){const e=c;for(const t in e){const s=e[t];null!==s&&"object"==typeof s&&(e[t]=C(s,o,r,n+1))}}return c}function b(e,t){var r;return C(e,Object.assign(Object.assign({},t),{targetCase:(null==t?void 0:t.targetCase)||"camel",depth:null!==(r=null==t?void 0:t.depth)&&void 0!==r?r:3}))}export{b as default};
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
import { TransformOptionsInternal } from '../types/transformOptionTypes';
|
|
2
|
-
/**
|
|
3
|
-
* Recursively transforms data structures (objects, arrays, Maps) by changing their keys/property names
|
|
4
|
-
*
|
|
5
|
-
* @param data - The data to transform (object, array, Map)
|
|
6
|
-
* @param options - Transformation options
|
|
7
|
-
* @param visitedRefs - Used internally to track circular references
|
|
8
|
-
* @param currentDepth - Used internally to track current recursion depth
|
|
9
|
-
* @returns The transformed data
|
|
10
|
-
*
|
|
11
|
-
* @internal This function is for internal use by the library
|
|
12
|
-
*/
|
|
13
|
-
export default function internalTransform(data: unknown, options: TransformOptionsInternal & {
|
|
14
|
-
depth?: number;
|
|
15
|
-
}, visitedRefs?: WeakMap<object, unknown>, currentDepth?: number): unknown;
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
import { StringCase } from '../types/stringCaseTypes';
|
|
2
|
-
import { TransformOptions } from '../types/transformOptionTypes';
|
|
3
|
-
import { TransformRecursive } from '../types/transformTypes';
|
|
4
|
-
declare function transform<T, From extends StringCase, To extends StringCase>(data: T, options: TransformOptions & {
|
|
5
|
-
depth?: number;
|
|
6
|
-
sourceCase: From;
|
|
7
|
-
targetCase: To;
|
|
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;
|
|
18
|
-
declare function transform<T>(data: T, options?: TransformOptions & {
|
|
19
|
-
depth?: number;
|
|
20
|
-
}): unknown;
|
|
21
|
-
export default transform;
|
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
import { TransformOptionsInternal } from '../types/transformOptionTypes';
|
|
2
|
-
/**
|
|
3
|
-
* Transforms a string from one case format to another.
|
|
4
|
-
*
|
|
5
|
-
* @param str - The string to transform
|
|
6
|
-
* @param options - Transformation options
|
|
7
|
-
* @param options.targetCase - The target case format to transform to
|
|
8
|
-
* @param options.sourceCase - Optional source case format. If provided, skips detection
|
|
9
|
-
*
|
|
10
|
-
* @returns The transformed string, or the original string if transformation is not possible
|
|
11
|
-
*
|
|
12
|
-
* @example
|
|
13
|
-
* // With automatic source detection
|
|
14
|
-
* transformCase('hello_world', { targetCase: 'camel' })
|
|
15
|
-
* // => 'helloWorld'
|
|
16
|
-
*
|
|
17
|
-
* // With explicit source case
|
|
18
|
-
* transformCase('HelloWorld', { targetCase: 'snake', sourceCase: 'pascal' })
|
|
19
|
-
* // => 'hello_world'
|
|
20
|
-
*
|
|
21
|
-
* @internal This function is for internal use by the library
|
|
22
|
-
*/
|
|
23
|
-
export default function transformCase(str: string, options: TransformOptionsInternal): string;
|
|
@@ -1,41 +0,0 @@
|
|
|
1
|
-
import { StringCase } from './stringCaseTypes';
|
|
2
|
-
/**
|
|
3
|
-
* Options for the transform function
|
|
4
|
-
*/
|
|
5
|
-
export interface TransformOptions {
|
|
6
|
-
/**
|
|
7
|
-
* The target casing format to transform to
|
|
8
|
-
* @default 'camel'
|
|
9
|
-
*/
|
|
10
|
-
targetCase?: StringCase;
|
|
11
|
-
/**
|
|
12
|
-
* The source casing format to transform from
|
|
13
|
-
*
|
|
14
|
-
* When specified:
|
|
15
|
-
* - Provides precise TypeScript type transformations
|
|
16
|
-
* - Bypasses runtime case detection (more efficient)
|
|
17
|
-
* - Ensures consistent results if input has mixed casing
|
|
18
|
-
*
|
|
19
|
-
* When omitted:
|
|
20
|
-
* - Automatic case detection is used at runtime
|
|
21
|
-
* - TypeScript types will be less precise (string keys)
|
|
22
|
-
* - Works with mixed case inputs (each key detected separately)
|
|
23
|
-
*
|
|
24
|
-
* @example
|
|
25
|
-
* // With source specified - precise types
|
|
26
|
-
* const result = transform(data, { targetCase: 'camel', sourceCase: 'snake' });
|
|
27
|
-
* // result has exact transformed types
|
|
28
|
-
*
|
|
29
|
-
* // Without source - flexible runtime behavior
|
|
30
|
-
* const result = transform(data, { targetCase: 'camel' });
|
|
31
|
-
* // TypeScript types are more general
|
|
32
|
-
*
|
|
33
|
-
* @default undefined (automatic detection)
|
|
34
|
-
*/
|
|
35
|
-
sourceCase?: StringCase;
|
|
36
|
-
}
|
|
37
|
-
/**
|
|
38
|
-
* Internal options for transformation (used within the package).
|
|
39
|
-
* Ensures required fields are set after defaults are applied.
|
|
40
|
-
*/
|
|
41
|
-
export type TransformOptionsInternal = Required<Pick<TransformOptions, 'targetCase'>> & Omit<TransformOptions, 'targetCase'>;
|
|
@@ -1,279 +0,0 @@
|
|
|
1
|
-
import { Expand } from './helperTypes';
|
|
2
|
-
import { StringCase } from './stringCaseTypes';
|
|
3
|
-
import { TransformOptions } from './transformOptionTypes';
|
|
4
|
-
/**
|
|
5
|
-
* Type utility that transforms a snake_case string to camelCase
|
|
6
|
-
* Example: 'hello_world' -> 'helloWorld'
|
|
7
|
-
*/
|
|
8
|
-
export type SnakeToCamel<S extends string> = S extends `${infer P}_${infer C}${infer R}` ? `${P}${Uppercase<C>}${SnakeToCamel<R>}` : S;
|
|
9
|
-
/**
|
|
10
|
-
* Type utility that transforms a snake_case string to PascalCase
|
|
11
|
-
* Example: 'hello_world' -> 'HelloWorld'
|
|
12
|
-
*/
|
|
13
|
-
type SnakeWordsToPascal<Parts extends string[]> = Parts extends [
|
|
14
|
-
infer First extends string,
|
|
15
|
-
...infer Rest extends string[]
|
|
16
|
-
] ? `${Capitalize<First>}${SnakeWordsToPascal<Rest>}` : '';
|
|
17
|
-
type SnakeToWords<S extends string> = S extends `${infer P}_${infer R}` ? [P, ...SnakeToWords<R>] : [S];
|
|
18
|
-
export type SnakeToPascal<S extends string> = S extends `${infer P}_${infer R}` ? SnakeWordsToPascal<[P, ...SnakeToWords<R>]> : Capitalize<S>;
|
|
19
|
-
/**
|
|
20
|
-
* Type utility that transforms a snake_case string to kebab-case
|
|
21
|
-
* Example: 'hello_world' -> 'hello-world'
|
|
22
|
-
*/
|
|
23
|
-
export type SnakeToKebab<S extends string> = S extends `${infer P}_${infer R}` ? `${P}-${SnakeToKebab<R>}` : S;
|
|
24
|
-
/**
|
|
25
|
-
* Type utility that transforms a camelCase string to snake_case
|
|
26
|
-
* Example: 'helloWorld' -> 'hello_world'
|
|
27
|
-
*/
|
|
28
|
-
export type CamelToSnake<S extends string> = S extends `${infer C}${infer R}` ? C extends Uppercase<C> ? `_${Lowercase<C>}${CamelToSnake<R>}` : `${C}${CamelToSnake<R>}` : S;
|
|
29
|
-
/**
|
|
30
|
-
* Type utility that transforms a camelCase string to PascalCase
|
|
31
|
-
* Example: 'helloWorld' -> 'HelloWorld'
|
|
32
|
-
*/
|
|
33
|
-
export type CamelToPascal<S extends string> = Capitalize<S>;
|
|
34
|
-
/**
|
|
35
|
-
* Type utility that transforms a camelCase string to kebab-case
|
|
36
|
-
* Example: 'helloWorld' -> 'hello-world'
|
|
37
|
-
*/
|
|
38
|
-
export type CamelToKebab<S extends string> = S extends `${infer C}${infer R}` ? C extends Uppercase<C> ? `-${Lowercase<C>}${CamelToKebab<R>}` : `${C}${CamelToKebab<R>}` : S;
|
|
39
|
-
/**
|
|
40
|
-
* Type utility that transforms a PascalCase string to camelCase
|
|
41
|
-
* Example: 'HelloWorld' -> 'helloWorld'
|
|
42
|
-
*/
|
|
43
|
-
export type PascalToCamel<S extends string> = S extends `${infer F}${infer R}` ? `${Lowercase<F>}${R}` : S;
|
|
44
|
-
/**
|
|
45
|
-
* Type utility that transforms a PascalCase string to snake_case
|
|
46
|
-
* Example: 'HelloWorld' -> 'hello_world'
|
|
47
|
-
*/
|
|
48
|
-
export type PascalToSnake<S extends string> = S extends `${infer F}${infer R}` ? R extends `` ? Lowercase<F> : `${Lowercase<F>}${PascalToSnakeInner<R>}` : S;
|
|
49
|
-
type PascalToSnakeInner<S extends string> = S extends `${infer C}${infer R}` ? C extends Uppercase<C> ? `_${Lowercase<C>}${PascalToSnakeInner<R>}` : `${C}${PascalToSnakeInner<R>}` : S;
|
|
50
|
-
/**
|
|
51
|
-
* Type utility that transforms a PascalCase string to kebab-case
|
|
52
|
-
* Example: 'HelloWorld' -> 'hello-world'
|
|
53
|
-
*/
|
|
54
|
-
export type PascalToKebab<S extends string> = S extends `${infer F}${infer R}` ? R extends `` ? Lowercase<F> : `${Lowercase<F>}${PascalToKebabInner<R>}` : S;
|
|
55
|
-
type PascalToKebabInner<S extends string> = S extends `${infer C}${infer R}` ? C extends Uppercase<C> ? `-${Lowercase<C>}${PascalToKebabInner<R>}` : `${C}${PascalToKebabInner<R>}` : S;
|
|
56
|
-
/**
|
|
57
|
-
* Type utility that transforms a kebab-case string to camelCase
|
|
58
|
-
* Example: 'hello-world' -> 'helloWorld'
|
|
59
|
-
*/
|
|
60
|
-
export type KebabToCamel<S extends string> = S extends `${infer P}-${infer C}${infer R}` ? `${P}${Uppercase<C>}${KebabToCamel<R>}` : S;
|
|
61
|
-
/**
|
|
62
|
-
* Type utility that transforms a kebab-case string to PascalCase
|
|
63
|
-
* Example: 'hello-world' -> 'HelloWorld'
|
|
64
|
-
*/
|
|
65
|
-
type KebabWordsToPascal<Parts extends string[]> = Parts extends [
|
|
66
|
-
infer First extends string,
|
|
67
|
-
...infer Rest extends string[]
|
|
68
|
-
] ? `${Capitalize<First>}${KebabWordsToPascal<Rest>}` : '';
|
|
69
|
-
type KebabToWords<S extends string> = S extends `${infer P}-${infer R}` ? [P, ...KebabToWords<R>] : [S];
|
|
70
|
-
/**
|
|
71
|
-
* Type utility that transforms a kebab-case string to PascalCase
|
|
72
|
-
* Example: 'hello-world' -> 'HelloWorld'
|
|
73
|
-
*/
|
|
74
|
-
export type KebabToPascal<S extends string> = S extends `${infer P}-${infer R}` ? KebabWordsToPascal<[P, ...KebabToWords<R>]> : Capitalize<S>;
|
|
75
|
-
/**
|
|
76
|
-
* Type utility that transforms a kebab-case string to snake_case
|
|
77
|
-
* Example: 'hello-world' -> 'hello_world'
|
|
78
|
-
*/
|
|
79
|
-
export type KebabToSnake<S extends string> = S extends `${infer P}-${infer R}` ? `${P}_${KebabToSnake<R>}` : S;
|
|
80
|
-
/**
|
|
81
|
-
* Utility type to detect preserved keys that shouldn't be transformed.
|
|
82
|
-
* Preserved keys include those with leading/trailing special characters,
|
|
83
|
-
* unsupported patterns, or invalid starting/ending characters.
|
|
84
|
-
*/
|
|
85
|
-
type ForbiddenStartChars = '_' | '-' | '$' | '&' | '%' | '#' | '@' | '!' | '*' | '+' | '=' | '~' | '`' | '^' | '(' | ')' | '[' | ']' | '{' | '}' | '|' | '\\' | ':' | ';' | '"' | "'" | '<' | '>' | ',' | '.' | '?' | '/';
|
|
86
|
-
type ForbiddenEndChars = '_' | '-' | '$' | '&' | '%' | '#' | '@' | '!' | '*' | '+' | '=' | '~' | '`' | '^' | '(' | ')' | '[' | ']' | '{' | '}' | '|' | '\\' | ':' | ';' | '"' | "'" | '<' | '>' | ',' | '.' | '?' | '/' | `${number}`;
|
|
87
|
-
type PreservedKey<K extends string> = K extends `${infer First}${string}` ? First extends ForbiddenStartChars ? true : K extends `${string}${infer Last}` ? Last extends ForbiddenEndChars ? true : K extends `${string}__${string}` | `${string}--${string}` ? true : false : false : false;
|
|
88
|
-
/**
|
|
89
|
-
* Type utility that selects the correct string transformation based on source and target casing
|
|
90
|
-
*/
|
|
91
|
-
export type TransformKey<K extends string, O extends TransformOptions> = PreservedKey<K> extends true ? K : undefined extends O['sourceCase'] ? string : O['sourceCase'] extends 'snake' ? undefined extends O['targetCase'] ? SnakeToCamel<K> : O['targetCase'] extends 'camel' ? SnakeToCamel<K> : O['targetCase'] extends 'pascal' ? SnakeToPascal<K> : O['targetCase'] extends 'kebab' ? SnakeToKebab<K> : K : O['sourceCase'] extends 'camel' ? undefined extends O['targetCase'] ? K : O['targetCase'] extends 'snake' ? CamelToSnake<K> : O['targetCase'] extends 'pascal' ? CamelToPascal<K> : O['targetCase'] extends 'kebab' ? CamelToKebab<K> : K : O['sourceCase'] extends 'pascal' ? undefined extends O['targetCase'] ? PascalToCamel<K> : O['targetCase'] extends 'camel' ? PascalToCamel<K> : O['targetCase'] extends 'snake' ? PascalToSnake<K> : O['targetCase'] extends 'kebab' ? PascalToKebab<K> : K : O['sourceCase'] extends 'kebab' ? undefined extends O['targetCase'] ? KebabToCamel<K> : O['targetCase'] extends 'camel' ? KebabToCamel<K> : O['targetCase'] extends 'pascal' ? KebabToPascal<K> : O['targetCase'] extends 'snake' ? KebabToSnake<K> : K : K;
|
|
92
|
-
/**
|
|
93
|
-
* Type utility that transforms all keys in an object from the source case to the target case
|
|
94
|
-
*/
|
|
95
|
-
export type TransformObjectKeys<T, O extends TransformOptions = {
|
|
96
|
-
targetCase: 'camel';
|
|
97
|
-
}> = {
|
|
98
|
-
[K in keyof T as TransformKey<K & string, O>]: T[K];
|
|
99
|
-
};
|
|
100
|
-
/**
|
|
101
|
-
* Helper type to determine the return type of transformObject based on options
|
|
102
|
-
*/
|
|
103
|
-
export type TransformObjectReturn<T, O> = O extends {
|
|
104
|
-
sourceCase: StringCase;
|
|
105
|
-
} ? Expand<TransformObjectKeys<T, O>> : Record<string | number | symbol, unknown>;
|
|
106
|
-
/**
|
|
107
|
-
* Helper type to determine the return type of transformMap based on options
|
|
108
|
-
*/
|
|
109
|
-
export type TransformMapReturn<K, V, O> = O extends {
|
|
110
|
-
sourceCase: StringCase;
|
|
111
|
-
} ? Map<K extends string ? TransformKey<K & string, O> : K, V> : Map<string | Exclude<K, string>, V>;
|
|
112
|
-
/**
|
|
113
|
-
* Object transformation type aliases
|
|
114
|
-
* These provide more readable type names for common transformations
|
|
115
|
-
*/
|
|
116
|
-
export type SnakeToCamelObject<T> = TransformObjectKeys<T, {
|
|
117
|
-
sourceCase: 'snake';
|
|
118
|
-
targetCase: 'camel';
|
|
119
|
-
}>;
|
|
120
|
-
export type SnakeToPascalObject<T> = TransformObjectKeys<T, {
|
|
121
|
-
sourceCase: 'snake';
|
|
122
|
-
targetCase: 'pascal';
|
|
123
|
-
}>;
|
|
124
|
-
export type SnakeToKebabObject<T> = TransformObjectKeys<T, {
|
|
125
|
-
sourceCase: 'snake';
|
|
126
|
-
targetCase: 'kebab';
|
|
127
|
-
}>;
|
|
128
|
-
export type CamelToSnakeObject<T> = TransformObjectKeys<T, {
|
|
129
|
-
sourceCase: 'camel';
|
|
130
|
-
targetCase: 'snake';
|
|
131
|
-
}>;
|
|
132
|
-
export type CamelToPascalObject<T> = TransformObjectKeys<T, {
|
|
133
|
-
sourceCase: 'camel';
|
|
134
|
-
targetCase: 'pascal';
|
|
135
|
-
}>;
|
|
136
|
-
export type CamelToKebabObject<T> = TransformObjectKeys<T, {
|
|
137
|
-
sourceCase: 'camel';
|
|
138
|
-
targetCase: 'kebab';
|
|
139
|
-
}>;
|
|
140
|
-
export type PascalToCamelObject<T> = TransformObjectKeys<T, {
|
|
141
|
-
sourceCase: 'pascal';
|
|
142
|
-
targetCase: 'camel';
|
|
143
|
-
}>;
|
|
144
|
-
export type PascalToSnakeObject<T> = TransformObjectKeys<T, {
|
|
145
|
-
sourceCase: 'pascal';
|
|
146
|
-
targetCase: 'snake';
|
|
147
|
-
}>;
|
|
148
|
-
export type PascalToKebabObject<T> = TransformObjectKeys<T, {
|
|
149
|
-
sourceCase: 'pascal';
|
|
150
|
-
targetCase: 'kebab';
|
|
151
|
-
}>;
|
|
152
|
-
export type KebabToCamelObject<T> = TransformObjectKeys<T, {
|
|
153
|
-
sourceCase: 'kebab';
|
|
154
|
-
targetCase: 'camel';
|
|
155
|
-
}>;
|
|
156
|
-
export type KebabToPascalObject<T> = TransformObjectKeys<T, {
|
|
157
|
-
sourceCase: 'kebab';
|
|
158
|
-
targetCase: 'pascal';
|
|
159
|
-
}>;
|
|
160
|
-
export type KebabToSnakeObject<T> = TransformObjectKeys<T, {
|
|
161
|
-
sourceCase: 'kebab';
|
|
162
|
-
targetCase: 'snake';
|
|
163
|
-
}>;
|
|
164
|
-
/**
|
|
165
|
-
* Array transformation type aliases
|
|
166
|
-
*/
|
|
167
|
-
export type SnakeToCamelArray<T> = Array<SnakeToCamelObject<T>>;
|
|
168
|
-
export type SnakeToPascalArray<T> = Array<SnakeToPascalObject<T>>;
|
|
169
|
-
export type SnakeToKebabArray<T> = Array<SnakeToKebabObject<T>>;
|
|
170
|
-
export type CamelToSnakeArray<T> = Array<CamelToSnakeObject<T>>;
|
|
171
|
-
export type CamelToPascalArray<T> = Array<CamelToPascalObject<T>>;
|
|
172
|
-
export type CamelToKebabArray<T> = Array<CamelToKebabObject<T>>;
|
|
173
|
-
export type PascalToCamelArray<T> = Array<PascalToCamelObject<T>>;
|
|
174
|
-
export type PascalToSnakeArray<T> = Array<PascalToSnakeObject<T>>;
|
|
175
|
-
export type PascalToKebabArray<T> = Array<PascalToKebabObject<T>>;
|
|
176
|
-
export type KebabToCamelArray<T> = Array<KebabToCamelObject<T>>;
|
|
177
|
-
export type KebabToPascalArray<T> = Array<KebabToPascalObject<T>>;
|
|
178
|
-
export type KebabToSnakeArray<T> = Array<KebabToSnakeObject<T>>;
|
|
179
|
-
/**
|
|
180
|
-
* Generic transformation utility for objects
|
|
181
|
-
*/
|
|
182
|
-
export type TransformObject<T, From extends StringCase, To extends StringCase> = TransformObjectKeys<T, {
|
|
183
|
-
sourceCase: From;
|
|
184
|
-
targetCase: To;
|
|
185
|
-
}>;
|
|
186
|
-
/**
|
|
187
|
-
* Generic transformation utility for arrays
|
|
188
|
-
*/
|
|
189
|
-
export type TransformArray<T, From extends StringCase, To extends StringCase> = Array<TransformObject<T, From, To>>;
|
|
190
|
-
/**
|
|
191
|
-
* Helper type to determine array return type based on options
|
|
192
|
-
*/
|
|
193
|
-
export type TransformArrayReturn<T extends unknown[], O> = O extends {
|
|
194
|
-
sourceCase: StringCase;
|
|
195
|
-
} ? {
|
|
196
|
-
[K in keyof T]: T[K] extends object ? TransformObjectKeys<T[K], O> : T[K] extends Map<infer KT, infer VT> ? Map<KT extends string ? string : KT, VT> : T[K];
|
|
197
|
-
} : unknown[];
|
|
198
|
-
/**
|
|
199
|
-
* Recursive type transformations
|
|
200
|
-
* These types handle nested structures like arrays, objects, Maps, and Sets
|
|
201
|
-
*/
|
|
202
|
-
export type SnakeToCamelRecursive<T> = T extends Array<infer U> ? Array<SnakeToCamelRecursive<U>> : T extends Map<infer K, infer V> ? Map<K extends string ? SnakeToCamel<K> : K, SnakeToCamelRecursive<V>> : T extends Set<infer V> ? Set<SnakeToCamelRecursive<V>> : T extends object ? {
|
|
203
|
-
[K in keyof T as TransformKey<K & string, {
|
|
204
|
-
sourceCase: 'snake';
|
|
205
|
-
targetCase: 'camel';
|
|
206
|
-
}>]: SnakeToCamelRecursive<T[K]>;
|
|
207
|
-
} : T;
|
|
208
|
-
export type SnakeToPascalRecursive<T> = T extends Array<infer U> ? Array<SnakeToPascalRecursive<U>> : T extends Map<infer K, infer V> ? Map<K extends string ? SnakeToPascal<K> : K, SnakeToPascalRecursive<V>> : T extends Set<infer V> ? Set<SnakeToPascalRecursive<V>> : T extends object ? {
|
|
209
|
-
[K in keyof T as TransformKey<K & string, {
|
|
210
|
-
sourceCase: 'snake';
|
|
211
|
-
targetCase: 'pascal';
|
|
212
|
-
}>]: SnakeToPascalRecursive<T[K]>;
|
|
213
|
-
} : T;
|
|
214
|
-
export type SnakeToKebabRecursive<T> = T extends Array<infer U> ? Array<SnakeToKebabRecursive<U>> : T extends Map<infer K, infer V> ? Map<K extends string ? SnakeToKebab<K> : K, SnakeToKebabRecursive<V>> : T extends Set<infer V> ? Set<SnakeToKebabRecursive<V>> : T extends object ? {
|
|
215
|
-
[K in keyof T as TransformKey<K & string, {
|
|
216
|
-
sourceCase: 'snake';
|
|
217
|
-
targetCase: 'kebab';
|
|
218
|
-
}>]: SnakeToKebabRecursive<T[K]>;
|
|
219
|
-
} : T;
|
|
220
|
-
export type CamelToSnakeRecursive<T> = T extends Array<infer U> ? Array<CamelToSnakeRecursive<U>> : T extends Map<infer K, infer V> ? Map<K extends string ? CamelToSnake<K> : K, CamelToSnakeRecursive<V>> : T extends Set<infer V> ? Set<CamelToSnakeRecursive<V>> : T extends object ? {
|
|
221
|
-
[K in keyof T as TransformKey<K & string, {
|
|
222
|
-
sourceCase: 'camel';
|
|
223
|
-
targetCase: 'snake';
|
|
224
|
-
}>]: CamelToSnakeRecursive<T[K]>;
|
|
225
|
-
} : T;
|
|
226
|
-
export type CamelToPascalRecursive<T> = T extends Array<infer U> ? Array<CamelToPascalRecursive<U>> : T extends Map<infer K, infer V> ? Map<K extends string ? CamelToPascal<K> : K, CamelToPascalRecursive<V>> : T extends Set<infer V> ? Set<CamelToPascalRecursive<V>> : T extends object ? {
|
|
227
|
-
[K in keyof T as TransformKey<K & string, {
|
|
228
|
-
sourceCase: 'camel';
|
|
229
|
-
targetCase: 'pascal';
|
|
230
|
-
}>]: CamelToPascalRecursive<T[K]>;
|
|
231
|
-
} : T;
|
|
232
|
-
export type CamelToKebabRecursive<T> = T extends Array<infer U> ? Array<CamelToKebabRecursive<U>> : T extends Map<infer K, infer V> ? Map<K extends string ? CamelToKebab<K> : K, CamelToKebabRecursive<V>> : T extends Set<infer V> ? Set<CamelToKebabRecursive<V>> : T extends object ? {
|
|
233
|
-
[K in keyof T as TransformKey<K & string, {
|
|
234
|
-
sourceCase: 'camel';
|
|
235
|
-
targetCase: 'kebab';
|
|
236
|
-
}>]: CamelToKebabRecursive<T[K]>;
|
|
237
|
-
} : T;
|
|
238
|
-
export type PascalToCamelRecursive<T> = T extends Array<infer U> ? Array<PascalToCamelRecursive<U>> : T extends Map<infer K, infer V> ? Map<K extends string ? PascalToCamel<K> : K, PascalToCamelRecursive<V>> : T extends Set<infer V> ? Set<PascalToCamelRecursive<V>> : T extends object ? {
|
|
239
|
-
[K in keyof T as TransformKey<K & string, {
|
|
240
|
-
sourceCase: 'pascal';
|
|
241
|
-
targetCase: 'camel';
|
|
242
|
-
}>]: PascalToCamelRecursive<T[K]>;
|
|
243
|
-
} : T;
|
|
244
|
-
export type PascalToSnakeRecursive<T> = T extends Array<infer U> ? Array<PascalToSnakeRecursive<U>> : T extends Map<infer K, infer V> ? Map<K extends string ? PascalToSnake<K> : K, PascalToSnakeRecursive<V>> : T extends Set<infer V> ? Set<PascalToSnakeRecursive<V>> : T extends object ? {
|
|
245
|
-
[K in keyof T as TransformKey<K & string, {
|
|
246
|
-
sourceCase: 'pascal';
|
|
247
|
-
targetCase: 'snake';
|
|
248
|
-
}>]: PascalToSnakeRecursive<T[K]>;
|
|
249
|
-
} : T;
|
|
250
|
-
export type PascalToKebabRecursive<T> = T extends Array<infer U> ? Array<PascalToKebabRecursive<U>> : T extends Map<infer K, infer V> ? Map<K extends string ? PascalToKebab<K> : K, PascalToKebabRecursive<V>> : T extends Set<infer V> ? Set<PascalToKebabRecursive<V>> : T extends object ? {
|
|
251
|
-
[K in keyof T as TransformKey<K & string, {
|
|
252
|
-
sourceCase: 'pascal';
|
|
253
|
-
targetCase: 'kebab';
|
|
254
|
-
}>]: PascalToKebabRecursive<T[K]>;
|
|
255
|
-
} : T;
|
|
256
|
-
export type KebabToCamelRecursive<T> = T extends Array<infer U> ? Array<KebabToCamelRecursive<U>> : T extends Map<infer K, infer V> ? Map<K extends string ? KebabToCamel<K> : K, KebabToCamelRecursive<V>> : T extends Set<infer V> ? Set<KebabToCamelRecursive<V>> : T extends object ? {
|
|
257
|
-
[K in keyof T as TransformKey<K & string, {
|
|
258
|
-
sourceCase: 'kebab';
|
|
259
|
-
targetCase: 'camel';
|
|
260
|
-
}>]: KebabToCamelRecursive<T[K]>;
|
|
261
|
-
} : T;
|
|
262
|
-
export type KebabToPascalRecursive<T> = T extends Array<infer U> ? Array<KebabToPascalRecursive<U>> : T extends Map<infer K, infer V> ? Map<K extends string ? KebabToPascal<K> : K, KebabToPascalRecursive<V>> : T extends Set<infer V> ? Set<KebabToPascalRecursive<V>> : T extends object ? {
|
|
263
|
-
[K in keyof T as TransformKey<K & string, {
|
|
264
|
-
sourceCase: 'kebab';
|
|
265
|
-
targetCase: 'pascal';
|
|
266
|
-
}>]: KebabToPascalRecursive<T[K]>;
|
|
267
|
-
} : T;
|
|
268
|
-
export type KebabToSnakeRecursive<T> = T extends Array<infer U> ? Array<KebabToSnakeRecursive<U>> : T extends Map<infer K, infer V> ? Map<K extends string ? KebabToSnake<K> : K, KebabToSnakeRecursive<V>> : T extends Set<infer V> ? Set<KebabToSnakeRecursive<V>> : T extends object ? {
|
|
269
|
-
[K in keyof T as TransformKey<K & string, {
|
|
270
|
-
sourceCase: 'kebab';
|
|
271
|
-
targetCase: 'snake';
|
|
272
|
-
}>]: KebabToSnakeRecursive<T[K]>;
|
|
273
|
-
} : T;
|
|
274
|
-
/**
|
|
275
|
-
* Generic recursive transformation type
|
|
276
|
-
* Allows dynamically selecting the transformation based on source and target cases
|
|
277
|
-
*/
|
|
278
|
-
export type TransformRecursive<T, FromCase extends StringCase, ToCase extends StringCase> = FromCase extends 'snake' ? ToCase extends 'camel' ? SnakeToCamelRecursive<T> : ToCase extends 'pascal' ? SnakeToPascalRecursive<T> : ToCase extends 'kebab' ? SnakeToKebabRecursive<T> : T : FromCase extends 'camel' ? ToCase extends 'snake' ? CamelToSnakeRecursive<T> : ToCase extends 'pascal' ? CamelToPascalRecursive<T> : ToCase extends 'kebab' ? CamelToKebabRecursive<T> : T : FromCase extends 'pascal' ? ToCase extends 'snake' ? PascalToSnakeRecursive<T> : ToCase extends 'camel' ? PascalToCamelRecursive<T> : ToCase extends 'kebab' ? PascalToKebabRecursive<T> : T : FromCase extends 'kebab' ? ToCase extends 'snake' ? KebabToSnakeRecursive<T> : ToCase extends 'camel' ? KebabToCamelRecursive<T> : ToCase extends 'pascal' ? KebabToPascalRecursive<T> : T : T;
|
|
279
|
-
export {};
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Checks if a string is in camelCase format
|
|
3
|
-
* @param str - The string to check
|
|
4
|
-
* @returns boolean indicating if the string is in camelCase
|
|
5
|
-
*
|
|
6
|
-
* @example
|
|
7
|
-
* ```typescript
|
|
8
|
-
* isCamelCase('helloWorld') // => true
|
|
9
|
-
* isCamelCase('hello_world') // => false
|
|
10
|
-
* ```
|
|
11
|
-
* @internal This function is for internal use by the library
|
|
12
|
-
*/
|
|
13
|
-
export default function isCamelCase(str: string): boolean;
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Checks if a string is in kebab-case format
|
|
3
|
-
* @param str - The string to check
|
|
4
|
-
* @returns boolean indicating if the string is in kebab-case
|
|
5
|
-
*
|
|
6
|
-
* @example
|
|
7
|
-
* ```typescript
|
|
8
|
-
* isKebabCase('hello-world') // => true
|
|
9
|
-
* isKebabCase('helloWorld') // => false
|
|
10
|
-
* ```
|
|
11
|
-
* @internal This function is for internal use by the library
|
|
12
|
-
*/
|
|
13
|
-
export declare function isKebabCase(str: string): boolean;
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Checks if a string is in PascalCase format
|
|
3
|
-
* @param str - The string to check
|
|
4
|
-
* @returns boolean indicating if the string is in PascalCase
|
|
5
|
-
*
|
|
6
|
-
* @example
|
|
7
|
-
* ```typescript
|
|
8
|
-
* isPascalCase('HelloWorld') // => true
|
|
9
|
-
* isPascalCase('helloWorld') // => false
|
|
10
|
-
* ```
|
|
11
|
-
*
|
|
12
|
-
* @internal This function is for internal use by the library
|
|
13
|
-
*/
|
|
14
|
-
export default function isPascalCase(str: string): boolean;
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Checks if a string is in snake_case format
|
|
3
|
-
* @param str - The string to check
|
|
4
|
-
* @returns boolean indicating if the string is in snake_case
|
|
5
|
-
*
|
|
6
|
-
* @example
|
|
7
|
-
* ```typescript
|
|
8
|
-
* isSnakeCase('hello_world') // => true
|
|
9
|
-
* isSnakeCase('helloWorld') // => false
|
|
10
|
-
* ```
|
|
11
|
-
*
|
|
12
|
-
* @internal This function is for internal use by the library
|
|
13
|
-
*/
|
|
14
|
-
export default function isSnakeCase(str: string): boolean;
|
|
@@ -1,37 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Determines whether the given string qualifies as a single word.
|
|
3
|
-
*
|
|
4
|
-
* A string is considered a "single word" if:
|
|
5
|
-
* - It does not contain any delimiters such as underscores (`_`), hyphens (`-`), or spaces.
|
|
6
|
-
* - It contains only alphanumeric characters (letters and digits). Any other character (e.g., punctuation) will cause it to be considered as not a single word.
|
|
7
|
-
* - For strings longer than one character:
|
|
8
|
-
* - If the entire string is lowercase, it's considered a single word.
|
|
9
|
-
* - If the string starts with an uppercase letter and the rest are lowercase, it's considered a single word.
|
|
10
|
-
* - Single-character strings and empty strings are treated as a single word.
|
|
11
|
-
*
|
|
12
|
-
* @param {string} str - The string to check.
|
|
13
|
-
* @returns {boolean} Returns `true` if the input string qualifies as a single word, otherwise returns `false`.
|
|
14
|
-
*
|
|
15
|
-
* @example
|
|
16
|
-
* // Returns true because "hello" is a single word (all lowercase).
|
|
17
|
-
* detectSingleWord("hello");
|
|
18
|
-
*
|
|
19
|
-
* @example
|
|
20
|
-
* // Returns true because "Hello" is considered a single word (capitalized first letter only).
|
|
21
|
-
* detectSingleWord("Hello");
|
|
22
|
-
*
|
|
23
|
-
* @example
|
|
24
|
-
* // Returns false because "hello_world" contains an underscore.
|
|
25
|
-
* detectSingleWord("hello_world");
|
|
26
|
-
*
|
|
27
|
-
* @example
|
|
28
|
-
* // Returns false because "hello world" contains a space.
|
|
29
|
-
* detectSingleWord("hello world");
|
|
30
|
-
*
|
|
31
|
-
* @example
|
|
32
|
-
* // Returns false because "hello@world" contains a special character.
|
|
33
|
-
* detectSingleWord("hello@world");
|
|
34
|
-
*
|
|
35
|
-
* @internal This function is for internal use by the library
|
|
36
|
-
*/
|
|
37
|
-
export default function detectSingleWord(str: string): boolean;
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
import { StringCase } from '../types/stringCaseTypes';
|
|
2
|
-
/**
|
|
3
|
-
* Detects the case format of a string
|
|
4
|
-
* @param str - The string to analyze
|
|
5
|
-
* @returns The detected case format, 'single' for single words, or null if format cannot be determined
|
|
6
|
-
*
|
|
7
|
-
* @example
|
|
8
|
-
* ```typescript
|
|
9
|
-
* detectStringCase('hello_world') // => 'snake'
|
|
10
|
-
* detectStringCase('helloWorld') // => 'camel'
|
|
11
|
-
* detectStringCase('HelloWorld') // => 'pascal'
|
|
12
|
-
* detectStringCase('hello-world') // => 'kebab'
|
|
13
|
-
* detectStringCase('hello') // => 'single'
|
|
14
|
-
* ```
|
|
15
|
-
* @internal This function is for internal use by the library
|
|
16
|
-
*/
|
|
17
|
-
export default function detectStringCase(str: string): StringCase | 'single' | null;
|
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
import { StringCase } from '../types/stringCaseTypes';
|
|
2
|
-
/**
|
|
3
|
-
* Internal type used by string preparation utility
|
|
4
|
-
* Not exported as it's an implementation detail
|
|
5
|
-
*/
|
|
6
|
-
interface StringPreparationResult {
|
|
7
|
-
string: string;
|
|
8
|
-
shouldTransform: boolean;
|
|
9
|
-
sourceCase: StringCase | null;
|
|
10
|
-
singleWord: boolean;
|
|
11
|
-
}
|
|
12
|
-
/**
|
|
13
|
-
* Prepares a string for case transformation by validating input
|
|
14
|
-
* @param str - The input string to prepare
|
|
15
|
-
* @returns StringPreparationResult object containing the processed parts
|
|
16
|
-
* @throws {Error} If the input is not a string
|
|
17
|
-
* @internal This function is for internal use by the library
|
|
18
|
-
*/
|
|
19
|
-
export declare function prepareStringTransformation(str: string): StringPreparationResult;
|
|
20
|
-
export {};
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Converts a camelCase string to kebab-case
|
|
3
|
-
* Core transformation function without special character handling
|
|
4
|
-
*
|
|
5
|
-
* @param str - The camelCase string to convert
|
|
6
|
-
* @returns The kebab-case transformed string
|
|
7
|
-
*
|
|
8
|
-
* @example
|
|
9
|
-
* ```typescript
|
|
10
|
-
* camelToKebabCase('helloWorld') // => 'hello-world'
|
|
11
|
-
* ```
|
|
12
|
-
* @internal This function is for internal use by the library
|
|
13
|
-
*/
|
|
14
|
-
export default function camelToKebabCase(str: string): string;
|