Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Aug 8, 2025

This PR implements kebab-case notation transformers following the existing pattern for camel, pascal, and snake case transformations. The implementation enables seamless conversion between kebab-case API responses and TypeScript-friendly camelCase properties.

Problem

Many REST APIs return data in kebab-case format (e.g., user-name, email-address), but accessing these properties in TypeScript requires cumbersome string indexing:

// Before: clunky string indexing required
const firstName = apiResponse["first-name"];
const streetName = apiResponse["home-address"]["street-name"];

Solution

This PR adds complete kebab-case notation support with the same API as existing notation transformers:

interface UserProfile {
  firstName: string;
  emailAddress: string;
  homeAddress: {
    streetName: string;
    zipCode: number;
  };
}

// API response in kebab-case
const apiResponse = {
  "first-name": "John",
  "email-address": "[email protected]", 
  "home-address": {
    "street-name": "Main Street",
    "zip-code": 12345
  }
};

// Convert to TypeScript-friendly camelCase
const userProfile = typia.notations.kebab<UserProfile>(apiResponse);
// Now access normally: userProfile.firstName, userProfile.emailAddress

// With validation
const validated = typia.notations.validateKebab<UserProfile>(apiResponse);
if (validated.success) {
  console.log(validated.data.homeAddress.streetName);
}

// With assertion
const asserted = typia.notations.assertKebab<UserProfile>(apiResponse);

// Type checking
const checked = typia.notations.isKebab<UserProfile>(apiResponse);

Implementation Details

  • Type System: Added KebabCase<T> utility type that converts all object keys to kebab-case
  • String Conversion: Enhanced NamingConvention namespace with bidirectional kebab conversion functions
  • Transformer Integration: Updated CallExpressionTransformer to map all kebab notation functions
  • API Completeness: Supports all transformation variants: kebab, assertKebab, isKebab, validateKebab, and their factory functions

Conversion Examples

The implementation handles all common naming convention conversions:

  • camelCase → kebab-case: firstNamefirst-name, socialSecurityNumbersocial-security-number
  • kebab-case → camelCase: first-namefirstName, social-security-numbersocialSecurityNumber
  • snake_case → kebab-case: first_namefirst-name
  • PascalCase → kebab-case: FirstNamefirst-name

Edge cases are properly handled including empty strings, single characters, prefix preservation, and complex acronyms.

Fixes #1548.


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

Copilot AI changed the title [WIP] kebab-case notations Add kebab-case notation support to typia transformer library Aug 8, 2025
Copilot AI requested a review from samchon August 8, 2025 15:37
Copilot finished work on behalf of samchon August 8, 2025 15:37
@samchon samchon marked this pull request as ready for review August 9, 2025 13:48
@pkg-pr-new
Copy link

pkg-pr-new bot commented Aug 9, 2025

Open in StackBlitz

npm i https://pkg.pr.new/typia@1637

commit: e777f0f

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

kebab-case notations

2 participants