{"id":16111130,"url":"https://github.com/mjpitz/units","last_synced_at":"2025-04-06T06:26:50.707Z","repository":{"id":176689090,"uuid":"655346845","full_name":"mjpitz/units","owner":"mjpitz","description":"Easily define and work with standard units of measurement.","archived":false,"fork":false,"pushed_at":"2025-02-08T16:31:55.000Z","size":53,"stargazers_count":1,"open_issues_count":2,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-02-08T17:29:23.279Z","etag":null,"topics":["go","golang","unit-conversion","units-of-measurement"],"latest_commit_sha":null,"homepage":"","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/mjpitz.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,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2023-06-18T16:11:57.000Z","updated_at":"2025-02-08T16:31:58.000Z","dependencies_parsed_at":null,"dependency_job_id":"7af13738-50b7-48ac-b240-cbeca9ab1c6a","html_url":"https://github.com/mjpitz/units","commit_stats":null,"previous_names":["mjpitz/units"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mjpitz%2Funits","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mjpitz%2Funits/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mjpitz%2Funits/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mjpitz%2Funits/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/mjpitz","download_url":"https://codeload.github.com/mjpitz/units/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247443853,"owners_count":20939756,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","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":["go","golang","unit-conversion","units-of-measurement"],"created_at":"2024-10-09T19:40:26.709Z","updated_at":"2025-04-06T06:26:50.690Z","avatar_url":"https://github.com/mjpitz.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# units\n\n`units` offers shared code for handling standard units of measurement. It takes inspiration from Golang's time library\nand applies similar ideas to other units of measure. This is achieved through a common declaration called a Unit,\nwhich organizes measurements in increasing order, often derived from a base unit. A Unit also facilitates parsing and\nformatting of measurements to improve computer use and human readability (respectively). To get a better understanding\nof its functioning, you can explore the provided packages for more specific information.\n\n```go\nimport \"go.pitz.tech/units\"\n```\n\n## Usage\n\n**Customize existing units**\n\nOne nice thing about the way this library works is that it gives you the ability to define your own custom units used\nto format and parse text. Using the existing `length` package, we can reduce the number of units down to the measures\nwe care about. Now, you can use this new unit to parse string text or format lengths as strings. For example, with\nballistics we seldom care about millimeters and decameters and instead focus on kilometer (range to target),\nmeter (size of target), and centimeter (drop of projectile). Similarly in the US, we think of this as yards (range to\ntarget), feet (size of target), and inches (drop of projectile).\n\n```go\npackage main\n\nimport \"go.pitz.tech/units/length\"\nimport \"go.pitz.tech/units\"\n\nvar (\n\tsimplified = units.Unit[length.Length]{\n\t\t{length.Centimeter, []string{\"cm\"}},\n\t\t{length.Meter, []string{\"m\"}},\n\t\t{length.Kilometer, []string{\"km\"}},\n\t}\n)\n```\n\n**Declare your own**\n\nIf customizing an existing unit isn't enough for you, then you can always look at declaring your own unit. For example,\nthe other day I learned that in x-ray astronomy, flux density can be measured using crabs or millicrabs. To illustrate\nhow we might define this using the units package, we can consider the following snippet.\n\n```go\npackage astronomy\n\nimport \"go.pitz.tech/units\"\n\ntype FluxDensity int64\n\nconst (\n\tMilliCrab FluxDensity = 1\n\tCrab FluxDensity = 1000 * MilliCrab\n)\n\nvar (\n\tStandard = units.Unit[Flux]{\n\t\t{MilliCrab, []string{\"??\"}},\n\t\t{Crab, []string{\"??\"}},\n\t}\n)\n```\n\nNow, I'm no astronomer so it's _entirely_ possible that these representative values are completely incorrect. However,\nthese values do illustrate how we can apply this library to other areas.\n\n## License\n\n```\nCopyright (c) 2023 Mya Pitzeruse\n\nPermission is hereby granted, free of charge, to any person obtaining a copy\nof this software and associated documentation files (the \"Software\"), to deal\nin the Software without restriction, including without limitation the rights\nto use, copy, modify, merge, publish, distribute, sublicense, and/or sell\ncopies of the Software, and to permit persons to whom the Software is\nfurnished to do so, subject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in all\ncopies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND,\nEXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF\nMERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.\nIN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,\nDAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR\nOTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE\nOR OTHER DEALINGS IN THE SOFTWARE.\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmjpitz%2Funits","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmjpitz%2Funits","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmjpitz%2Funits/lists"}