-
Notifications
You must be signed in to change notification settings - Fork 19
Expand file tree
/
Copy pathPowerShellHumanizer.psm1
More file actions
145 lines (114 loc) · 2.94 KB
/
PowerShellHumanizer.psm1
File metadata and controls
145 lines (114 loc) · 2.94 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
Add-Type -Path "$PSScriptRoot\Humanizer.dll"
$Types = @("$PSScriptRoot\String.types.ps1xml",
"$PSScriptRoot\Int.types.ps1xml",
"$PSScriptRoot\TimeSpan.types.ps1xml",
"$PSScriptRoot\DateTime.types.ps1xml",
"$PSScriptRoot\CmdletInfo.types.ps1xml")
Update-TypeData -PrependPath $Types
# Must call Update-FormatData with -PrependPath to override built-in defined formats
Update-FormatData -PrependPath "$PSScriptRoot\TimeSpan.format.ps1xml"
Update-FormatData -PrependPath "$PSScriptRoot\FileInfo.format.ps1xml"
function ConvertFrom-RomanNumeral {
param(
[Parameter(ValueFromPipeline=$true)]
[string]$RomanNumeral
)
Process {
[Humanizer.RomanNumeralExtensions]::FromRoman($RomanNumeral)
}
}
function ConvertTo-Casing {
param(
[Parameter(ValueFromPipeline=$true)]
[string]$Target,
[ValidateSet("Title","AllCaps","LowerCase","Sentence")]
$Case="Title"
)
Process {
[Humanizer.CasingExtensions]::ApplyCase($Target, $Case)
}
}
function ConvertTo-HumanDate {
param(
[Parameter(ValueFromPipeline=$true)]
[datetime]$Date=(Get-Date)
)
Process {
[Humanizer.DateHumanizeExtensions]::Humanize( $Date , $false )
}
}
function ConvertTo-Ordinal {
param(
[Parameter(ValueFromPipeline=$true)]
[int]$Target
)
Process {
[Humanizer.OrdinalizeExtensions]::Ordinalize($Target)
}
}
function ConvertTo-OrdinalWords {
param(
[Parameter(ValueFromPipeline=$true)]
[int]$Target
)
Process {
[Humanizer.NumberToWordsExtension]::ToOrdinalWords($Target)
}
}
function ConvertTo-Plural {
param(
[Parameter(ValueFromPipeline=$true)]
$Word
)
Process {
[Humanizer.InflectorExtensions]::Pluralize($word)
}
}
function ConvertTo-Quantity {
param(
[string]$string,
[Parameter(ValueFromPipeline=$true)]
[int]$quantity,
[ValidateSet("None","Numeric","Words")]
$showQuantityAs="Numeric"
)
Process {
[Humanizer.ToQuantityExtensions]::ToQuantity($string, $quantity, $showQuantityAs)
}
}
function ConvertTo-RomanNumeral {
param(
[Parameter(ValueFromPipeline=$true)]
[int]$Number
)
Process {
[Humanizer.RomanNumeralExtensions]::ToRoman($Number)
}
}
function ConvertTo-Singular {
param(
[Parameter(ValueFromPipeline=$true)]
$Word
)
Process {
[Humanizer.InflectorExtensions]::Singularize($word)
}
}
function ConvertTo-Words {
param(
[Parameter(ValueFromPipeline=$true)]
[int]$number
)
Process {
[Humanizer.NumberToWordsExtension]::ToWords($number)
}
}
function ConvertTo-HyphenatedString {
param(
[Parameter(ValueFromPipeline=$true)]
$TitleString
)
Process {
[Humanizer.InflectorExtensions]::Dasherize($TitleString.Underscore())
}
}