Coder Social home page Coder Social logo

dfinke / powershellhumanizer Goto Github PK

View Code? Open in Web Editor NEW
116.0 13.0 17.0 1.29 MB

PowerShell Humanizer wraps Humanizer: meets all your .NET needs for manipulating and displaying strings, enums, dates, times, timespans, numbers and quantities

License: Apache License 2.0

PowerShell 44.27% Jupyter Notebook 55.73%

powershellhumanizer's Introduction

PowerShell Humanizer

This PowerShell module wraps Mehdi Khalili's .NET Humanizer.

Humanizer meets all your .NET needs for manipulating and displaying strings, enums, dates, times, timespans, numbers and quantities http://humanizr.net

Install

To install grab it from the Powershell Gallery

Install-Module -Name PowerShellHumanizer

What's new

4/24/2016

Check out how to call the Humanize capabilities.

Using PowerShell Humanizer

image

Examples

Pluralize

PS C:\> ConvertTo-Plural man
men

PS C:\> echo person man woman | ConvertTo-Plural
people
men
women

Singularize

PS C:\> echo people men women geese indicies oxen knives | ConvertTo-Singular
person
man
woman
goose
indicy
ox
knife

Hyphenate

PS C:\> "Continuing To Make Powershell A Bit More Human" | ConvertTo-HyphenatedString
continuing-to-make-powershell-a-bit-more-human

Number to ordinal words

PS C:\> ConvertTo-OrdinalWords 121
hundred and twenty first

PS C:\> 120..130 | ConvertTo-OrdinalWords
hundred and twentieth
hundred and twenty first
hundred and twenty second
hundred and twenty third
hundred and twenty fourth
hundred and twenty fifth
hundred and twenty sixth
hundred and twenty seventh
hundred and twenty eighth
hundred and twenty ninth
hundred and thirtieth

String Extension Methods

PS C:\> 'then add nodes under it.'.ToTitleCase()
Then Add Nodes Under It.

PS C:\> 'FromTitleCase'.Underscore()
from_title_case

PS C:\> 'then add nodes under it.'.TruncateWords(3)
then add nodes…

PS C:\> 'then add nodes under it.'.Truncate(3,"Words")
then add nodes…

PS C:\> 'then add nodes under it.'.Truncate(7, "Characters", '-')
then a-

PS C:\> 'then add nodes under it.'.Dehumanize()
ThenAddNodesUnderIt.

PS C:\> 'string'.ToQuantity(50)
50 strings

PS C:\> 'string'.ToQuantity(50, "word")
fifty strings

PS C:\> (Get-Date).Year.ToRoman()
MMXIV

Integer Extension Methods

PS C:\> Register-HumanizerInteger

PS C:\> (3).Ordinalize()
3rd

PS C:\> (3).ToWords()
three

PS C:\> Write-Host "Now: $(Get-Date). In three weeks: $((Get-Date) + (3).Weeks)"
Now: 04/16/2014 09:18:10. In three weeks: 05/07/2014 09:18:10

TimeSpan Extension Methods

PS C:\> $past = Get-Date

# Do some stuff

PS C:\> ((Get-Date)-$past).Humanize()
1 minute

PS C:\> ((Get-Date)-$past).Humanize(2)
1 minute, 42 seconds

DateTime Extension Methods

PS C:\> (Get-Date).Humanize($true)
4 hours ago

PS C:\> (Get-Date).Humanize()
now

PS C:\> dir | select @{Label="LastModified";Expression={$_.LastWriteTime.ToUniversalTime().Humanize()}}

LastModified
------------
7 months ago
7 months ago
7 months ago
7 months ago
one year ago
10 months ago

Custom TimeSpan Formats

PS C:\> measure-command { 1..15000000}

2 seconds, 981 milliseconds

PS C:\> (get-date) - (get-date "1/1/2015")

57 weeks, 6 days, 20 hours

PS C:\> $output = (get-date "1/1/2015") - (get-date)

PS C:\> $output

no time

PS C:\> $output | fl


Days              : -405
Hours             : -20
Minutes           : -50
Seconds           : -23
Milliseconds      : -356
Ticks             : -350670233562167
TotalDays         : -405.868325882138
TotalHours        : -9740.8398211713
TotalMinutes      : -584450.389270278
TotalSeconds      : -35067023.3562167
TotalMilliseconds : -35067023356.2167

Custom FileSystem Table Format

PS C:\> Get-ChildItem


    Directory: C:\Program Files\7-Zip


Mode     LastWritten         Length Name
----     -----------         ------ ----
da----   9 months ago               Lang
-a----   one year ago         93 KB 7-zip.chm
-a----   one year ago         79 KB 7-zip.dll
-a----   one year ago         49 KB 7-zip32.dll
-a----   one year ago          1 MB 7z.dll
-a----   one year ago        414 KB 7z.exe
-a----   one year ago        178 KB 7z.sfx
-a----   one year ago        163 KB 7zCon.sfx
-a----   one year ago        784 KB 7zFM.exe
-a----   one year ago        533 KB 7zG.exe
-a----   4 years ago          366 B descript.ion
-a----   one year ago         40 KB History.txt
-a----   one year ago          2 KB License.txt
-a----   one year ago          2 KB readme.txt

powershellhumanizer's People

Contributors

cdhunt avatar dfinke avatar farzadmf avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

