internal/functions/ConvertTo-CanonicalPuppetAuthorName.ps1
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
Function ConvertTo-CanonicalPuppetAuthorName { <# .SYNOPSIS Convert a string to a valid Puppet module author name .DESCRIPTION Convert a string to a valid Puppet module author name, replacing any non-alphanumeric characters with underscores, downcasing the strin, and trimming any extraneous underscores. .PARAMETER AuthorName The string to convert into a canonicalized Puppet module author name. .EXAMPLE "foo bar" | ConvertTo-CanonicalPuppetAuthorName This command will return the string 'foo_bar', which is a valid Puppet module author name. #> [cmdletbinding()] param( [Parameter(ValueFromPipeline)] [string]$AuthorName ) Begin {} Process { # Puppet module author names must be lower cased alphanumeric $CanonicalAuthorName = $AuthorName.ToLower() -replace '[^a-zA-Z\d]+', '_' # An author name likely should neither end nor begin with one or more underscores $CanonicalAuthorName.trim('_') } End {} } |