Functions/Get-Puppeteer_DeclareVariable.ps1

<#
.SYNOPSIS
    This function returns the Node JS Puppeteer code for declaring a variable.
#>

function Get-Puppeteer_DeclareVariable {
    [CmdletBinding(PositionalBinding=$true)]
    [OutputType([String])]
    param (
        # The name of the variable.
        [Parameter(Mandatory=$true)]
        [ValidateNotNullOrEmpty()]
        [String]$name,

        # The value of the variable.
        [Parameter(Mandatory=$true)]
        [ValidateNotNullOrEmpty()]
        [String]$value,

        # Select if the variable should be const.
        [Parameter(Mandatory=$false)]
        [Switch]$const
    )

    # Generate the code
    $code = "$($name) = $($value);"
    if ($const) {
        $code = "const $($code)"
    }

    # Return the code
    return $code
}