Skip to content

Instantly share code, notes, and snippets.

@patelnwd
Forked from awakecoding/PascalSnakeCase.ps1
Created June 9, 2023 05:24
Show Gist options
  • Save patelnwd/a40cd32d07393982bb9162d941dd2b0f to your computer and use it in GitHub Desktop.
Save patelnwd/a40cd32d07393982bb9162d941dd2b0f to your computer and use it in GitHub Desktop.
PowerShell ConvertTo-PascalCase, ConvertTo-SnakeCase
function ConvertTo-PascalCase
{
[OutputType('System.String')]
param(
[Parameter(Position=0)]
[string] $Value
)
# https://devblogs.microsoft.com/oldnewthing/20190909-00/?p=102844
return [regex]::replace($Value.ToLower(), '(^|_)(.)', { $args[0].Groups[2].Value.ToUpper()})
}
function ConvertTo-SnakeCase
{
[OutputType('System.String')]
param(
[Parameter(Position=0)]
[string] $Value
)
return [regex]::replace($Value, '(?<=.)(?=[A-Z])', '_').ToLower()
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment