{"id":15286908,"url":"https://github.com/g7s/unit","last_synced_at":"2025-10-11T03:58:30.206Z","repository":{"id":44476604,"uuid":"241307906","full_name":"g7s/unit","owner":"g7s","description":"Clojure(Script) library for dealing with units and conversions","archived":false,"fork":false,"pushed_at":"2020-02-19T16:35:17.000Z","size":20,"stargazers_count":12,"open_issues_count":0,"forks_count":3,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-08-24T18:30:46.793Z","etag":null,"topics":["clojure","clojurescript","units-of-measurement"],"latest_commit_sha":null,"homepage":null,"language":"Clojure","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"epl-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/g7s.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","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":"2020-02-18T08:21:00.000Z","updated_at":"2025-05-16T22:37:20.000Z","dependencies_parsed_at":"2022-09-08T03:23:46.266Z","dependency_job_id":null,"html_url":"https://github.com/g7s/unit","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/g7s/unit","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/g7s%2Funit","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/g7s%2Funit/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/g7s%2Funit/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/g7s%2Funit/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/g7s","download_url":"https://codeload.github.com/g7s/unit/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/g7s%2Funit/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":279006110,"owners_count":26084027,"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","status":"online","status_checked_at":"2025-10-11T02:00:06.511Z","response_time":55,"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":["clojure","clojurescript","units-of-measurement"],"created_at":"2024-09-30T15:18:55.794Z","updated_at":"2025-10-11T03:58:30.166Z","avatar_url":"https://github.com/g7s.png","language":"Clojure","funding_links":[],"categories":[],"sub_categories":[],"readme":"# unit\n\n[![Clojars Project](https://img.shields.io/clojars/v/unit.svg)](https://clojars.org/unit)\n\nA Clojure(Script) library for dealing with units and conversions.\n\nFor some background on units see [here](https://g7s.io/post/units/)\n\n\n## Installation\n\nTo install, add the following to your project `:dependencies`:\n\n    [unit \"0.1.1\"]\n\n\n## Usage\n\nWith this library you can define, derive, convert and recognize units of measurement.\n\n### Definition\n\nDefine a unit with `make-unit` that has the form\n\n```clojure\n(make-unit dimensions slope y-intercept prefix?)\n```\n\nwhere `dimensions` is either a 7-element vector or a keyword from the [predefined dimensions](https://github.com/g7s/unit/blob/master/src/unit/core.cljc#L15)\n`slope` is a non-zero number representing the conversion factor to the reference unit,\n`y-intercept` is a number (usually 0 except for units like `Celcius` etc) and `prefix?`\na boolean that is true only when the unit accepts a prefix (defaults to `false`).\n\nAn example:\n\n```clojure\n(ns my.ns\n  (:require\n   [unit.core :refer [make-unit]))\n\n\n;; Taking the reference unit to be the kilogram\n\n(def gram (make-unit :mass 1e-3 0 true)\n(def pound (make-unit :mass 0.45359237))\n```\n\nIf your unit comes with a symbol it is better to use `defunit` (see [Recognition](#recognition))\n\n```clojure\n(defunit pound :lb (make-unit :mass 0.45359237))\n```\n\n### Derivation\n\nDeriving new units from other units is done with the functions\n\n* **mult** - For multiplying units\n* **div** - For dividing units\n* **exp** - For exponentiating a unit\n* **prefix** - For applying a prefix to a prefix accepting unit\n\nAn example:\n\n```clojure\n(def watt-per-sq-meter-kelvin (div watt (mult (exp meter 2) kelvin)))\n(def kcal-per-sq-foot-celsius-hour\n  (div (prefix calorie :k)\n       (mult (exp foot 2)\n             (mult hour celsius))))\n```\n\n\n### Conversion\n\nConvert a number (magnitude) from a unit to another using `convert` which has the form\n\n```clojure\n(convert magnitude unit-a unit-b)\n```\n\nwhere `magnitude` is the magnitude of a measurement expressed in `unit-a` units and\n`unit-b` is the target unit for the conversion.\n\nAn example:\n\n```clojure\n(convert 12 pound gram) ;; =\u003e 5443.10844\n```\n\nNote that `convert` will throw an exception if you try to convert between incompatible units\n(i.e. between units with different dimensions).\n\n\n### Recognition\n\nFor every unit that has been defined with `defunit` (see [Definition](#definition)) and therefore\nhas been associated with a symbol, you can use `to-unit` that takes a string and returns a\n(possibly prefixed) unit.\n\nAn example:\n\n```clojure\n(to-unit \"kJ\") ;; The kilojoule unit\n```\n\nNote that this will throw if it cannot find the unit symbol or if the recognised unit does not\naccept a prefix and you passed a prefix or if the prefix is not supported.\n\nExamples with exceptions\n\n```clojure\n(to-unit \"klb\") ;; Unit does not support prefix\n(to-unit \"rg\")  ;; Unrecognised prefix r\n(to-unit \"foo\") ;; Unrecognised unit\n```\n\nRecognition ends here, this library does not try to interpret an expression involving units in any way.\n\n\n## License\n\nCopyright © 2020 Gerasimos\n\nThis program and the accompanying materials are made available under the\nterms of the Eclipse Public License 2.0 which is available at\nhttp://www.eclipse.org/legal/epl-2.0.\n\nThis Source Code may also be made available under the following Secondary\nLicenses when the conditions for such availability set forth in the Eclipse\nPublic License, v. 2.0 are satisfied: GNU General Public License as published by\nthe Free Software Foundation, either version 2 of the License, or (at your\noption) any later version, with the GNU Classpath Exception which is available\nat https://www.gnu.org/software/classpath/license.html.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fg7s%2Funit","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fg7s%2Funit","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fg7s%2Funit/lists"}