diff --git a/.github/linters/.jscpd.json b/.github/linters/.jscpd.json new file mode 100644 index 0000000..23970e8 --- /dev/null +++ b/.github/linters/.jscpd.json @@ -0,0 +1,10 @@ +{ + "threshold": 0, + "reporters": [ + "consoleFull" + ], + "ignore": [ + "**/tests/**" + ], + "absolute": true +} diff --git a/.github/linters/.powershell-psscriptanalyzer.psd1 b/.github/linters/.powershell-psscriptanalyzer.psd1 index 570ac0d..09cc3d0 100644 --- a/.github/linters/.powershell-psscriptanalyzer.psd1 +++ b/.github/linters/.powershell-psscriptanalyzer.psd1 @@ -1,17 +1,56 @@ -#Documentation: https://github.com/PowerShell/PSScriptAnalyzer/blob/master/docs/Cmdlets/Invoke-ScriptAnalyzer.md#-settings -@{ - #CustomRulePath='path\to\CustomRuleModule.psm1' - #RecurseCustomRulePath='path\of\customrules' - #Severity = @( - # 'Error' - # 'Warning' - #) - #IncludeDefaultRules=${true} +@{ + Rules = @{ + PSAlignAssignmentStatement = @{ + Enable = $true + CheckHashtable = $true + } + PSAvoidLongLines = @{ + Enable = $true + MaximumLineLength = 150 + } + PSAvoidSemicolonsAsLineTerminators = @{ + Enable = $true + } + PSPlaceCloseBrace = @{ + Enable = $true + NewLineAfter = $false + IgnoreOneLineBlock = $true + NoEmptyLineBefore = $false + } + PSPlaceOpenBrace = @{ + Enable = $true + OnSameLine = $true + NewLineAfter = $true + IgnoreOneLineBlock = $true + } + PSProvideCommentHelp = @{ + Enable = $true + ExportedOnly = $false + BlockComment = $true + VSCodeSnippetCorrection = $false + Placement = 'begin' + } + PSUseConsistentIndentation = @{ + Enable = $true + IndentationSize = 4 + PipelineIndentation = 'IncreaseIndentationForFirstPipeline' + Kind = 'space' + } + PSUseConsistentWhitespace = @{ + Enable = $true + CheckInnerBrace = $true + CheckOpenBrace = $true + CheckOpenParen = $true + CheckOperator = $true + CheckPipe = $true + CheckPipeForRedundantWhitespace = $true + CheckSeparator = $true + CheckParameter = $true + IgnoreAssignmentOperatorInsideHashTable = $true + } + } ExcludeRules = @( - 'PSMissingModuleManifestField' + 'PSMissingModuleManifestField', # This rule is not applicable until the module is built. + 'PSUseToExportFieldsInManifest' ) - #IncludeRules = @( - # 'PSAvoidUsingWriteHost', - # 'MyCustomRuleName' - #) } diff --git a/.github/linters/.textlintrc b/.github/linters/.textlintrc new file mode 100644 index 0000000..db48de8 --- /dev/null +++ b/.github/linters/.textlintrc @@ -0,0 +1,513 @@ +{ + "filters": { + "comments": true + }, + "rules": { + "terminology": { + "defaultTerms": false, + "terms": [ + "Airbnb", + "Android", + "AppleScript", + "AppVeyor", + "AVA", + "BrowserStack", + "Browsersync", + "Codecov", + "CodePen", + "CodeSandbox", + "DefinitelyTyped", + "EditorConfig", + "ESLint", + "GitHub", + "GraphQL", + "GraphiQL", + "iOS", + "JavaScript", + "JetBrains", + "jQuery", + "LinkedIn", + "Lodash", + "MacBook", + "Markdown", + "OpenType", + "PayPal", + "PhpStorm", + "PowerShell", + "PlayStation", + "RubyMine", + "Sass", + "SemVer", + "TypeScript", + "UglifyJS", + "Wasm", + "WebAssembly", + "WebStorm", + "WordPress", + "YouTube", + [ + "Common[ .]js", + "CommonJS" + ], + [ + "JSDocs?", + "JSDoc" + ], + [ + "Node[ .]js", + "Node.js" + ], + [ + "React[ .]js", + "React" + ], + [ + "SauceLabs", + "Sauce Labs" + ], + [ + "StackOverflow", + "Stack Overflow" + ], + [ + "styled ?components", + "styled-components" + ], + [ + "HTTP[ /]2(?:\\.0)?", + "HTTP/2" + ], + [ + "OS X", + "macOS" + ], + [ + "Mac ?OS", + "macOS" + ], + [ + "a npm", + "an npm" + ], + "ECMAScript", + [ + "ES2015", + "ES6" + ], + [ + "ES7", + "ES2016" + ], + "3D", + [ + "3-D", + "3D" + ], + "Ajax", + "API", + "APIs", + "API's", + [ + "(? [Alias('ConvertFrom-Base64String')] [OutputType([string])] [CmdletBinding()] param( - # The base64 encoded string to convert. + # The base64-encoded string to be decoded. [Parameter( Mandatory, - ValueFromPipeline + ValueFromPipeline, + ValueFromPipelineByPropertyName )] [ValidateScript({ Test-Base64 -Base64String $_ }, ErrorMessage = 'Invalid Base64 string')] - [string] $Base64String + [string] $Base64String, + + # The encoding to use when converting the string to bytes. + [Parameter()] + [ValidateSet('UTF8', 'UTF7', 'UTF32', 'ASCII', 'Unicode', 'BigEndianUnicode', 'Latin1')] + [string] $Encoding = 'UTF8' ) - return [System.Text.Encoding]::UTF8.GetString([Convert]::FromBase64String($Base64String)) + [System.Text.Encoding]::$Encoding.GetString([Convert]::FromBase64String($Base64String)) } diff --git a/src/functions/public/ConvertTo-Base64.ps1 b/src/functions/public/ConvertTo-Base64.ps1 index 05a1fd6..40dbd13 100644 --- a/src/functions/public/ConvertTo-Base64.ps1 +++ b/src/functions/public/ConvertTo-Base64.ps1 @@ -1,34 +1,47 @@ filter ConvertTo-Base64 { <# .SYNOPSIS - Convert a string to base64 + Converts a string to its base64 encoded representation. .DESCRIPTION - Converts a string to a base64 encoded string. + This function takes a string as input and converts it to a base64 encoded string using UTF-8 encoding. + It accepts input from the pipeline and can process string values directly. .EXAMPLE - ConvertTo-Base64 -String 'ThisIsANiceString' - VGhpc0lzQU5pY2VTdHJpbmc= + "Hello World" | ConvertTo-Base64 - Converts the string 'ThisIsANiceString' to a base64 encoded string. - - .EXAMPLE - 'Hello World' | ConvertTo-Base64 + Output: + ```powershell SGVsbG8gV29ybGQ= + ``` + + Converts the string "Hello World" to its base64 encoded equivalent. - Converts the string 'Hello World' to base64. + .OUTPUTS + System.String + + .NOTES + The base64 encoded representation of the input string. + + .LINK + https://psmodule.io/Base64/Functions/ConvertTo-Base64/ #> [Alias('ConvertTo-Base64String')] [OutputType([string])] [CmdletBinding()] param( - # The string to convert to base64 + # The input string to be converted to base64 encoding. [Parameter( Mandatory, ValueFromPipeline, ValueFromPipelineByPropertyName )] - [string] $String + [string] $String, + + # The encoding to use when converting the string to bytes. + [Parameter()] + [ValidateSet('UTF8', 'UTF7', 'UTF32', 'ASCII', 'Unicode', 'BigEndianUnicode', 'Latin1')] + [string] $Encoding = 'UTF8' ) - return [Convert]::ToBase64String([System.Text.Encoding]::UTF8.GetBytes($String)) + [Convert]::ToBase64String([System.Text.Encoding]::$Encoding.GetBytes($String)) } diff --git a/src/functions/public/Test-Base64.ps1 b/src/functions/public/Test-Base64.ps1 index ade81cd..2796f97 100644 --- a/src/functions/public/Test-Base64.ps1 +++ b/src/functions/public/Test-Base64.ps1 @@ -1,26 +1,46 @@ filter Test-Base64 { <# .SYNOPSIS - Test if a string is a valid base64 string. + Determines whether a given string is a valid base64-encoded string. .DESCRIPTION - Test if a string is a valid base64 string. + This function checks whether the provided string is a valid base64-encoded string. + It attempts to decode the input using `[Convert]::FromBase64String()`. + If the decoding succeeds, it returns `$true`; otherwise, it returns `$false`. .EXAMPLE Test-Base64 -Base64String 'U29tZSBkYXRh' + + Output: + ```powershell True + ``` - Returns $true as the string is a valid base64 string. + Returns `$true` as the string is a valid base64-encoded string. .EXAMPLE 'U29tZSBkYXRh' | Test-Base64 + + Output: + ```powershell True + ``` + + Returns `$true` as the string is a valid base64-encoded string. + + .OUTPUTS + bool + + .NOTES + Returns `$true` if the string is a valid base64-encoded string, otherwise `$false`. - Returns $true as the string is a valid base64 string. + .LINK + https://psmodule.io/Test/Functions/Test-Base64 #> [OutputType([bool])] [CmdletBinding()] param ( + # The base64-encoded string to validate. [Parameter( Mandatory, ValueFromPipeline @@ -30,8 +50,8 @@ try { $null = [Convert]::FromBase64String($Base64String) - return $true + $true } catch { - return $false + $false } } diff --git a/tests/Module.Tests.ps1 b/tests/Base64.Tests.ps1 similarity index 100% rename from tests/Module.Tests.ps1 rename to tests/Base64.Tests.ps1