Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add pascalcase function to sprig #430

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

smoto-shei-applibot
Copy link

@smoto-shei-applibot smoto-shei-applibot commented Feb 1, 2025

Title

feat: add pascalcase function and change camelcase behavior


Description

This pull request introduces two changes to the sprig library:

1. Added a pascalcase function

A new function, pascalcase, has been added to the funcMap. This function converts strings to upper camel case (PascalCase) using xstrings.ToPascalCase.

Example
go
{{ pascalcase "hello_world" }} // Output: HelloWorld

2. Modified the behavior of camelcase

The camelcase function has been updated to explicitly provide lower camel case (lowerCamelCase) behavior using xstrings.ToCamelCase.

Breaking Change

This modification introduces a breaking change, as the previous camelcase function used to convert to upper camel case (PascalCase). However:

  • This aligns with the general convention where camelcase implies lower camel case.
  • It is more intuitive for new users of sprig.

Rationale

  1. Improved clarity for new users: By distinguishing camelcase (lower camel case) and pascalcase (upper camel case), the library becomes easier to understand and use.
  2. Backward compatibility tradeoff: While this change introduces a breaking change for existing users of camelcase, the new behavior makes the function naming consistent with common expectations.

Tests Added

  • Unit tests for both pascalcase and the updated camelcase have been added to ensure expected behavior.
  • Test cases include scenarios with:
    • Underscores (_)
    • Hyphens (-)
    • Spaces
    • Mixed cases

Backward Compatibility

  • camelcase behavior change: May affect existing users relying on the previous upper camel case functionality.
  • New pascalcase function: Provides a clear alternative for upper camel case conversion.

Example Comparison

Input String | Old camelcase | New camelcase | New pascalcase -- | -- | -- | -- hello_world | HelloWorld | helloWorld | HelloWorld go-programming-lang | GoProgrammingLang | goProgrammingLang | GoProgrammingLang

Checklist

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.

1 participant