{"id":17004808,"url":"https://github.com/clickermonkey/unitz","last_synced_at":"2025-03-22T16:30:49.316Z","repository":{"id":57386514,"uuid":"60782228","full_name":"ClickerMonkey/unitz","owner":"ClickerMonkey","description":"A unit parser, converter, \u0026 combiner in JS: '1 cup' + '1.5 pint' = '1 quart`","archived":false,"fork":false,"pushed_at":"2018-10-01T01:28:34.000Z","size":369,"stargazers_count":36,"open_issues_count":0,"forks_count":3,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-03-20T08:45:02.038Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"http://clickermonkey.github.io/unitz/","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/ClickerMonkey.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2016-06-09T14:44:48.000Z","updated_at":"2024-07-03T21:01:17.000Z","dependencies_parsed_at":"2022-08-30T20:01:21.782Z","dependency_job_id":null,"html_url":"https://github.com/ClickerMonkey/unitz","commit_stats":null,"previous_names":[],"tags_count":7,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ClickerMonkey%2Funitz","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ClickerMonkey%2Funitz/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ClickerMonkey%2Funitz/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ClickerMonkey%2Funitz/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ClickerMonkey","download_url":"https://codeload.github.com/ClickerMonkey/unitz/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":244986337,"owners_count":20542999,"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":[],"created_at":"2024-10-14T04:44:31.097Z","updated_at":"2025-03-22T16:30:49.016Z","avatar_url":"https://github.com/ClickerMonkey.png","language":"JavaScript","readme":"This library is no longer maintained, and has been replaced by [unitz-ts](https://github.com/ClickerMonkey/unitz-ts)\n\n# Unitz\n\n[![Build Status](https://travis-ci.org/ClickerMonkey/unitz.svg?branch=master)](https://travis-ci.org/ClickerMonkey/unitz)\n[![devDependency Status](https://david-dm.org/ClickerMonkey/unitz/dev-status.svg)](https://david-dm.org/ClickerMonkey/unitz#info=devDependencies)\n[![Dependency Status](https://david-dm.org/ClickerMonkey/unitz.svg)](https://david-dm.org/ClickerMonkey/unitz)\n[![License](https://img.shields.io/badge/license-MIT-blue.svg)](https://github.com/ClickerMonkey/unitz/blob/master/LICENSE)\n[![Alpha](https://img.shields.io/badge/State-Alpha-orange.svg)]()\n\nUnitz is a library designed to take in a quantity and unit provided by a user and perform addition, subtraction, conversion, and transformation to human friendly representations.\nUnitz will attempt to handle conversions, additions, and subtractions even if the units aren't recognized.\n\n### Documentation\n\nhttp://clickermonkey.github.io/unitz/\n\n### Installation\n\nInstall via `bower install unitz` or `npm install unitz`.\n\nSeveral classes are implemented - you can even add your own:\n- Area\n- Digital\n- Length\n- Rotation\n- Time\n- Volume\n- Weight\n\nFurther down this document provides a detailed list of all units supported.\n\n### Examples\n\n```javascript\n// =============================================================================\n// Unitz.parse( input )\n// =============================================================================\n\n// Valid numbers: 1, 1/2, 1 1/2, 3/2, 1.5, .5, -1 1/2, -1.5, -.5\nUnitz.parse('2c'); /*{\n  value: 2,\n  unit: 'c',\n  normal: '2 cups',\n  unitClass: ... // Unitz.Class instance\n  group: ... // Unitz.Group instance\n}*/\n\n// =============================================================================\n// Unitz.parse( input ).convert( toUnit, returnFraction, withUnit, largestDenominator, classlessDenominators )\n// =============================================================================\n\nUnitz.parse('2c').convert('tbsp'); // 32\nUnitz.parse('2 cup').convert('tbsp', false, true); // '32 tbsp'\nUnitz.parse('4 tbsps').convert('cups', true); // {numerator: 1, denominator: 4, string: '1/4', remainder: 1, whole: 0, actual: 0.25, distance: 0, valid: true}\nUnitz.parse('4 tbsps').convert('cups', true).string; // '1/4'\nUnitz.parse('3 cups').convert('pint', true).string; // '1 1/2 pints'\n\n// =============================================================================\n// Unitz.parse( input ).best()\n// Unitz.best( input )\n// =============================================================================\n\nUnitz.parse('2c').best().normal; // '1 pint'\nUnitz.best('12in').normal; // '1 foot'\nUnitz.best('1/4 cup').normal; // '2 fluid ounces'\n\n// =============================================================================\n// Unitz.compound( input, unitsAllowed )\n// =============================================================================\n\nUnitz.compound('2 cups', ['pt', 'c']); // '1 pt'\nUnitz.compound('2 cups', ['c', 'tbsp']); // '2 c'\nUnitz.compound('0.625 cups', ['c', 'tbsp', 'tsp']); // '1/2 c, 2 tbsp'\nUnitz.compound('1.342 cups', ['c', 'tbsp', 'tsp']); // '1 c, 5 tbsp, 1 tsp'\n\n// =============================================================================\n// Unitz.combine( a, b, useFractions, abbreviations, largestDenominator )\n// =============================================================================\n\nUnitz.combine( '1 cup', '2 cups' ); // '3 cups'\nUnitz.combine( '1 pint', '2 cup' ); // '1 quart'\nUnitz.combine( '2 bags, 2 cup', '1 pint, 1 bag' ); // '3 bags, 1 quart'\n// units that don't exist, but they look similar enough to intelligibly join (looks at first X characters) and intelligibly guess the correct singular/plural form.\nUnitz.combine( '1 loaf', '2 loaves' ); // '3 loaves'\nUnitz.combine( '2, 3, 4', '1 taco' ); // '10 taco'\nUnitz.combine( '2, 3 tacos, 4', '1 taco' ); // '10 tacos'\n\n// =============================================================================\n// Unitz.subtract( a, b, allowNegatives, useFractions, abbreviations, largestDenominator )\n// =============================================================================\n\nUnitz.subtract( '2 bags, 3 pints', '1 bag, 1 quart' ); // '1 bag, 1 pint'\n\n// =============================================================================\n// Unitz.conversions( input, largestDenominator, min, max );\n// =============================================================================\n\nUnitz.conversions( '1.5 quarts' ); /* Unitz.Parsed with conversions: Unitz.Conversion\n  conversions[0]\n    decimal: 288\n    fraction: Unitz.Fraction\n    friendly: 288\n    group: Unitz.Group\n    longNormal: \"288 teaspoons\"\n    longUnit: \"teaspoons\"\n    shortNormal: \"288 tsp\"\n    shortUnit: \"tsp\"\n  ...\n  conversions[3]\n    decimal: 6\n    fraction: Unitz.Fraction\n    friendly: 6\n    group: Unitz.Group\n    longNormal: \"6 cups\"\n    longUnit: \"cups\"\n    shortNormal: \"6 c\"\n    shortUnit: \"c\"\n  ...\n  conversions[6]\n    decimal: 0.375\n    fraction: Unitz.Fraction\n    friendly: \"3/8\"\n    group: Unitz.Group\n    longNormal: \"3/8 gallons\"\n    longUnit: \"gallons\"\n    shortNormal: \"3/8 gal\"\n    shortUnit: \"gal\"\n*/\n```\n\n## Classes\n\n### Volume\n- `['tsp', 'ts', 'tsps', 'teaspoon', 'teaspoons']`\n- `['tbsp', 'tbsps', 'tablespoon', 'tablespoons']`\n- `['oz', 'ounce', 'ounces', 'fl-oz', 'fl oz', 'floz', 'fluid ounce', 'fl. oz.', 'oz. fl.', 'oz fl']`\n- `['c', 'cup', 'cups']`\n- `['pt', 'pint', 'pints']`\n- `['qt', 'quart', 'quarts']`\n- `['gal', 'gallon', 'gallons']`\n- `['ml', 'millilitre', 'millilitres', 'milliliter', 'milliliters']`\n- `['l', 'litre', 'litres', 'liter', 'liters']`\n- `['cl', 'centilitre', 'centilitres', 'centiliter', 'centiliters']`\n- `['dl', 'decalitre', 'decalitres', 'decaliter', 'decaliters']`\n- `['kl', 'kilolitre', 'kilolitres', 'kiloliter', 'kiloliters']`\n- `['mm3', 'mm^3', 'cubic mm', 'cubic millimeter', 'cubic millimeters']`\n- `['cm3', 'cm^3', 'cubiccmm', 'cubic centimeter', 'cubic centimeters']`\n- `['m3', 'm^3', 'cubic m', 'cubic meter', 'cubic meters']`\n- `['km3', 'km^3', 'cubic km', 'meter', 'meters']`\n- `['in3', 'in^3', 'cubic in', 'cubic inch', 'cubic inches']`\n- `['ft3', 'ft^3', 'cubic ft', 'cubic foot', 'cubic feet']`\n- `['yd3', 'yd^3', 'cubic yd', 'cubic yard', 'cubic yards']`\n\n### Weight\n- `['mg', 'milligram', 'milligrams']`\n- `['g', 'gram', 'grams']`\n- `['kg', 'kilogram', 'kilograms', 'kilo', 'kilos']`\n- `['oz', 'ounce', 'ounces']`\n- `['lb', 'lbs', 'pound', 'pounds']`\n- `['ton', 'tons', 'tonnes']`\n\n### Length\n- `['in', 'inch', 'inches', '\"']`\n- `['ft', 'foot', 'feet', \"'\"]`\n- `['yd', 'yds', 'yard', 'yards']`\n- `['mi', 'mile', 'miles']`\n- `['league', 'leagues']`\n- `['mm', 'millimeter', 'millimeters']`\n- `['cm', 'centimeter', 'centimeters']`\n- `['dc', 'decimeter', 'decimeters']`\n- `['m', 'meter', 'meters']`\n- `['km', 'kilometer', 'kilometers']`\n\n### Time\n- `['ns', 'nanosecond', 'nanoseconds', 'nano', 'nanos']`\n- `['us', 'microsecond', 'microseconds', 'micros', 'micro']`\n- `['ms', 'millisecond', 'milliseconds', 'millis']`\n- `['s', 'second', 'seconds', 'sec', 'secs']`\n- `['min', 'minute', 'minutes', 'mins']`\n- `['hr', 'hour', 'hours', 'hrs']`\n- `['day', 'days']`\n- `['wk', 'week', 'weeks', 'wks']`\n- `['yr', 'year', 'years', 'yrs']`\n\n### Area\n- `['sqin', 'sq. in.', 'sq in', 'in2', 'in^2', 'square inch', 'square inches']`\n- `['sqft', 'sq. ft.', 'sq ft', 'ft2', 'ft^2', 'square foot', 'square feet']`\n- `['sqyd', 'sq. yd.', 'sq yd', 'yd2', 'yd^2', 'square yard', 'square yards']`\n- `['acre', 'acres']`\n- `['sqmi', 'sq. mi.', 'sq mi', 'mi2', 'mi^2', 'square mile', 'square miles']`\n- `['sqmm', 'sq. mm.', 'sq mm', 'mm2', 'mm^2', 'square millimeter', 'square millimeters']`\n- `['sqcm', 'sq. cm.', 'sq cm', 'cm2', 'cm^2', 'square centimeter', 'square centimeters']`\n- `['sqm', 'sq. m.', 'sq m', 'm2', 'm^2', 'square meter', 'square meters']`\n- `['sqkm', 'sq. km.', 'sq km', 'km2', 'km^2', 'square kilometer', 'square kilometers']`\n\n### Digital\n- `['bit', 'bits']`\n- `['nibble', 'nibbles']`\n- `['b', 'byte', 'bytes']`\n- `['kb', 'kilobyte', 'kilobytes']`\n- `['mb', 'megabyte', 'megabytes']`\n- `['gb', 'gigabyte', 'gigabytes']`\n- `['tb', 'terabyte', 'terabytes']`\n- `['pb', 'petabyte', 'petabytes']`\n- `['eb', 'exabyte', 'exabytes']`\n- `['kbit', 'kilobit', 'kilobits']`\n- `['mbit', 'megabit', 'megabits']`\n- `['gbit', 'gigabit', 'gigabits']`\n- `['tbit', 'terabit', 'terabits']`\n- `['pbit', 'petabit', 'petabits']`\n- `['ebit', 'exabit', 'exabits']`\n\n### Rotation\n- `['deg', 'degs', 'degree', 'degrees']`\n- `['rad', 'rads', 'radian', 'radians']`\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fclickermonkey%2Funitz","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fclickermonkey%2Funitz","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fclickermonkey%2Funitz/lists"}