{"id":40900519,"url":"https://github.com/imbue11235/humanize","last_synced_at":"2026-01-22T02:31:25.441Z","repository":{"id":45343003,"uuid":"397989257","full_name":"imbue11235/humanize","owner":"imbue11235","description":"A collection of utility functions, with built-in localization, for humanizing various types of data input, in Go","archived":false,"fork":false,"pushed_at":"2021-12-19T21:06:24.000Z","size":202,"stargazers_count":73,"open_issues_count":3,"forks_count":1,"subscribers_count":2,"default_branch":"main","last_synced_at":"2024-06-19T02:06:34.839Z","etag":null,"topics":["converter","format","formatting","go","golang","humanizer","text"],"latest_commit_sha":null,"homepage":"https://pkg.go.dev/github.com/imbue11235/humanize","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/imbue11235.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2021-08-19T15:26:08.000Z","updated_at":"2024-02-05T13:22:12.000Z","dependencies_parsed_at":"2022-08-20T18:31:24.707Z","dependency_job_id":null,"html_url":"https://github.com/imbue11235/humanize","commit_stats":null,"previous_names":[],"tags_count":3,"template":false,"template_full_name":null,"purl":"pkg:github/imbue11235/humanize","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/imbue11235%2Fhumanize","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/imbue11235%2Fhumanize/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/imbue11235%2Fhumanize/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/imbue11235%2Fhumanize/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/imbue11235","download_url":"https://codeload.github.com/imbue11235/humanize/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/imbue11235%2Fhumanize/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28651760,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-22T01:17:37.254Z","status":"online","status_checked_at":"2026-01-22T02:00:07.137Z","response_time":144,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["converter","format","formatting","go","golang","humanizer","text"],"created_at":"2026-01-22T02:31:24.230Z","updated_at":"2026-01-22T02:31:25.434Z","avatar_url":"https://github.com/imbue11235.png","language":"Go","readme":"# humanize [![Test Status](https://github.com/imbue11235/humanize/workflows/Go/badge.svg)](https://github.com/imbue11235/humanize/actions?query=workflow:Go) [![codecov](https://codecov.io/gh/imbue11235/humanize/branch/main/graph/badge.svg?token=XTJ42655U1)](https://codecov.io/gh/imbue11235/humanize) [![Go Reference](https://pkg.go.dev/badge/github.com/imbue11235/humanize.svg)](https://pkg.go.dev/github.com/imbue11235/humanize)\n\n\u003e A collection of utility functions, with [built-in localization](#built-in-locales), for humanizing various types of data input.\n\n## 🛠  Installation\n\nMake sure to have Go installed (Version `1.16` or higher).\n\nInstall `humanize` with `go get`:\n\n```sh\n$ go get -u github.com/imbue11235/humanize\n```\n\n## 💻  Usage\n\n### Humanizing time\n\nTakes two time instances, and presents the difference in a human-readable format.\n\n#### Estimated time\n\nThis is a more loose calculation of time, where only the highest unit of time is prioritized.\nE.g. `1 hour 20 minutes` becomes `1 hour` and `1 hour 55 minutes` becomes `2 hours` etc. \n\n##### Time from _x_\n\nTakes two time instances as input, to produce a human-readable representation of the difference in time.\n\n```go\na := time.Parse(..., \"2020-01-01\")\nb := time.Parse(..., \"2021-02-01\")\n\nfmt.Printf(\"It happened almost %s\", humanize.Time(a).From(b)) // =\u003e It happened almost a year ago\n```\n\n##### Time from now\n\nThis is a utility function, which is like calling `Time(a).From(b)`, but where `b` is automatically set to `time.Now()`\n\n```go\na := time.Parse(..., \"2021-05-05\")\n\nfmt.Printf(\"The file was created %s\", humanize.Time(a).FromNow()) // =\u003e The file was created 5 days ago\n```\n\n##### Time to _x_\n\nThe same as [humanize.From](#time-from-x), but the opposite time difference.\n\n```go\na := time.Parse(..., \"2020-01-01\")\nb := time.Parse(..., \"2021-02-01\")\n\nfmt.Printf(\"It will happen %s\", humanize.Time(a).To(b)) // =\u003e It will happen in a year\n```\n\n##### Time to now\n\nA utility function like [humanize.FromNow](#time-from-now), which is like calling `Time(a).To(b)` where `b` is set to `time.Now()`\n\n```go\na := time.Parse(..., \"2021-05-05 22:10:00\")\n\nfmt.Printf(\"The plane will take off %s\", humanize.Time(a).ToNow()) // =\u003e The plane will take off in a minute\n```\n\n#### Exact time\n\nA more precise calculation of time, where all time units is included.\n\n##### Exact time from _x_\n\nTakes two time instances as input, to produce a string-representation of the exact difference in time.\n\n```go\na := time.Parse(..., \"2020-01-01 22:00:05\")\nb := time.Parse(..., \"2021-02-01 02:50:22\")\n\nfmt.Printf(\"It happened exactly %s\", humanize.ExactTime(a).From(b)) // =\u003e It happened exactly 1 year, 30 days, 4 hours, 45 minutes and 22 seconds ago\n```\n\n##### Exact time from now\n\nThis is a utility function, which is like calling `ExactTime(a).From(b)`, but where `b` is automatically set to `time.Now()`.\n\n```go\na := time.Parse(..., \"2021-06-06 22:05:05\")\n\nfmt.Printf(\"The file was deleted %s\", humanize.ExactTime(a).FromNow()) // =\u003e The file was deleted 5 minutes and 5 seconds ago\n```\n\n##### Exact time to _x_\n\nThe same as [humanize.From](#exact-time-from-x), but the opposite time difference.\n\n```go\na := time.Parse(..., \"2021-05-03 15:00:00\")\nb := time.Parse(..., \"2021-05-08 18:30:00\")\n\nfmt.Printf(\"It's my birthday %s\", humanize.ExactTime(a).To(b)) // =\u003e It's my birthday in 5 days, 3 hours and 30 minutes\n```\n\n##### Exact time to now\n\nA utility function like [humanize.FromNow](#exact-time-from-now), which is like calling `ExactTime(a).To(b)` where `b` is set to `time.Now()`\n\n```go\na := time.Parse(..., \"2021-03-02 12:00:33\")\n\nfmt.Printf(\"The train will depart %s\", humanize.ExactTime(a).ToNow()) // =\u003e The train will depart in 2 minutes and 33 seconds\n```\n---\n\n### Humanizing duration\n\n#### Estimated duration\n\nSimilar to [estimated time](#estimated-time), this is a loose calculation of given duration.\n\n```go\nfmt.Printf(\"My dog is %s old\", humanize.Duration(time.Hour * 24 * 68)) // =\u003e My dog is 2 months old\n```\n\u003cdetails\u003e\n\u003csummary\u003eAdditional examples of usage\u003c/summary\u003e\n\n```go\nhumanize.Duration(time.Hour * 24 * 38)  // =\u003e a month\nhumanize.Duration(time.Hour * 24 * 400) // =\u003e a year\nhumanize.Duration(time.Hour * 24 * 800) // =\u003e 2 years\n```\n\u003c/details\u003e\n\n#### Exact duration\n\nSimilar to [exact time](#exact-time), this is a strict and precise calculation of the given duration.\n\n```go\nfmt.Printf(\"The offer ends in %s\", humanize.ExactDuration(time.Hour * 70)) // =\u003e The offer ends in 2 days and 22 hours\n```\n\n\u003cdetails\u003e\n\u003csummary\u003eAdditional examples of usage\u003c/summary\u003e\n\n```go\nhumanize.ExactDuration(time.Hour * 70)                                // =\u003e 2 days and 22 hours\nhumanize.ExactDuration(time.Hour*3 + time.Minute*33 + time.Second*55) // =\u003e 3 hours, 33 minutes and 55 seconds\nhumanize.ExactDuration(time.Hour * 24 * 8)                            // =\u003e 8 days\n```\n\u003c/details\u003e\n\n---\n\n### Humanizing slices\n\nConverts a string slice into a comma-separated string list with an optional limit.\n\n```go\nfmt.Printf(\"I went to the zoo with %s\", humanize.Slice([]string{\"Noah\", \"Marc\"})) // =\u003e I went to the zoo with Noah and Marc\n```\n\n\u003cdetails\u003e\n\u003csummary\u003eAdditional examples of usage\u003c/summary\u003e\n\n```go\nhumanize.Slice([]string{\"Joe\"})                                // =\u003e Joe\nhumanize.Slice([]string{\"Joe\", \"Leslie\"})                      // =\u003e Joe and Leslie\nhumanize.Slice([]string{\"Joe\", \"Leslie\", \"Carl\"})              // =\u003e Joe, Leslie and Carl\nhumanize.Slice([]string{\"Joe\", \"Leslie\", \"Carl\"}, 2)           // =\u003e Joe, Leslie and one other\nhumanize.Slice([]string{\"Joe\", \"Leslie\", \"Carl\", \"Yvonne\"}, 2) // =\u003e Joe, Leslie and 2 others\nhumanize.Slice([]string{\"Joe\", \"Leslie\"}, 2)                   // =\u003e Joe and Leslie\n```\n\u003c/details\u003e\n\n---\n\n### Humanizing sizes\n\nTransforms byte-sizes into the closest related multi-byte unit size (MB, GB etc.)\n\n#### Bytes\n\nUses the SI prefixes (powers of `10`, e.g. `1000b = 1kB`) for converting the bytes into their human-readable representation.\n\n```go\nfmt.Printf(\"The size of 'cats.jpg' is %s\", humanize.Bytes(2500000)) // =\u003e The size of 'cats.jpg' is 2.5 MB \n```\n\n\u003cdetails\u003e\n\u003csummary\u003eAdditional examples of usage\u003c/summary\u003e\n\n```go\nhumanize.Bytes(2000000000)          // =\u003e 2.0 GB\nhumanize.Bytes(1000000000000)       // =\u003e 1.0 TB\nhumanize.Bytes(1000000000000000000) // =\u003e 1.0 EB\n```\n\u003c/details\u003e\n\n#### Binary bytes\n\nUses the binary system (powers of `2`, e.g. `1024b = 1KiB`) for converting the bytes into their human-readable representation.\n\n```go\nfmt.Printf(\"The size of 'dogs.jpg' is %s\", humanize.BinaryBytes(2500000)) // =\u003e The size of 'dogs.jpg' is 2.4 MiB\n```\n\n\u003cdetails\u003e\n\u003csummary\u003eAdditional examples of usage\u003c/summary\u003e\n\n```go\nhumanize.BinaryBytes(2500000)          // =\u003e 2.4 MiB\nhumanize.BinaryBytes(10000000)         // =\u003e 9.5 MiB\nhumanize.BinaryBytes(1000000000000000) // =\u003e 909 TiB\n```\n\u003c/details\u003e\n\n#### Short-form binary bytes\n\nUsing the same system as [binary bytes](#binary-bytes), but in a GNU-like format.\n\n```go\nfmt.Printf(\"vacation.zip | %s\", humanize.ShortFormBinaryBytes(1000000000000)) // =\u003e vacation.zip | 931G\n```\n\n\u003cdetails\u003e\n\u003csummary\u003eAdditional examples of usage\u003c/summary\u003e\n\n```go\nhumanize.ShortFormBinaryBytes(35324355)             // =\u003e 34M\nhumanize.ShortFormBinaryBytes(2000000000)           // =\u003e 1.9G\nhumanize.ShortFormBinaryBytes(13400000000000000000) // =\u003e 12E\n```\n\u003c/details\u003e\n\n---\n\n### Humanizing fractions\n\nTransforms a float value into a formatted human-readable fraction\n\n```go\nfmt.Printf(\"You can have %s of the cake\", humanize.Fraction(0.25)) // =\u003e You can have 1/4 of the cake\n```\n\n\u003cdetails\u003e\n\u003csummary\u003eAdditional examples of usage\u003c/summary\u003e\n\n```go\nhumanize.Fraction(2.625) // =\u003e 2 5/8\nhumanize.Fraction(0.5)   // =\u003e 1/2\nhumanize.Fraction(1.66)  // =\u003e 1 33/50\n```\n\u003c/details\u003e\n\n---\n\n### Humanizing fuzzy text\n\nSometimes, being able to print out information to the user, directly from a data structure, a key \nin a JSON object or similar, is nice, instead of redefining it all, word for word.\n\n#### Text\n\nFormats a fuzzy text as a common sentence, capitalizing the first letter of the first word, and lower-casing the rest.\n\n```go\nfmt.Print(humanize.FuzzyText(\"some-!!@@----Wierd_____format\")) // =\u003e Some wierd format\n```\n\n\u003cdetails\u003e\n\u003csummary\u003eAdditional examples of usage\u003c/summary\u003e\n\n```go\nhumanize.FuzzyText(\"my.key\")                  // =\u003e My key\nhumanize.FuzzyText(\"snake-case\")              // =\u003e Snake case\nhumanize.FuzzyText(\"a_text_with_underscores\") // =\u003e A text with underscores\n```\n\u003c/details\u003e\n\n#### Custom format\n\nExtracts words from a fuzzy text and constructs a string from the words, using the provided formatter on every extracted word.\nIf the formatter is `nil`, the words will be concatenated in their natural state.\n\n```go\nfmt.Printf(\"The receipt contains your %s\", humanize.FormatFuzzyText(\"customer__id\", strings.ToUpperCase)) // =\u003e The receipt contains your CUSTOMER ID\n```\n\n\u003cdetails\u003e\n\u003csummary\u003eAdditional examples of usage\u003c/summary\u003e\n\nWith custom formatter:\n```go\nmyCustomFormatter := func(index int, word string) {\n    if index == 1 {\n        return strings.ToUpperCase(word)\n    }\n\n    return strings.Title(word)\n}\n\nhumanize.FormatFuzzyText(\"app-id\", myCustomFormatter) // =\u003e App ID\n```\n\nWith pre-defined formatter:\n```go\nhumanize.FormatFuzzyText(\"app-id\", strings.Title) // =\u003e App Id\n```\n\n\u003c/details\u003e\n\n---\n\n### Humanizing numbers\n\nConverting small or larger numbers into a shorter form of the number to a human-friendly text representation\n\n#### Int\n\nConverts an integer into a readable string representation, rounding the volume and using the [names of large numbers](https://en.wikipedia.org/wiki/Names_of_large_numbers) as a suffix.\n\n```go\nfmt.Printf(\"I have %s followers\", humanize.Int(1589035)) // =\u003e I have 1.6 million followers\n```\n\n\u003cdetails\u003e\n\u003csummary\u003eAdditional examples of usage\u003c/summary\u003e\n\n```go\nhumanize.Int(999)      // =\u003e 999\nhumanize.Int(125000)   // =\u003e 125 thousand\nhumanize.Int(15600000) // =\u003e 15.6 million\n```\n\u003c/details\u003e\n\n#### Including symbol\n\nDoes the same calculations as [humanize.Int](#int), but returns the symbol identifier, rather than the fully translated suffix. E.g. `million = M`\n\n```go\nfmt.Printf(\"I have $%s on my bank account\", humanize.IntWithSymbol(785030)) // =\u003e I have $785K on my bank account\n```\n\n\u003cdetails\u003e\n\u003csummary\u003eAdditional examples of usage\u003c/summary\u003e\n\n```go\nhumanize.Int(999)      // =\u003e 999\nhumanize.Int(125000)   // =\u003e 125K\nhumanize.Int(15600000) // =\u003e 15.6M\n```\n\u003c/details\u003e\n\n## 🌍 Localization\n\n`humanize` comes prepacked with localization support, which are easily switchable on the fly.\n\n#### Switching locales\n\nTo use a different locale with `humanize`, simply import the locale you need, and register it.\nTo view a list of currently available locales, see [built-in locales](#built-in-locales).\n\n```go\nimport (\n\t\"github.com/imbue11235/humanize\"\n\t\"github.com/imbue11235/humanize/locale/da\"\n)\n\nfunc main() {\n\t// register the locale\n\thumanize.RegisterLocale(da.Code, da.Locale)\n\t\n\tnames := []string{\"Hans\", \"Viggo\", \"Klaus\"}\n\t\n\tfmt.Printf(\"Seen by %s\", humanize.Slice(names, 2)) // =\u003e Seen by Hans, Viggo and one other\n\t\n\t// switch the locale\n\thumanize.SetLocale(da.Code)\n\t\n\tfmt.Printf(\"Set af %s\", humanize.Slice(names, 2)) // =\u003e Set af Hans, Viggo og én anden\n}\n```\n\n#### Registering custom locale\n\nTo register your own custom locale, simply specify a `locale.Map` mimicking the same key-value format\nas the built-in locales. See [the english locale map](locale/en/locale.go) for additional details.\n\n```go\nhumanize.RegisterLocale(\"my-locale\", locale.Map{...})\n```\n#### Fallback locale\n\nIf the current selected locale does not support or define the translation needed, you can define a locale to fall back to. Make sure that the locale is registered beforehand or it will result in an error.\n\n```go\nhumanize.SetFallbackLocale(\"my-fallback-locale\")\n```\n\n#### Built-in locales\n\nCurrently, the following locales are included in the `humanize` package:\n\n- [Arabic](locale/ar/locale.go) - Thanks [@MohammadSaad1](https://github.com/MohammadSaad1)\n- [Danish](locale/da/locale.go)\n- [English](locale/en/locale.go)\n- [German](locale/de/locale.go)\n\n#### Contributing locales\n\nIf you find your language is not on the list, and you want to add it, please [submit a PR](https://github.com/imbue11235/humanize/pulls).\nIt would be greatly appreciated and help the package become even more usable across languages.\n\nList of wanted locales:\n\n- [ ] Dutch\n- [ ] Finnish\n- [ ] French\n- [ ] Italian\n- [ ] Japanese\n- [ ] Korean\n- [ ] Mandarin Chinese\n- [ ] Norwegian\n- [ ] Russian\n- [ ] Spanish\n- [ ] Swedish\n- [ ] Vietnamese\n- [ ] Add your own\n\n## 📜 License\n\nThis project is licensed under the [MIT license](LICENSE).\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fimbue11235%2Fhumanize","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fimbue11235%2Fhumanize","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fimbue11235%2Fhumanize/lists"}