Skip to content

Commit

Permalink
Random (#78)
Browse files Browse the repository at this point in the history
* Random Components.

* Update components.

* Readme.
  • Loading branch information
adamdriscoll authored Sep 5, 2024
1 parent 4b1a131 commit 21a5d55
Show file tree
Hide file tree
Showing 5 changed files with 170 additions and 5 deletions.
17 changes: 17 additions & 0 deletions Misc/Random.Apps/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# Random Components

Components for dealing with randomization.

## Components

### `New-UDRandom`

Displays a card that allows for generating different types of random data. This includes:

- Password
- Number
- GUID
- List item
- Powerball Numbers

![Weather Card](https://raw.githubusercontent.com/ironmansoftware/scripts/main/images/Misc/Random.Apps.png)
22 changes: 22 additions & 0 deletions Misc/Random.Apps/Random.Apps.psd1
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
@{
RootModule = 'Random.Apps.psm1'
ModuleVersion = '1.0.0'
GUID = '36bc5153-97b0-4447-8b45-64b0cb31213d'
Author = 'Ironman Software'
CompanyName = 'Ironman Software'
Copyright = '(c) Ironman Software. All rights reserved.'
Description = 'Random tools for apps.'
FunctionsToExport = @(
'New-UDRandom'
)

PrivateData = @{
PSData = @{
Tags = @('app', 'random')
LicenseUri = 'https://github.com/ironmansoftware/scripts/blob/main/LICENSE'
ProjectUri = 'https://github.com/ironmansoftware/scripts/tree/main/Misc/Random.Apps'
IconUri = 'https://raw.githubusercontent.com/ironmansoftware/scripts/main/images/app.png'
}
}
}

127 changes: 127 additions & 0 deletions Misc/Random.Apps/Random.Apps.psm1
Original file line number Diff line number Diff line change
@@ -0,0 +1,127 @@

function New-UDRandomPassword {
param(
[int]$Length = 12,
[switch]$IncludeUppercase,
[switch]$IncludeLowercase,
[switch]$IncludeNumbers,
[switch]$IncludeSpecialCharacters
)

$Characters = @()
if ($IncludeUppercase) {
$Characters += 65..90 | ForEach-Object { [char]$_ }
}
if ($IncludeLowercase) {
$Characters += 97..122 | ForEach-Object { [char]$_ }
}
if ($IncludeNumbers) {
$Characters += 48..57 | ForEach-Object { [char]$_ }
}
if ($IncludeSpecialCharacters) {
$Characters += 33..47 | ForEach-Object { [char]$_ }
$Characters += 58..64 | ForEach-Object { [char]$_ }
$Characters += 91..96 | ForEach-Object { [char]$_ }
$Characters += 123..126 | ForEach-Object { [char]$_ }
}

$Password = ""
for ($i = 0; $i -lt $Length; $i++) {
$Password += $Characters | Get-Random
}

$Password
}

function New-UDRandomPowerballNumbers {
$Numbers = 1..69 | Get-Random -Count 5
$Powerball = 1..26 | Get-Random
$Numbers + $Powerball
}

function New-UDRandom {
param(
[Parameter()]
[string[]]$Tools = @("Password", "GUID", "Number", "ListItem", "Powerball")
)

New-UDForm -Content {
if ($Tools.Length -gt 1) {
New-UDSelect -Label "Tool" -Option {
$Tools | ForEach-Object {
New-UDSelectOption -Name $_ -Value $_
}
} -OnChange {
$Page:Tool = $EventData
Sync-UDElement -Id 'form'
} -DefaultValue $Tools[0]
$Page:Tool = $Tools[0]
}
else {
$Page:Tool = $Tools[0]
}

New-UDDynamic -Id 'form' -Content {
if ($Page:Tool -eq "Password") {
New-UDTypography "Length"
New-UDSlider -Id "Length" -Value 12 -Min 4 -Max 128
New-UDCheckbox -Label "Include Uppercase" -Id "IncludeUppercase"
New-UDCheckbox -Label "Include Lowercase" -Id "IncludeLowercase"
New-UDCheckbox -Label "Include Numbers" -Id "IncludeNumbers"
New-UDCheckbox -Label "Include Special Characters" -Id "IncludeSpecialCharacters"
}
elseif ($Page:Tool -eq "Number") {
New-UDTypography "Minimum"
New-UDSlider -Id "Minimum" -Value 0 -Min 0 -Max 10000
New-UDTypography "Maximum"
New-UDSlider -Id "Maximum" -Value 100 -Min 0 -Max 10000
}
elseif ($Page:Tool -eq "ListItem") {
New-UDTextbox -Label "Items" -Id "Items" -Multiline -Rows 4 -RowsMax 10
}
}
} -OnSubmit {
if ($Page:Tool -eq "Password") {
$Page:Password = New-UDRandomPassword -Length $EventData.Length -IncludeUppercase:$EventData.IncludeUppercase -IncludeLowercase:$EventData.IncludeLowercase -IncludeNumbers:$EventData.IncludeNumbers -IncludeSpecialCharacters:$EventData.IncludeSpecialCharacters
}
elseif ($Page:Tool -eq "GUID") {
$Page:Guid = New-Guid
}
elseif ($Page:Tool -eq "Number") {
$Page:Number = Get-Random -Minimum $EventData.Minimum -Maximum $EventData.Maximum
}
elseif ($Page:Tool -eq "ListItem") {
$Page:Items = $EventData.Items -split "`n"
$Page:Item = $Page:Items | Get-Random
}
elseif ($Page:Tool -eq "Powerball") {
$Page:Powerball = New-UDRandomPowerballNumbers
}
Sync-UDElement -Id "Output"
}

New-UDDynamic -Id "Output" -Content {
New-UDCard -Title 'Output' -Content {
if ($Page:Tool -eq "Password") {
New-UDTypography -Text $Page:Password
}
elseif ($Page:Tool -eq "GUID") {
New-UDTypography -Text $Page:Guid
}
elseif ($Page:Tool -eq "Number") {
New-UDTypography -Text $Page:Number
}
elseif ($Page:Tool -eq "ListItem") {
New-UDTypography -Text $Page:Item
}
elseif ($Page:Tool -eq "Powerball") {
$Page:Powerball | Select-Object -First 5 | ForEach-Object {
New-UDChip -Label $_
}
New-UDChip -Label $Page:Powerball[-1] -Style @{
backgroundColor = 'red'
}
}
}
}
}
9 changes: 4 additions & 5 deletions Misc/Weather.Apps/Weather.Apps.psd1
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,10 @@

PrivateData = @{
PSData = @{
Tags = @('app', 'weather')
LicenseUri = 'https://github.com/ironmansoftware/scripts/blob/main/LICENSE'
ProjectUri = 'https://github.com/ironmansoftware/scripts/tree/main/Misc/Weather.Apps'
IconUri = 'https://raw.githubusercontent.com/ironmansoftware/scripts/main/images/app.png'
DisplayName = 'PowerShell Scripts'
Tags = @('app', 'weather')
LicenseUri = 'https://github.com/ironmansoftware/scripts/blob/main/LICENSE'
ProjectUri = 'https://github.com/ironmansoftware/scripts/tree/main/Misc/Weather.Apps'
IconUri = 'https://raw.githubusercontent.com/ironmansoftware/scripts/main/images/app.png'
}
}
}
Expand Down
Binary file added images/Misc/Random.Apps.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 21a5d55

Please sign in to comment.