{"id":13397936,"url":"https://github.com/convert-units/convert-units","last_synced_at":"2025-04-25T14:21:54.537Z","repository":{"id":11917766,"uuid":"14483693","full_name":"convert-units/convert-units","owner":"convert-units","description":"An elegant way to convert quantities between different units.","archived":false,"fork":false,"pushed_at":"2025-01-02T17:46:43.000Z","size":877,"stargazers_count":816,"open_issues_count":21,"forks_count":304,"subscribers_count":26,"default_branch":"main","last_synced_at":"2025-04-24T06:55:26.529Z","etag":null,"topics":["conversion","convert","javascript","measure","quantities","units"],"latest_commit_sha":null,"homepage":"","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/convert-units.png","metadata":{"files":{"readme":"README.md","changelog":null,"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":"2013-11-18T05:40:08.000Z","updated_at":"2025-04-23T10:28:12.000Z","dependencies_parsed_at":"2024-03-07T20:27:12.008Z","dependency_job_id":"8a0603a5-a7e4-4477-893c-f02828f123bd","html_url":"https://github.com/convert-units/convert-units","commit_stats":{"total_commits":243,"total_committers":70,"mean_commits":"3.4714285714285715","dds":0.7942386831275721,"last_synced_commit":"b779334977a502016f0324a27ff214359e3429f5"},"previous_names":["ben-ng/convert-units"],"tags_count":26,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/convert-units%2Fconvert-units","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/convert-units%2Fconvert-units/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/convert-units%2Fconvert-units/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/convert-units%2Fconvert-units/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/convert-units","download_url":"https://codeload.github.com/convert-units/convert-units/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":250767873,"owners_count":21484046,"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":["conversion","convert","javascript","measure","quantities","units"],"created_at":"2024-07-30T18:01:55.085Z","updated_at":"2025-04-25T14:21:54.517Z","avatar_url":"https://github.com/convert-units.png","language":"TypeScript","readme":"convert-units\n=============\n\n[![Downloads](https://img.shields.io/npm/dm/convert-units.svg)](https://www.npmjs.com/package/convert-units)\n\nA handy utility for converting between quantities in different units.\n\nInstallation\n-----\n\n```bash\nnpm install convert-units --save\n```\n\n```bash\n# beta builds are also available with\nnpm install convert-units@beta --save\n```\n\nUsage\n-----\n\n`convert-units` has a simple chained API that is easy to read. It can also be configured with the measures that are packaged with it or custom measures.\n\nThe code snippet below shows everything needed to get going:\n\n```js\n// `allMeasures` includes all the measures packaged with this library\nimport configureMeasurements from 'convert-units';\nimport allMeasures from 'convert-units/definitions/all';\n\nconst convert = configureMeasurements(allMeasures);\n```\n\nIt's also possible to limit the measures configured. This allows for smaller packages when using a bundler like `webpack` or `rollup`:\n\n```js\nimport configureMeasurements from 'convert-units';\nimport volume from 'convert-units/definitions/volume';\n\n/*\n  `configureMeasurements` is a closure that accepts a directory\n  of measures and returns a factory function (`convert`) that uses\n  only those measures.\n*/\nconst convert = configureMeasurements({\n    volume,\n    mass,\n    length,\n});\n```\n\nConverting between units in a measure:\n\n```js\nconvert(1).from('l').to('ml');\n// 1000\n```\n\nConverting between systems is handled automatically (`imperial` to `metric` in this case):\n\n```js\nconvert(1).from('lb').to('kg');\n// 0.4536... (tested to 4 significant figures)\n```\n\nAttempting to convert between measures will result in an error:\n\n```js\nconvert(1).from('oz').to('fl-oz');\n// throws -- you can't go from mass to volume!\n```\n\nTo convert a unit to another unit within the same measure with the smallest value above `1`:\n\n```js\nconvert(12000).from('mm').toBest();\n// { val: 12, unit: 'm', ... }\n```\n\n\u003e Note: The `toBest` method is *subjective* and **does not work for all measures**.\n\nIf a *better* value is not found, then from unit is returned. This is also the case for zero:\n\n```js\nconvert(1).from('mm').toBest();\n// { val: 1, unit: 'mm', ... }\n\nconvert(0).from('mm').toBest();\n// { val: 0, unit: 'mm', ... }\n```\n\nExclude units to get different results:\n\n```js\nconvert(12000).from('mm').toBest({ exclude: ['m'] });\n// { val: 1200, unit: 'cm', ... } (the smallest unit excluding meters)\n```\n\nThe best is always the smallest number above `1`. If the value is a negative number, the best is always the largest number below `-1`. The cut off number of either `1` or `-1` can be changed to get different results:\n\n```js\nconvert(900).from('mm').toBest({ cutOffNumber: 10 });\n// { val: 90, unit: 'cm', ... } (the smallest unit with a value equal to or above 10)\n\nconvert(1000).from('mm').toBest({ cutOffNumber: 10 });\n// { val: 100, unit: 'cm', plural: 'Centimeters' } (the smallest unit with a value equal to or above 10)\n\n// by default the system of the origin is used, the `system` option overwrites this behaviour\nconvert(254).from('mm').toBest({ system: 'imperial' }); // ('mm' is metric)\n// { val: 10, unit: 'in', plural: 'Inches' }            // ('in' is imperial)\n```\n\nList all available measures:\n\n```js\nconvert().measures();\n// [ 'length', 'mass', 'volume', ... ]\n\nconst differentConvert = configureMeasurements({\n    volume,\n    mass,\n    length,\n    area,\n});\ndifferentConvert().measures();\n// [ 'length', 'mass', 'volume', 'area' ]\n```\n\nList all units that a given unit can be converted to:\n\n```js\nconvert().from('l').possibilities();\n// [ 'ml', 'l', 'tsp', 'Tbs', 'fl-oz', 'cup', 'pnt', 'qt', 'gal' ]\n\nconvert().from('kg').possibilities();\n// [ 'mcg', 'mg', 'g', 'kg', 'oz', 'lb' ]\n```\n\nList all units that belong to a measure:\n\n```js\nconvert().possibilities('mass');\n// [ 'mcg', 'mg', 'g', 'kg', 'oz', 'lb', 'mt', 't' ]\n```\n\nList all configured units:\n\n```js\nconvert().possibilities();\n// [ 'mm', 'cm', 'm', 'in', 'ft-us', 'ft', 'mi', 'mcg', 'mg', 'g', 'kg', 'oz', 'lb', 'mt', 't', 'ml', 'l', 'tsp', 'Tbs', 'fl-oz', 'cup', 'pnt', 'qt', 'gal', 'ea', 'dz' ];\n```\n\nGet a detailed description of a unit:\n\n```js\nconvert().describe('kg');\n/*\n  {\n    abbr: 'kg',\n    measure: 'mass',\n    system: 'metric',\n    singular: 'Kilogram',\n    plural: 'Kilograms',\n  }\n*/\n```\n\nList detailed descriptions of all units:\n\n```js\nconvert().list();\n/*\n  [{\n    abbr: 'kg',\n    measure: 'mass',\n    system: 'metric',\n    singular: 'Kilogram',\n    plural: 'Kilograms',\n  }, ...]\n*/\n```\n\nList detailed descriptions of all units for a measure:\n\n```js\nconvert().list('mass');\n/*\n  [{\n    abbr: 'kg',\n    measure: 'mass',\n    system: 'metric',\n    singular: 'Kilogram',\n    plural: 'Kilograms',\n  }, ...]\n*/\n```\n\nCustom Measures\n---------------\n\nTo create a custom measure, it's best to start with an plain object. The key itself will be used as the measure's name. In the example below, the measure's name is \"`customMeasure`\".\n\n\u003cdetails\u003e\n\u003csummary\u003eCode example:\u003c/summary\u003e\n\n```js\nconst measure = {\n  customMeasure: {},\n};\n```\n\u003c/details\u003e\n\nNext step is to create the measure's systems. A system is a collection of related units. Here are some examples of some common systems: metric, imperial, SI, bits, bytes, etc. You don't need to use one of these systems for your measure. In the example below, there are 3 systems defined: `A`, `B`, `C`.\n\n\u003cdetails\u003e\n\u003csummary\u003eCode example:\u003c/summary\u003e\n\n```js\nconst measure = {\n  customMeasure: {\n    systems: {\n      A: {},\n      B: {},\n      C: {},\n    }\n  },\n};\n```\n\u003c/details\u003e\n\nNow the measure is ready to define some units. The first unit that needs to be defined for each system is the base unit. The base unit is like all other units except that it's the unit used to convert between systems and every other unit in the system will be configured to convert directly to it. Below is an example of a base unit for the `A` system.\n\n\u003cdetails\u003e\n\u003csummary\u003eCode example:\u003c/summary\u003e\n\n```js\nconst measure = {\n  customMeasure: {\n    systems: {\n      A: {\n        a: {  // the name of the unit (commonly an abbreviation)\n          name: {  // human friendly names for the unit\n            singular: 'a',\n            plural: 'as',\n          },\n        }\n      },\n      // ignoring C \u0026 B for now\n    }\n  },\n};\n```\n\u003c/details\u003e\n\nEach unit also needs to a `to_anchor` property. `to_anchor` holds a number that represents the factor needed to go from another unit in the system to the base unit. In the case of the `a` unit, the value will be `1`. The value for all base units in every system should be `1` because if you convert `5 a` to `a` the result should be `5 a`. This is because the value of `to_anchor` is multiplied by the value of the unit being converted from. So in this case, `5 * 1 = 5`.\n\n\u003cdetails\u003e\n\u003csummary\u003eCode example:\u003c/summary\u003e\n\n```js\nconst measure = {\n  customMeasure: {\n    systems: {\n      A: {\n        a: {\n          name: {\n            singular: 'a',\n            plural: 'as',\n          },\n          to_anchor: 1,\n        }\n      },\n      // ignoring C \u0026 B for now\n    }\n  },\n};\n```\n\u003c/details\u003e\n\nAdding a second measure to the `A` measure looks exactly the same as the `a` unit except the `to_anchor` value will be different. If the unit is supposed to be larger than the base then the `to_anchor` value needs to be greater than `1`. For example, the new unit `ah` should be a factor of 10 larger than the base. This would mean that `1 ah` equals `10 a`. To make sure this assumption is correct multiply the `to_anchor` by the unit, `5 ah * 10 = 50 a`.\n\n\u003cdetails\u003e\n\u003csummary\u003eCode example:\u003c/summary\u003e\n\n```js\nconst measure = {\n  customMeasure: {\n    systems: {\n      A: {\n        ah: {  // new unit, ah\n          name: {\n            singular: 'ah',\n            plural: 'ahs',\n          },\n          to_anchor: 1e1,  // = 10 ^ 1 = 10\n        },\n        a: {\n          name: {\n            singular: 'a',\n            plural: 'as',\n          },\n          to_anchor: 1,\n        }\n      },\n      // ignoring C \u0026 B for now\n    },\n  },\n};\n```\n\u003c/details\u003e\n\nIf the unit should be smaller than the base unit then the `to_anchor` value should be less than `1` and greater than `0`. With that said, the new unit `al` should have a `to_anchor` value of `0.1`. This would mean that `10 al` would equal `1 a`.\n\n\u003cdetails\u003e\n\u003csummary\u003eCode example:\u003c/summary\u003e\n\n```js\nconst measure = {\n  customMeasure: {\n    systems: {\n      A: {\n        ah: {  // new unit, ah\n          name: {\n            singular: 'ah',\n            plural: 'ahs',\n          },\n          to_anchor: 1e1,  // = 10 ^ 1 = 10\n        },\n        a: {\n          name: {\n            singular: 'a',\n            plural: 'as',\n          },\n          to_anchor: 1,\n        }\n        al: {  // new unit, al\n          name: {\n            singular: 'al',\n            plural: 'als',\n          },\n          to_anchor: 1e-1,  // = 10 ^ -1 = 0.1\n        },\n      },\n      // ignoring C \u0026 B for now\n    },\n  },\n};\n```\n\u003c/details\u003e\n\nThere is one more option, `anchor_shift`, it can be defined on a unit if it requires to be shifted after the conversion. If `al` had an `anchor_shift` of `5` then `10 al` to `a` would look like, `10 * 0.1 - 5 = -4 a`. If the shift needs to go in the opposite direction then it should be a negative number. Typically, measures and units that use the `anchor_shift` only need to be shifted. If that is the desired effect then setting `to_anchor` to `1` for each unit will achieve that. To see a real world example, check out the `temperature` measure in the `definitions` folder.\n\n\u003cdetails\u003e\n\u003csummary\u003eCode example:\u003c/summary\u003e\n\n```js\nconst measure = {\n  customMeasure: {\n    systems: {\n      A: {\n        ah: {  // new unit, ah\n          name: {\n            singular: 'ah',\n            plural: 'ahs',\n          },\n          to_anchor: 1e1,  // = 10 ^ 1 = 10\n        },\n        a: {\n          name: {\n            singular: 'a',\n            plural: 'as',\n          },\n          to_anchor: 1,\n        }\n        al: {  // new unit, al\n          name: {\n            singular: 'al',\n            plural: 'als',\n          },\n          to_anchor: 1e-1,  // = 10 ^ -1 = 0.1\n          anchor_shift: 5,\n        },\n      },\n      // ignoring C \u0026 B for now\n    }\n  },\n};\n```\n\u003c/details\u003e\n\nAt this point if the custom measure only needs one system then it's done! However, if it requires more than one system, an extra step is required. In the example code below, the previously ignored systems `C` and `B` have been defined to look exactly like the `A` system.\n\n\u003cdetails\u003e\n\u003csummary\u003eCode example:\u003c/summary\u003e\n\n```js\nconst measure = {\n  customMeasure: {\n    systems: {\n      A: {\n        ah: {\n          name: {\n            singular: 'ah',\n            plural: 'ahs',\n          },\n          to_anchor: 1e1,\n        },\n        a: {\n          name: {\n            singular: 'a',\n            plural: 'as',\n          },\n          to_anchor: 1,\n        },\n        al: {\n          name: {\n            singular: 'al',\n            plural: 'als',\n          },\n          to_anchor: 1e-1,\n        },\n      },\n      B: {\n        bh: {\n          name: {\n            singular: 'bh',\n            plural: 'bhs',\n          },\n          to_anchor: 1e1,\n        },\n        b: {\n          name: {\n            singular: 'b',\n            plural: 'bs',\n          },\n          to_anchor: 1,\n        },\n        bl: {\n          name: {\n            singular: 'bl',\n            plural: 'bls',\n          },\n          to_anchor: 1e-1,\n        },\n      },\n      C: {\n        ch: {\n          name: {\n            singular: 'ch',\n            plural: 'chs',\n          },\n          to_anchor: 1e1,\n        },\n        c: {\n          name: {\n            singular: 'c',\n            plural: 'cs',\n          },\n          to_anchor: 1,\n        },\n        cl: {\n          name: {\n            singular: 'cl',\n            plural: 'cls',\n          },\n          to_anchor: 1e-1,\n        },\n      },\n    },\n  }\n};\n```\n\u003c/details\u003e\n\nThe measure now has three systems, `A`, `B`, and `C`. To define how each system can be converted to the other, anchors will needs to be defined for each possible conversion. To start, add the key `anchors` to the `customMeasure` object:\n\n\u003cdetails\u003e\n\u003csummary\u003eCode example:\u003c/summary\u003e\n\n```js\nconst measure = {\n  customMeasure: {\n    systems: {\n      // ...\n    },\n    anchors: {},\n  }\n};\n```\n\u003c/details\u003e\n\nThen just like for the `systems` object, add a key for each system with it's value being an empty object:\n\n\u003cdetails\u003e\n\u003csummary\u003eCode example:\u003c/summary\u003e\n\n```js\nconst measure = {\n  customMeasure: {\n    systems: {\n      // ...\n    },\n    anchors: {\n      A: {},\n      B: {},\n      C: {},\n    },\n  }\n};\n```\n\u003c/details\u003e\n\nIn each of those empty objects, add keys for the other systems which their values being an empty object. The measure should look like the code snippet below:\n\n\u003cdetails\u003e\n\u003csummary\u003eCode example:\u003c/summary\u003e\n\n```js\nconst measure = {\n  customMeasure: {\n    systems: {\n      // ...\n    },\n    anchors: {\n      A: {  // A to B or C\n        B: {},\n        C: {},\n      },\n      B: {  // B to A or C\n        A: {},\n        C: {},\n      },\n      C: {  // C to A or B\n        A: {},\n        B: {},\n      },\n    },\n  }\n};\n```\n\u003c/details\u003e\n\nWhen converting, for example, `1 a` to `bl`, the code can perform a simple lookup here, `anchors.A.B`. If instead, the conversion is from `10 c` to `ah` then the lookup would be, `anchors.C.A`. At this point how to convert from one system to the next hasn't been defined yet; that will be the next and final step in creating a new measure.\n\nEach system pair needs to either defined a `ratio` or a `transform` function. If a `ratio` is defined then it's multiplied by the base unit to convert it to the target system's base unit. If `transform` is defined, the function is called with the value of the best unit. It's value is used as the base unit of the target system. The `transform` function should return a number.\n\n\u003e Note: If both `ratio` and `transform` are defined then the `ratio` will be used and the `transform` function will be ignored. If neither is defined, the conversion will throw an error.\n\n\u003cdetails\u003e\n\u003csummary\u003eCode example:\u003c/summary\u003e\n\n```js\nconst measure = {\n  customMeasure: {\n    systems: {\n      // ...\n    },\n    anchors: {\n      A: {  // A to B or C\n        B: {\n          ratio: 2,\n        },\n        C: {\n          ratio: 3,\n        },\n      },\n      B: {  // B to A or C\n        A: {\n          ratio: 1 / 2,\n        },\n        C: {\n          ratio: 3 / 2,\n        },\n      },\n      C: {  // C to A or B\n        A: {\n          // example of using a transform function\n          // This would be the same as ratio: 1 / 3\n          transform: value =\u003e value * 1 / 3,\n        },\n        B: {\n          transform: value =\u003e value * 2 / 3,\n        },\n      },\n    },\n  }\n};\n```\n\u003c/details\u003e\n\nWith the above example, converting `10 cl` to `ah` would result in `0.0333` (rounded).\n\n\u003cdetails\u003e\n\u003csummary\u003eHere is the complete measure:\u003c/summary\u003e\n\n```js\nconst measure = {\n  customMeasure: {\n    systems: {\n      A: {\n        ah: {\n          name: {\n            singular: 'ah',\n            plural: 'ahs',\n          },\n          to_anchor: 1e1,\n        },\n        a: {\n          name: {\n            singular: 'a',\n            plural: 'as',\n          },\n          // to_anchor: The factor used to reach the base unit\n          // The base unit should have a to_anchor value of 1\n          // Eg. 1 a -\u003e al = 1a * 1e-1 (to_anchor of al) = 10 al\n          to_anchor: 1,\n        },\n        al: {\n          name: {\n            singular: 'al',\n            plural: 'als',\n          },\n          to_anchor: 1e-1,\n        },\n      },\n      B: {\n        bh: {\n          name: {\n            singular: 'bh',\n            plural: 'bhs',\n          },\n          to_anchor: 1e1,\n        },\n        b: {\n          name: {\n            singular: 'b',\n            plural: 'bs',\n          },\n          to_anchor: 1,\n        },\n        bl: {\n          name: {\n            singular: 'bl',\n            plural: 'bls',\n          },\n          to_anchor: 1e-1,\n        },\n      },\n      C: {\n        ch: {\n          name: {\n            singular: 'ch',\n            plural: 'chs',\n          },\n          to_anchor: 1e1,\n        },\n        c: {\n          name: {\n            singular: 'c',\n            plural: 'cs',\n          },\n          to_anchor: 1,\n        },\n        cl: {\n          name: {\n            singular: 'cl',\n            plural: 'cls',\n          },\n          to_anchor: 1e-1,\n        },\n      },\n    },\n    anchors: {\n      A: {\n        // unit a -\u003e unit b\n        B: {\n          ratio: 2,\n        },\n        // unit a -\u003e unit c\n        C: {\n          ratio: 3,\n        },\n      },\n      B: {\n        // unit b -\u003e unit a\n        A: {\n          ratio: 1 / 2,\n        },\n        // unit b -\u003e unit c\n        C: {\n          ratio: 3 / 2,\n        },\n      },\n      C: {\n        // unit c -\u003e unit a\n        A: {\n          ratio: 1 / 3,\n        },\n        // unit c -\u003e unit b\n        B: {\n          ratio: 2 / 3,\n        },\n      },\n    },\n  }\n};\n\nconst convert = configureMeasurements(measure);\nconvert(1).from('a').to('bl')\n// 20\n```\n\u003c/details\u003e\n\n\u003cdetails\u003e\n\u003csummary\u003ePseudo code that shows the maths involved when converting a unit\u003c/summary\u003e\n\n```js\n// a -\u003e bl\nlet v = 1  // 1 a\nlet a_to_anchor = 1  // systems.A.a.to_anchor\nlet r = v * a_to_anchor\n// r = 1 a\nlet ratio = 2  // anchors.A.B.ratio\nr *= ratio\n// r = 2 b\nlet bl_to_anchor = 1e-1  // systems.B.bl.to_anchor\nr /= b_to_anchor\n// r = 20 bl\n```\n\u003c/details\u003e\n\n## Extending Existing Measures\n\nSince measure definitions are plain JS objects, additional units can be added, removed, and changed.\n\n\u003cdetails\u003e\n\u003csummary\u003eExample of extending the `length` measure\u003c/summary\u003e\n\n```ts\nimport configureMeasurements, {\n  Measure\n} from 'convert-units';\n\nimport\n  length, {\n  LengthSystems,\n  LengthUnits,\n} from \"convert-units/definitions/length\"\n\ntype NewLengthUnits = LengthUnits | 'px';\nconst DPI = 96;\nconst extendedLength: Measure\u003cLengthSystems, NewLengthUnits\u003e = {\n  systems: {\n    metric: {\n      ...length.systems.metric,\n      px: {\n        name: {\n          singular: 'Pixel',\n          plural: 'Pixels',\n        },\n        to_anchor: 0.0254 / DPI,\n      },\n    },\n    imperial: {\n      ...length.systems.imperial,\n    },\n  },\n  anchors: {\n    ...length.anchors,\n  },\n};\n\nconst convert = configureMeasurements\u003c'length', LengthSystems, NewLengthUnits\u003e(\n  { length: extendedLength }\n);\n\nconvert(4).from('cm').to('px');\n// 151.18110236220474\n```\n\u003c/details\u003e\n\nMigrating from v2 to v3+\n-----------------------\n\nThis only applies if moving from `\u003c=2.3.4` to `\u003e=3.x`.\n \n`index.js`\n```js\nimport convert from 'convert-units';\n\nconvert(1).from('m').to('mm');\nconvert(1).from('m').to('ft');\n```\n\nThe code above could be changed to match the following:\n\n`index.js`\n```js\nimport convert from './convert';  // defined below\n\nconvert(1).from('m').to('mm');\nconvert(1).from('m').to('ft');\n```\n\n`convert.js`\n```js\nimport configureMeasurements from 'convert-units';\nimport allMeasures from 'convert-units/definitions/all';  \n\nexport default configureMeasurements(allMeasures);\n```\n\nTypescript\n----------\n\nThe library provides types for all packaged mesasures:\n\n```ts\nimport configureMeasurements from 'convert-units';\n\nimport length, {\n  LengthSystems,\n  LengthUnits,\n} from \"convert-units/definitions/length\"\n\nimport area, {\n  AreaSystems,\n  AreaUnits,\n} from \"convert-units/definitions/area\"\n\n// Measures: The names of the measures being used\ntype Measures = 'length' | 'area';\n// Systems: The systems being used across all measures\ntype Systems = LengthSystems | AreaSystems;\n// Units: All the units across all measures and their systems\ntype Units = LengthUnits | AreaUnits;\n\nconst convert = configureMeasurements\u003cMeasures, Systems, Units\u003e({\n  length,\n  area,\n});\n\nconvert(4).from('m').to('cm');\n// 400\n```\n\nThis also allows for IDE tools to highlight issues before running the application:\n\n```ts\nimport configureMeasurements from 'convert-units';\n\nimport length, {\n  LengthSystems,\n  LengthUnits,\n} from \"convert-units/definitions/length\"\n\nimport area, {\n  AreaSystems,\n  AreaUnits,\n} from \"convert-units/definitions/area\"\n\n// Measures: The names of the measures being used\ntype Measures = 'length' | 'area';\n// Systems: The systems being used across all measures\ntype Systems = LengthSystems | AreaSystems;\n// Units: All the units across all measures and their systems\ntype Units = LengthUnits | AreaUnits;\n\nconst convert = configureMeasurements\u003cMeasures, Systems, Units\u003e({\n  length,\n  area,\n});\n\nconvert(4).from('wat').to('cm');\n// Typescript will warn that the unit `wat` does not exist because it's not a member of the `Units` type defined above.\n```\n\nTypes for the `allMeasures` object are also provided:\n\n```js\nimport configureMeasurements from 'convert-units';\n\nimport allMeasures, {\n  AllMeasures,\n  AllMeasuresSystems,\n  AllMeasuresUnits,\n} from 'convert-units/definitions/all';\n\nconst convertAll = configureMeasurements\u003c\n  AllMeasures,\n  AllMeasuresSystems,\n  AllMeasuresUnits\n\u003e(allMeasures);\n\nconvertAll(4).from('m2').to('cm2');\n// 400000\n```\n\nRequest Measures \u0026 Units\n-----------------------\n\nAll new measures and additional units are welcome! Take a look at [`src/definitions`](https://github.com/convert-units/convert-units/tree/main/src/definitions) to see some examples.\n\nPackaged Units\n--------------\n\u003cdetails\u003e\n\u003csummary\u003eLength\u003c/summary\u003e\n* nm\n* μm\n* mm\n* cm\n* m\n* km\n* in\n* yd\n* ft-us\n* ft\n* fathom\n* mi\n* nMi\n\u003c/details\u003e\n\n\u003cdetails\u003e\n\u003csummary\u003eArea\u003c/summary\u003e\n* mm2\n* cm2\n* m2\n* ha\n* km2\n* in2\n* ft2\n* ac\n* mi2\n\u003c/details\u003e\n\n\u003cdetails\u003e\n\u003csummary\u003eMass\u003c/summary\u003e\n* mcg\n* mg\n* g\n* kg\n* oz\n* lb\n* mt\n* st\n* t\n\u003c/details\u003e\n\n\u003cdetails\u003e\n\u003csummary\u003eVolume\u003c/summary\u003e\n* mm3\n* cm3\n* ml\n* l\n* kl\n* Ml\n* Gl\n* m3\n* km3\n* tsp\n* Tbs\n* in3\n* fl-oz\n* cup\n* pnt\n* qt\n* gal\n* ft3\n* yd3\n\u003c/details\u003e\n\n\u003cdetails\u003e\n\u003csummary\u003eVolume Flow Rate\u003c/summary\u003e\n* mm3/s\n* cm3/s\n* ml/s\n* cl/s\n* dl/s\n* l/s\n* l/min\n* l/h\n* kl/s\n* kl/min\n* kl/h\n* m3/s\n* m3/min\n* m3/h\n* km3/s\n* tsp/s\n* Tbs/s\n* in3/s\n* in3/min\n* in3/h\n* fl-oz/s\n* fl-oz/min\n* fl-oz/h\n* cup/s\n* pnt/s\n* pnt/min\n* pnt/h\n* qt/s\n* gal/s\n* gal/min\n* gal/h\n* ft3/s\n* ft3/min\n* ft3/h\n* yd3/s\n* yd3/min\n* yd3/h'\n\u003c/details\u003e\n\n\u003cdetails\u003e\n\u003csummary\u003eTemperature\u003c/summary\u003e\n* C\n* F\n* K\n* R\n\u003c/details\u003e\n\n\u003cdetails\u003e\n\u003csummary\u003eTime\u003c/summary\u003e\n* ns\n* mu\n* ms\n* s\n* min\n* h\n* d\n* week\n* month\n* year\n\u003c/details\u003e\n\n\u003cdetails\u003e\n\u003csummary\u003eFrequency\u003c/summary\u003e\n* Hz\n* mHz\n* kHz\n* MHz\n* GHz\n* THz\n* rpm\n* deg/s\n* rad/s\n\u003c/details\u003e\n\n\u003cdetails\u003e\n\u003csummary\u003eSpeed\u003c/summary\u003e\n* m/s\n* km/h\n* mph\n* knot\n* ft/s\n* in/h\n* mm/h\n\u003c/details\u003e\n\n\u003cdetails\u003e\n\u003csummary\u003eTorque\u003c/summary\u003e\n* Nm\n* lbf-ft\n\u003c/details\u003e\n\n\n\n\u003cdetails\u003e\n\u003csummary\u003ePace\u003c/summary\u003e\n* s/m\n* min/km\n* s/ft\n* min/mi\n\u003c/details\u003e\n\n\u003cdetails\u003e\n\u003csummary\u003ePressure\u003c/summary\u003e\n* Pa\n* hPa\n* kPa\n* MPa\n* bar\n* torr\n* mH2O\n* mmHg\n* psi\n* ksi\n\u003c/details\u003e\n\n\u003cdetails\u003e\n\u003csummary\u003eDigital\u003c/summary\u003e\n* bit\n* byte\n* kB\n* MB\n* GB\n* TB\n* KiB\n* MiB\n* GiB\n* TiB\n\u003c/details\u003e\n\n\u003cdetails\u003e\n\u003csummary\u003eIlluminance\u003c/summary\u003e\n* lx\n* ft-cd\n\u003c/details\u003e\n\n\u003cdetails\u003e\n\u003csummary\u003eParts-Per\u003c/summary\u003e\n* ppm\n* ppb\n* ppt\n* ppq\n\u003c/details\u003e\n\n\u003cdetails\u003e\n\u003csummary\u003eVoltage\u003c/summary\u003e\n* V\n* mV\n* kV\n\u003c/details\u003e\n\n\u003cdetails\u003e\n\u003csummary\u003eCurrent\u003c/summary\u003e\n* A\n* mA\n* kA\n\u003c/details\u003e\n\n\u003cdetails\u003e\n\u003csummary\u003ePower\u003c/summary\u003e\n* W\n* mW\n* kW\n* MW\n* GW\n* PS\n* Btu/s\n* ft-lb/s\n* hp\n\u003c/details\u003e\n\n\u003cdetails\u003e\n\u003csummary\u003eApparent Power\u003c/summary\u003e\n* VA\n* mVA\n* kVA\n* MVA\n* GVA\n\u003c/details\u003e\n\n\u003cdetails\u003e\n\u003csummary\u003eReactive Power\u003c/summary\u003e\n* VAR\n* mVAR\n* kVAR\n* MVAR\n* GVAR\n\u003c/details\u003e\n\n\u003cdetails\u003e\n\u003csummary\u003eEnergy\u003c/summary\u003e\n* Ws\n* Wm\n* Wh\n* mWh\n* kWh\n* MWh\n* GWh\n* J\n* kJ\n* MJ\n* GJ\n\u003c/details\u003e\n\n\u003cdetails\u003e\n\u003csummary\u003eReactive Energy\u003c/summary\u003e\n* VARh\n* mVARh\n* kVARh\n* MVARh\n* GVARh\n\u003c/details\u003e\n\n\u003cdetails\u003e\n\u003csummary\u003eAngle\u003c/summary\u003e\n* deg\n* rad\n* grad\n* arcmin\n* arcsec\n\u003c/details\u003e\n\n\u003cdetails\u003e\n\u003csummary\u003eCharge\u003c/summary\u003e\n* c\n* mC\n* μC\n* nC\n* pC\n\u003c/details\u003e\n\n\u003cdetails\u003e\n\u003csummary\u003eForce\u003c/summary\u003e\n* N\n* kN\n* lbf\n* kgf\n\u003c/details\u003e\n\n\u003cdetails\u003e\n\u003csummary\u003eAcceleration\u003c/summary\u003e\n* g (g-force)\n* m/s2\n* g0 (Standard Gravity)\n\u003c/details\u003e\n\n\u003cdetails\u003e\n\u003csummary\u003ePieces\u003c/summary\u003e\n* pcs\n* bk-doz\n* cp\n* doz-doz\n* doz\n* gr-gr\n* gros \n* half-dozen\n* long-hundred\n* ream\n* scores\n* sm-gr\n* trio\n\u003c/details\u003e\n\n\nLicense\n-------\nCopyright (c) 2013-2017 Ben Ng and Contributors, http://benng.me\n\nPermission is hereby granted, free of charge, to any person\nobtaining a copy of this software and associated documentation\nfiles (the \"Software\"), to deal in the Software without\nrestriction, including without limitation the rights to use,\ncopy, modify, merge, publish, distribute, sublicense, and/or sell\ncopies of the Software, and to permit persons to whom the\nSoftware is furnished to do so, subject to the following\nconditions:\n\nThe above copyright notice and this permission notice shall be\nincluded in all copies 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\nOF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND\nNONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT\nHOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,\nWHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING\nFROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR\nOTHER DEALINGS IN THE SOFTWARE.\n","funding_links":[],"categories":["JavaScript","TypeScript"],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fconvert-units%2Fconvert-units","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fconvert-units%2Fconvert-units","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fconvert-units%2Fconvert-units/lists"}