Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/jdhitsolutions/mynumber
A demonstration PowerShell module of a class-based tool that creates a custom number object.
https://github.com/jdhitsolutions/mynumber
powershell powershell-classes powershell-module powershell-scripting
Last synced: 2 months ago
JSON representation
A demonstration PowerShell module of a class-based tool that creates a custom number object.
- Host: GitHub
- URL: https://github.com/jdhitsolutions/mynumber
- Owner: jdhitsolutions
- License: mit
- Created: 2017-12-29T18:59:51.000Z (about 7 years ago)
- Default Branch: master
- Last Pushed: 2023-12-29T18:49:05.000Z (about 1 year ago)
- Last Synced: 2024-10-12T21:06:46.214Z (4 months ago)
- Topics: powershell, powershell-classes, powershell-module, powershell-scripting
- Language: PowerShell
- Homepage:
- Size: 31.3 KB
- Stars: 3
- Watchers: 3
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: Changelog.md
- License: License.txt
Awesome Lists containing this project
README
# MyNumber
:mortar_board: A demonstration class-based module that creates a *number* object. The functionality of the module isn't that practical. But it can serve as a model of how you might build a class-based PowerShell tool.
The module should work on Windows PowerShell and PowerShell 7, including cross-platform. It is intended for educational purposes.
Install the latest version from the PowerShell Gallery.
```powershell
Install-Module MyNumber
```You can also use the `Microsoft.PowerShell.PSResourceGet` module.
```powershell
Install-PSResource MyNumber -scope AllUsers
```The class is defined in [MyNumber.psm1](mynumber.psm1). Functionality is exposed through a set of functions.
+ [New-MyNumber](/docs/New-MyNumber.md)
+ [Set-MyNumber](/docs/Set-MyNumber.md)
+ [Convert-MyNumber](/docs/Convert-MyNumber.md)The module also includes custom format and type extensions. The examples shown below may not reflect these changes.
```powershell
PS C:\> $x = New-MyNumber 11
PS C:\> $xNumber : 11
Square : 121
Cube : 1331
Sqrt : 3.3166247903554
Log : 2.39789527279837
Sine : -0.999990206550703
Cosine : 0.00442569798805079
Tangent : -225.950846454195
CircleArea : 380.132711084365
Inverse : 0.0909090909090909
IsEven : False
IsPrime : True
Exp : 59874.1417151978
Factorial : 39916800
Factors : {1, 11}
Custom : 0PS C:\> $x | Set-MyNumber -value 123
Number : 123
Square : 15129
Cube : 1860867
Sqrt : 11.0905365064094
Log : 4.81218435537242
Sine : -0.459903490689591
Cosine : -0.887968906691855
Tangent : 0.517927471585655
CircleArea : 47529.15525616
Inverse : 0.00813008130081301
IsEven : False
IsPrime : False
Exp : 2.61951731874906E+53
Factorial : 1.21463043670253E+205
Factors : {1, 3, 41, 123}
Custom : 0PS C:\> $x | Convert-MyNumber -ToHex
7bPS C:\> Convert-MyNumber 1024 -ToBinary
10000000000
```You can also create a number with a custom script block.
```powershell
PS C:\> New-MyNumber 77 -CustomScriptBlock {Param($x) [char][int]$x }Number : 77
Square : 5929
Cube : 456533
Sqrt : 8.77496438739212
Log : 4.34380542185368
Sine : 0.999520158580731
Cosine : -0.0309750317312165
Tangent : -32.2685757759344
CircleArea : 18626.5028431339
Inverse : 0.012987012987013
IsEven : False
IsPrime : False
Exp : 2.75851345452317E+33
Factorial : 1.45183092028286E+113
Factors : {1, 7, 11, 77}
Custom : M
```You should include a parameter in your script block for the number value. It will be passed as an argument when calculating the value.
You can only access the class definition through the functions.