{"id":26127748,"url":"https://github.com/mongoose13/fling-units","last_synced_at":"2025-04-13T17:22:55.255Z","repository":{"id":278188431,"uuid":"934784147","full_name":"mongoose13/fling-units","owner":"mongoose13","description":"A type-safe Dart library for unit conversion","archived":false,"fork":false,"pushed_at":"2025-04-08T05:20:00.000Z","size":643,"stargazers_count":0,"open_issues_count":3,"forks_count":1,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-04-08T06:25:17.475Z","etag":null,"topics":["converter","unit-conversion","unit-conversions","unit-converter","unit-converters"],"latest_commit_sha":null,"homepage":"","language":"Dart","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"bsd-3-clause","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/mongoose13.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":"CONTRIBUTING.md","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":"2025-02-18T11:57:22.000Z","updated_at":"2025-02-23T16:31:38.000Z","dependencies_parsed_at":"2025-02-18T13:39:08.498Z","dependency_job_id":"d3a7f695-3e51-4228-beb7-62295e93bdd8","html_url":"https://github.com/mongoose13/fling-units","commit_stats":null,"previous_names":["mongoose13/fling-units"],"tags_count":59,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mongoose13%2Ffling-units","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mongoose13%2Ffling-units/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mongoose13%2Ffling-units/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mongoose13%2Ffling-units/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/mongoose13","download_url":"https://codeload.github.com/mongoose13/fling-units/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248750872,"owners_count":21155797,"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":["converter","unit-conversion","unit-conversions","unit-converter","unit-converters"],"created_at":"2025-03-10T18:37:11.126Z","updated_at":"2025-04-13T17:22:55.234Z","avatar_url":"https://github.com/mongoose13.png","language":"Dart","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Fling Units\r\n\r\n![Fling logo](https://f000.backblazeb2.com/file/mongoose-website/fling-title.png)\r\n\r\nA type safe Dart library for unit conversion. Pass around fully abstracted\r\nmeasurements to keep your code simple!\r\n\r\n![Pub Version](https://img.shields.io/pub/v/fling_units)\r\n![Pub Points](https://img.shields.io/pub/points/fling_units)\r\n[![Codacy Badge](https://app.codacy.com/project/badge/Grade/397a576a0c2144439f2901bd6f933be4)](https://app.codacy.com/gh/mongoose13/fling-units/dashboard?utm_source=bb\u0026utm_medium=referral\u0026utm_content=\u0026utm_campaign=Badge_grade)\r\n\r\n## Version 3.x changes a lot of things! If you are migrating from 2.x to 3.x, check the [migration guide](https://github.com/mongoose13/fling-units/wiki/Migration-Guide-2.x-to-3.x) for advice\r\n\r\n## Overview\r\n\r\nWe designed **fling_units** to simplify working with any measurement unit within\r\na code base by abstracting measurements to basic types that can be \"interpreted\"\r\ninto any valid unit of that type, all in a type-safe way. This means you will\r\nnever pass around a measurement of the wrong type or unit again without seeing\r\nred squiggles in your IDE.\r\n\r\nHave a look at the examples below for more details on what is possible, and let\r\nus know how we can improve **fling_units** by creating an issue!\r\n\r\n## Philosophy\r\n\r\n### Design goals\r\n\r\n- **Simplicity**: Casual users must be able to pick up the basic features. We\r\n  prefer idiomatic approaches since users will already have experience with\r\n  them. The library will not offer confusing or difficult options.\r\n\r\n- **Safety**: We will protect against invalid or incorrect usage. We favor\r\n  compile-time checks over runtime checks. If something is possible with the\r\n  library, it must be valid in the real world.\r\n\r\n- **Correctness**: Conversions must be accurate. The limiting factor in accuracy\r\n  is the measurement itself, not the library. Bug fixes take top priority. Full\r\n  test coverage is required.\r\n\r\n- **Minimalism**: We will not depend on larger libraries or other difficult\r\n  dependencies. Including the library into a project must be easy and must not\r\n  require any configuration or complicated setup.\r\n\r\n### Things that matter less\r\n\r\n- **Performance**: While we will not try to make the library slower than it\r\n  needs to be, we will not make small performance enhancements at the cost of\r\n  other design goals.\r\n\r\n- **Memory**: We will not reduce memory footprint at the cost of one of the\r\n  other design goals, but we will keep the library as small and unobtrusive as\r\n  possible.\r\n\r\n## Further documentation\r\n\r\nFor additional documentation, check the [project wiki](https://github.com/mongoose13/fling-units/wiki).\r\n\r\n## Usage\r\n\r\nCreate a measurement using any standard unit:\r\n\r\n```dart\r\n  // extensions on `num` make instantiating a measurement feel natural\r\n  var massOfTheMoon = (73.5).yocto.grams;\r\n\r\n  double timeInHours = 3.4;\r\n  var travelTime = timeInHours.hours;\r\n\r\n  // you can also build a measurement by \"calling\" a unit or building a sum of parts\r\n  var energyProduction = milli.amperes(123.4);\r\n  var distanceToTheMoon = sum([miles(238900), feet(42), inches(6.3)]);\r\n```\r\n\r\nConvert measurements to any other measurement type within that dimension easily:\r\n\r\n```dart\r\n  var distanceToTheMoonAsMiles = distanceToTheMoon.butAs(miles);\r\n  var massOfTheMoonAsShortTons = massOfTheMoon.butAs(shortTons);\r\n```\r\n\r\nYou can read the `double` value of any measurement using any unit in the same dimension:\r\n\r\n```dart\r\n  double distanceToTheMoonInMiles = distanceToTheMoon.as(miles);\r\n  double massOfTheMoonInShortTons = massOfTheMoon.as(shortTons);\r\n```\r\n\r\nPerform basic arithmetic:\r\n\r\n```dart\r\n  // multiplication\r\n  var distanceToTheMoonAndBack = distanceToTheMoon * 2;\r\n\r\n  // addition\r\n  var distanceToTheMoon = distanceToUpperAtmosphere + distanceFromAtmosphereToMoon;\r\n\r\n  // support for infinite measurements\r\n  var distanceToTheEndsOfTheUniverse = DistanceMeasurement.infinite();\r\n\r\n  // compare measurements within the same dimension\r\n  bool useTheCar = distanceToTravel \u003e= miles(1.5);\r\n```\r\n\r\nAll measurements have built-in ordering within their dimension:\r\n\r\n```dart\r\n  [zero(meters), infinite(inches), meters(3), feet(3), yards(-2)].sort();\r\n  // produces [yards(-2), zero(meters), feet(3), meters(3), infinite(inches)]\r\n```\r\n\r\nAbstract away the specific units your code needs by passing around the\r\nencapsulated types. It doesn't matter which units different parts of your code\r\nrequire; you can combine them seamlessly:\r\n\r\n```dart\r\nMeasurement\u003cDistance\u003e computeTotalDistanceWithWiggleRoom(Measurement\u003cDistance\u003e targetDistance) {\r\n  return targetDistance + meters(3.0);\r\n}\r\n```\r\n\r\nYou can create derived units (with all the features you'd expect) from existing units:\r\n\r\n```dart\r\n  // create a derived unit from any existing units:\r\n  var milesPerGallon = miles.per.gallon;\r\n\r\n  // instantiate measurements using the new unit the same way you would any other unit:\r\n  var stateRequiredFuelEconomy = milesPerGallon(20);\r\n\r\n  // you can also instantiate a measurement by providing the component parts of the measurement:\r\n  var fuelEconomy = milesPerGallon.using(kilo.meters(100), liters(6));\r\n\r\n  // or, if you're using the same units the derivative was defined with, just their values:\r\n  var yourFuelEconomy = milesPerGallon(50 /*miles*/, 2 /*gallons*/);\r\n\r\n  // measurements created this way have all the features of any other measurement, such as comparison operators:\r\n  bool switchCars = fuelEconomy \u003c stateRequiredFuelEconomy;\r\n\r\n  // extensions on num exist for the derived unit helper methods, too (inverse, ratio, product, square, cubic):\r\n  var frequency = 2000.inverse(seconds);\r\n```\r\n\r\nEnsure type safety at compile time:\r\n\r\n```dart\r\n  // none of these lines will compile:\r\n  var nonsense = miles(123) + grams(18);\r\n  var impossible = meters(3).as(celsius);\r\n  var silliness = grams(5) \u003c seconds(3);\r\n```\r\n\r\nExpress the certainty in your measurements by setting a precision. Conversions\r\nwill automatically provide appropriate significant digits. Set the precision\r\nwhen you create the measurement, or later on:\r\n\r\n```dart\r\n  var myHeight = meters(1.5, precision: 2);\r\n  double myHeightInInches = myHeight.as(inches); // 59.0\r\n  \r\n  var myWeight = kilo.grams(61.234);\r\n  double myPreciseWeight = myWeight.withPrecision(3); // 61.2\r\n```\r\n\r\nUse the `equals` method for less restrictive equality checks that read more naturally,\r\neven if the measurements' precisions differ:\r\n\r\n```dart\r\n  var massOfMyPetRock = 500.grams.withPrecision(3);\r\n  var anotherWayToWriteIt = (0.5).kilo.grams.withPrecision(1);\r\n\r\n  massOfMyPetRock == anotherWayToWriteIt; // false\r\n  massOfMyPetRock.equals(anotherWayToWriteIt); // true\r\n```\r\n\r\nMeasurements and units alike produce sensible `toString()` output to facilitate debugging:\r\n\r\n```dart\r\nvoid main() {\r\n  print(3.miles); // \"3.0 mi\"\r\n  print(kilo.meters); // \"km\"\r\n  print(miles.per.hour(2.0)); // \"2.0 mi⋅h⁻¹\"\r\n}\r\n```\r\n\r\n## Supported Features\r\n\r\n### Operations\r\n\r\nWith some exceptions (due to the nature of those measurements), all measurements\r\nsupport:\r\n\r\n- all standard metric prefixes for each unit\r\n- customizable precision for each measurement\r\n- `Comparable` for built-in ordering among similar measurements\r\n- compare two similar measurements (`\u003e`, `\u003c`, `==`, `!=`, `\u003e=`, `\u003c=`)\r\n- add or subtract two similar measurements (`+`, `-`)\r\n- multiply or divide measurements by a scalar (`*`, `/`)\r\n- negate measurements (unary `-`)\r\n- measurement comparisons (`~/`, `%`, `compareMagnitude`)\r\n- visitor pattern compatible\r\n- extensions on *num* for more natural instantiation\r\n\r\n### SI Prefixes\r\n\r\nWork with any unit:\r\n\r\n- quecto\r\n- ronto\r\n- yocto\r\n- zepto\r\n- atto\r\n- femto\r\n- pico\r\n- nano\r\n- micro\r\n- milli\r\n- centi\r\n- deci\r\n- deka\r\n- hecto\r\n- kilo\r\n- mega\r\n- giga\r\n- tera\r\n- peta\r\n- exa\r\n- zetta\r\n- yotta\r\n- ronna\r\n- quetta\r\n\r\n### Distance Units\r\n\r\n- meters\r\n- inches\r\n- feet\r\n- yards\r\n- miles\r\n- nautical miles\r\n\r\n### Area Units\r\n\r\n- [any Distance unit] x [any Distance unit]\r\n\r\n### Volume Units\r\n\r\n- liters\r\n- teaspoon (Imperial / US)\r\n- tablespoon (Imperial / US)\r\n- fluid ounce (Imperial / US)\r\n- cup (Imperial / US / US Legal)\r\n- pint (Imperial / US)\r\n- quart (Imperial / US)\r\n- gallon (Imperial / US)\r\n- cubic foot\r\n- cubic inch\r\n- [any Distance unit] x [any Distance unit] x [any Distance unit]\r\n\r\n### Temperature Units\r\n\r\n- kelvin\r\n- celsius\r\n- fahrenheit\r\n\r\n### Time units\r\n\r\n- seconds\r\n- minutes\r\n- hours\r\n- days\r\n\r\n### Mass units\r\n\r\n- grams\r\n- tonnes\r\n- ounces\r\n- pounds\r\n- short (US) tons\r\n- long (UK) tons\r\n- atomic mass units\r\n- daltons\r\n- electron rest mass\r\n\r\n### Electric Charge units\r\n\r\n- amperes\r\n\r\n### Luminous Intensity units\r\n\r\n- candela\r\n- candlepower\r\n- Hefnerkerze\r\n\r\n### Pressure units\r\n\r\n- Pascals\r\n- bars\r\n- Baryes\r\n- standard atmospheres\r\n- technical atmospheres\r\n- mmHg\r\n- inHg\r\n- PSI\r\n\r\n### Angle units\r\n\r\n- turns (rotations)\r\n- radians\r\n- gradians\r\n- degrees\r\n- arc minutes\r\n- arc seconds\r\n\r\n### Frequency units\r\n\r\n- hertz","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmongoose13%2Ffling-units","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmongoose13%2Ffling-units","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmongoose13%2Ffling-units/lists"}