Functions/Get-Puppeteer_DeclareUsernameAndPassword.ps1

<#
.SYNOPSIS
    This function returns the Node JS Puppeteer code for declaring username and password variables.
#>

function Get-Puppeteer_DeclareUsernameAndPassword {
    [CmdletBinding(PositionalBinding=$true)]
    [OutputType([String])]
    param (
        # The credential containing the username and the password.
        [Parameter(Mandatory=$true)]
        [ValidateNotNull()]
        [PSCredential]$credential
    )

    # Generate the code
    $code = @"
const username = "%username%";
const password = "%password%";
"@

    $code = $code -replace "%username%", $credential.Username
    $code = $code -replace "%password%", $credential.GetNetworkCredential().Password

    # Return the code
    return $code
}