powershellhumanizer's Issues

Update-TypeData : Error in TypeData "System.String": The member ToQuantity is already present

ipmo PowerShellHumanizer -Force

Update-TypeData : Error in TypeData "System.String": The member ToQuantity is already present.
At C:\Users\Douglas\Documents\WindowsPowerShell\Modules\PowerShellHumanizer\PowerShellHumanizer.psm1:63 char:5
+     Update-TypeData -TypeName System.String `
+     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidOperation: (:) [Update-TypeData], RuntimeException
    + FullyQualifiedErrorId : TypesDynamicUpdateException,Microsoft.PowerShell.Commands.UpdateTypeDataCommand

Consider adding formatting

It might be useful to add custom formatting for some types, e.g. TimeSpan. The default display for TimeSpan isn't that good, the Humanize method looks much better, Use case:

Measure-Command { dir }

The output should be, well, humanized. In my own personal profile, I use something like:

<View>
<Name>Timespan</Name>
  <ViewSelectedBy>
    <TypeName>System.TimeSpan</TypeName>
  </ViewSelectedBy>
  <CustomControl>
    <CustomEntries>
      <CustomEntry>
        <CustomItem>
          <ExpressionBinding>
            <ScriptBlock>
$d = $_.Days; $h = $_.Hours; $m = $_.Minutes; $as = "","s"
$(if ($d) { "{0} day{1}," -f $d, $as[$d -gt 1] }
  if ($h) { "{0} hour{1}," -f $h, $as[$h -gt 1] }
  if ($m) { "{0} minute{1}," -f $m, $as[$m -gt 1] }
  "{0}.{1}s" -f $_.Seconds, $_.Milliseconds.ToString('D3')) -join " "
</ScriptBlock>
          </ExpressionBinding>
        </CustomItem>
      </CustomEntry>
    </CustomEntries>
  </CustomControl>
</View>   

ToQuantity issue

'widgets'.ToQuantity(1,"Words")
returns "one widget"

ConvertTo-Quantity -quantity 1 -string "widgets" -showQuantityAs "Words"
returns "Words widget"
expected output "one widget"

It appears that the ConvertTo-Quantity function is not working as expected
Under the covers ConvertTo-Quantity uses [Humanizer.ToQuantityExtensions]::ToQuantity($string, $quantity, $showQuantityAs)

Calling that directly like:
[Humanizer.ToQuantityExtensions]::ToQuantity('widget', 1, 'Words')
returns "Words widget"
expected output "one widget"

Looks like the parameter processing is messed up somehow.

License type change to MIT

Would you be willing to change the license type to MIT? This is more permissible and easier to use in context of commercial environments. Some similar projects like dbatools and others have migrated over to this license to allow much more flexible usage.

Additionally, I'd like to add more functionality for formatting timespans, dates. Do you want some pull requests to collaborate or is this current repository not actively maintained?

Thanks!

Unexpected token 'MyDocuments')) -ChildPath WindowsPowerShell\Modules in install.ps1

Invoke-Expression : At line:22 char:71
+     $personalModules = Join-Path -Path
([Environment]::GetFolderPath('MyDocument ...
+
~~~~~~~~~~
Unexpected token 'MyDocuments')) -ChildPath WindowsPowerShell\Modules
    if (($env:PSModulePath -split '' in expression or statement.
At line:23 char:37
+     if (($env:PSModulePath -split ';') -notcontains $personalModules)
+                                     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
The string is missing the terminator: '.
At line:46 char:2
+
Missing closing ')' in subexpression.
At line:1 char:1
+ iex (new-object
System.Net.WebClient).DownloadString('https://raw.github.com/dfi ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
~~~
    + CategoryInfo          : ParserError: (:) [Invoke-Expression], ParseExcep
   tion
    + FullyQualifiedErrorId : UnexpectedToken,Microsoft.PowerShell.Commands.In
   vokeExpressionCommand

Surface more options on casing

"CanReturnTitleCase".Humanize(LetterCasing.Title) => "Can Return Title Case"

"Can_return_title_Case".Humanize(LetterCasing.Title) => "Can Return Title Case"

"CanReturnLowerCase".Humanize(LetterCasing.LowerCase) => "can return lower case"

"CanHumanizeIntoUpperCase".Humanize(LetterCasing.AllCaps) => "CAN HUMANIZE INTO UPPER CASE"

`Install.ps1` not found, should it use `Install-Module`?

I went to use the readme recommended way of installing, which ended with an HTTP 404.

iex (new-object System.Net.WebClient).DownloadString('https://raw.github.com/dfinke/PowerShellHumanizer/master/Install.ps1')

Is this file inadvertently missing, or should the readme be updated to use Install-Module?

Install-Module -Name PowerShellHumanizer

Test says indicies/indicy instead of indices/index

Neither 'indicies' nor 'indicy' are words. indices/index are

Context 'Singularize' {
        $output = echo people men women geese indicies oxen knives | ConvertTo-Singular
        It 'Should convert to singles' {
            $output[0] | Should Be 'person'
            $output[1] | Should Be 'man'
            $output[2] | Should Be 'woman'
            $output[3] | Should Be 'goose'
            $output[4] | Should Be 'indicy'
            $output[5] | Should Be 'ox'
            $output[6] | Should Be 'knife'
        }

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.