Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion build.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,13 @@ $csproj = [System.IO.Path]::Combine($src, "dotnet", "dependencies.csproj")
$bin = [System.IO.Path]::Combine($src, "dotnet", "bin")
$obj = [System.IO.Path]::Combine($src, "dotnet", "obj")
$lib = [System.IO.Path]::Combine($publish, "lib")
$ps51 = [System.IO.Path]::Combine($src, "ps51")

Write-Host "src: $src"
Write-Host "docs: $docs"
Write-Host "publish: $publish"
Write-Host "lib: $lib"
Write-Host "ps51: $ps51"
Write-Host "dotnet: $([Environment]::Version)"
Write-Host "ps: $($PSVersionTable.PSVersion)"

Expand All @@ -64,7 +66,7 @@ $manifest = @{

FunctionsToExport = @()
ModuleVersion = [version]::new($Major, $Minor, $Build, $Revision)
PowerShellVersion = '7.4'
PowerShellVersion = '5.1'
ProjectUri = "https://github.com/dfinke/PowerShellHumanizer"
LicenseUri = "https://github.com/dfinke/PowerShellHumanizer/blob/master/LICENSE.txt"
RootModule = "$module.psm1"
Expand Down Expand Up @@ -105,6 +107,9 @@ function Build {
Get-ChildItem -Path $lib -filter "*.pdb" | Remove-Item -Force -ErrorAction SilentlyContinue
Get-ChildItem -Path $lib -filter "System.Management.Automation.dll" | Remove-Item -Force -ErrorAction SilentlyContinue
Get-ChildItem -Path $lib -filter "dependencies.dll" | Remove-Item -Force -ErrorAction SilentlyContinue

# Copy PowerShell 5.1 dll's
Copy-Item -Path "$ps51/*.dll" -Destination "$publish/lib"

Copy-Item -Path "$src/$module.psm1" -Destination $publish
Copy-Item -Path @("$parent/README.md") -Destination $publish -ErrorAction SilentlyContinue
Expand Down
12 changes: 4 additions & 8 deletions src/PowerShellHumanizer.psm1
Original file line number Diff line number Diff line change
@@ -1,13 +1,9 @@
# Load dlls
Add-Type -Path "$PSScriptRoot/lib/Humanizer.dll"

if ($PSCulture -ne 'en-US') {
if (Test-Path "$PSScriptRoot/lib/$PSCulture") {
Add-Type -Path "$PSScriptRoot/lib/$PSCulture/Humanizer.resources.dll"
} else {
Write-Warning "Humanizer doesn't currently support '$PSCulture'."
}
if ($PSVersionTable.PSVersion.Major -lt 6) {
Add-Type -Path "$PSScriptRoot/lib/System.Buffers.4.0.2.0.dll"
Add-Type -Path "$PSScriptRoot/lib/System.Runtime.CompilerServices.Unsafe.4.0.4.1.dll"
}
Add-Type -Path "$PSScriptRoot/lib/Humanizer.dll"

if (Get-Module -Name Terminal-Icons -ListAvailable -ErrorAction SilentlyContinue) {
Update-FormatData -PrependPath "$PSSCriptRoot/formats/FileInfoIcons.format.ps1xml"
Expand Down
4 changes: 2 additions & 2 deletions src/dotnet/dependencies.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@

<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
<Version>3.0.0-beta.13</Version>
<Version>3.0.0-beta.54</Version>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Humanizer" Version="3.0.0-beta.13" />
<PackageReference Include="Humanizer" Version="3.0.0-beta.54" />
</ItemGroup>

</Project>
2 changes: 1 addition & 1 deletion src/en-US/about_PowerShellHumanizer.help.txt
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ INTEGER EXTENSION PROPERTIES
.Milliseconds

TIMESPAN EXTENSION METHODS
.Humanize([int]Precision)
.Humanize([int]Precision, [CultureInfo]Culture, [Humanizer.TimeUnit]MaxUnit, [string]CollectionSeparator, [bool]ToWords)

DATETIME EXTENSION METHODS
.Humanize([bool]UTC)
34 changes: 16 additions & 18 deletions src/formats/FileInfo.format.ps1xml
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
<?xml version="1.0" encoding="utf-8" ?>
<Configuration>
<SelectionSets>
<SelectionSet>
Expand All @@ -8,7 +9,6 @@
</Types>
</SelectionSet>
</SelectionSets>

<!-- ################ GLOBAL CONTROL DEFINITIONS ################ -->
<Controls>
<Control>
Expand All @@ -22,47 +22,45 @@
<CustomItem>
<Text AssemblyName="System.Management.Automation" BaseName="FileSystemProviderStrings" ResourceId="DirectoryDisplayGrouping"/>
<ExpressionBinding>
<ScriptBlock>
$_.PSParentPath.Replace("Microsoft.PowerShell.Core\FileSystem::", "")
</ScriptBlock>
<ScriptBlock>
$_.PSParentPath.Replace("Microsoft.PowerShell.Core\FileSystem::", "")
</ScriptBlock>
</ExpressionBinding>
<NewLine/>
</CustomItem>
</CustomItem>
</Frame>
</CustomItem>
</CustomEntry>
</CustomEntries>
</CustomControl>
</Control>
</Controls>

<!-- ################ VIEW DEFINITIONS ################ -->

<ViewDefinitions>
<View>
<View>
<Name>children</Name>
<ViewSelectedBy>
<SelectionSetName>FileSystemTypes</SelectionSetName>
</ViewSelectedBy>
<GroupBy>
<PropertyName>PSParentPath</PropertyName>
<CustomControlName>FileSystemTypes-GroupingFormat</CustomControlName>
<PropertyName>PSParentPath</PropertyName>
<CustomControlName>FileSystemTypes-GroupingFormat</CustomControlName>
</GroupBy>
<TableControl>
<TableHeaders>
<TableColumnHeader>
<Label>Mode</Label>
<Width>8</Width>
<Alignment>left</Alignment>
</TableColumnHeader>
<TableColumnHeader>
<Label>Mode</Label>
<Width>8</Width>
<Alignment>Left</Alignment>
</TableColumnHeader>
<TableColumnHeader>
<Label>LastWritten</Label>
<Width>15</Width>
</TableColumnHeader>
<TableColumnHeader>
<Label>Length</Label>
<Width>10</Width>
<Alignment>right</Alignment>
<Alignment>Right</Alignment>
</TableColumnHeader>
<TableColumnHeader/>
</TableHeaders>
Expand All @@ -80,7 +78,7 @@
</TableColumnItem>
<TableColumnItem>
<ScriptBlock>
if (-not $_.PSIsContainer) { [Humanizer.ByteSizeExtensions]::bytes($_.Length).ToString(0.00)}
if (-not $_.PSIsContainer) { [Humanizer.ByteSizeExtensions]::bytes($_.Length).ToString(0.00)}
</ScriptBlock>
</TableColumnItem>
<TableColumnItem>
Expand All @@ -92,4 +90,4 @@
</TableControl>
</View>
</ViewDefinitions>
</Configuration>
</Configuration>
11 changes: 5 additions & 6 deletions src/formats/FileInfoIcons.format.ps1xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
<?xml version="1.0" encoding="utf-8" ?>

<!-- Based on the format.ps1xml file from DirColors
https://github.com/DHowett/DirColors -->
<Configuration>
Expand All @@ -26,7 +25,7 @@ https://github.com/DHowett/DirColors -->
<Text AssemblyName="System.Management.Automation" BaseName="FileSystemProviderStrings" ResourceId="DirectoryDisplayGrouping"/>
<ExpressionBinding>
<ScriptBlock>
$_.PSParentPath.Replace("Microsoft.PowerShell.Core\FileSystem::", "")
$_.PSParentPath.Replace("Microsoft.PowerShell.Core\FileSystem::", "")
</ScriptBlock>
</ExpressionBinding>
<NewLine/>
Expand Down Expand Up @@ -54,17 +53,17 @@ https://github.com/DHowett/DirColors -->
<TableColumnHeader>
<Label>Mode</Label>
<Width>7</Width>
<Alignment>left</Alignment>
<Alignment>Left</Alignment>
</TableColumnHeader>
<TableColumnHeader>
<Label>LastWriteTime</Label>
<Width>25</Width>
<Alignment>right</Alignment>
<Alignment>Right</Alignment>
</TableColumnHeader>
<TableColumnHeader>
<Label>Length</Label>
<Width>14</Width>
<Alignment>right</Alignment>
<Alignment>Right</Alignment>
</TableColumnHeader>
<TableColumnHeader>
<Label>Name</Label>
Expand Down Expand Up @@ -228,4 +227,4 @@ https://github.com/DHowett/DirColors -->
</WideControl>
</View>
</ViewDefinitions>
</Configuration>
</Configuration>
Binary file added src/ps51/System.Buffers.4.0.2.0.dll
Binary file not shown.
Binary file not shown.
4 changes: 2 additions & 2 deletions src/public/ConvertTo-Quantity.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,10 @@ function ConvertTo-Quantity {
[CmdletBinding()]
[OutputType('string')]
param(
[Parameter(Mandatory, Position = 0, ValueFromPipeline)]
[Parameter(Mandatory, Position = 0)]
[string]$String,

[Parameter(Mandatory, Position = 1)]
[Parameter(Mandatory, Position = 1, ValueFromPipeline)]
[Alias('Count')]
[int]$Quantity,

Expand Down
22 changes: 18 additions & 4 deletions src/types/TimeSpan.types.ps1xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,24 @@
<Name>Humanize</Name>
<Script>
[OutputType([System.String])]
param([int]$Precision = 1)
[Humanizer.TimeSpanHumanizeExtensions]::Humanize($this, $Precision)
param(
[Int]$Precision = 1,
[CultureInfo]$Culture = [CultureInfo]::CurrentUICulture,
[Humanizer.TimeUnit]$MaxUnit = [Humanizer.TimeUnit]::Year,
[String]$CollectionSeparator = ', ',
[Boolean]$ToWords = $false
)
[Humanizer.TimeSpanHumanizeExtensions]::Humanize(
$this,
$Precision,
$Culture,
$MaxUnit,
[Humanizer.TimeUnit]::Millisecond,
$CollectionSeparator,
$ToWords
)
</Script>
</ScriptMethod>
</ScriptMethod>
</Members>
</Type>
</Types>
</Types>
4 changes: 2 additions & 2 deletions tests/PowerShellHumanizer.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -151,8 +151,8 @@ Describe 'Custom Formats' {

Context 'FileSystem' {
BeforeAll {
$listAlphaLower = 'a'..'z'
$listAlphaUpper = 'A'..'Z'
$listAlphaLower = [char[]](97..122)
$listAlphaUpper = [char[]](65..90)
$listNumber = 0..9
$charset = $listAlphaLower + $listAlphaUpper + $listNumber

Expand Down