{"id":20211,"library":"metrick","title":"Metrick","description":"Metrick is a Babel-powered unit conversion library (v0.2.0) that leverages the ES7 function bind syntax (::) for human-readable unit expressions. It supports duration (milliseconds, seconds, minutes, hours, years) and data (bits, bytes, kilobytes, megabytes, gigabytes, etc.) conversions with explicit (unit::unit.in(target)) and implicit (number::unit) syntax. The library requires the Babel plugin transform-function-bind and is designed for Node.js and browser environments. Alternatives like js-quantities or convert-units offer more units or simpler syntax but lack the syntactic sugar of the bind operator. Release cadence is low; last release was 2017.","status":"active","version":"0.2.0","language":"javascript","source_language":"en","source_url":"https://github.com/ticky/metrick","tags":["javascript","babel","babel-plugin-transform-function-bind","conversion","convert","data","distance","duration","imperial"],"install":[{"cmd":"npm install metrick","lang":"bash","label":"npm"},{"cmd":"yarn add metrick","lang":"bash","label":"yarn"},{"cmd":"pnpm add metrick","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"Required for the :: function bind syntax used throughout the library","package":"babel-plugin-transform-function-bind","optional":false}],"imports":[{"note":"Units are exported from subpath modules like 'metrick/duration' or 'metrick/data'; 'metrick' only exports the Unit class.","wrong":"import { seconds } from 'metrick'","symbol":"seconds","correct":"import { seconds } from 'metrick/duration'"},{"note":"Unit is the default export from 'metrick/unit'; named import from 'metrick' does not exist.","wrong":"import { Unit } from 'metrick'","symbol":"Unit","correct":"import Unit from 'metrick/unit'"},{"note":"CommonJS require is not recommended; library is primarily designed for ESM with Babel.","wrong":"const { megabytes } = require('metrick');","symbol":"megabytes","correct":"import { megabytes } from 'metrick/data'"}],"quickstart":{"code":"// Ensure babel-plugin-transform-function-bind is installed and configured in .babelrc\nimport { seconds, minutes, milliseconds } from 'metrick/duration';\nimport { megabytes, gigabytes } from 'metrick/data';\n\n// Explicit conversion\nconst msInMinute = 1::minutes.in(milliseconds);\nconsole.log(`1 minute = ${msInMinute} ms`); // 60000\n\n// Implicit conversion (defaults to SI base unit)\nconst bitsInMegabyte = 1::megabytes;\nconsole.log(`1 megabyte = ${bitsInMegabyte} bits`); // 8000000\n\n// Chain conversions\nconst gbInMb = 1::gigabytes.in(megabytes);\nconsole.log(`1 GB = ${gbInMb} MB`); // 1000\n\n// Create custom units\nimport Unit from 'metrick/unit';\nconst lux = new Unit();\nconst lumen = new Unit(10.7639::lux);\nconst brightness = 100::lumen.in(lux);\nconsole.log(`100 lumens = ${brightness} lux`); // 1076.39","lang":"typescript","description":"Demonstrates importing units, explicit conversion with ::x.in(y), implicit conversion to base unit, and creating custom units."},"warnings":[{"fix":"Replace 'transform-function-bind' with '@babel/plugin-proposal-function-bind' in .babelrc.","message":"Babel plugin transform-function-bind is deprecated in Babel 7+; use @babel/plugin-proposal-function-bind instead.","severity":"deprecated","affected_versions":">=0.2.0"},{"fix":"Always transpile code with Babel and the function bind plugin before running.","message":"The function bind syntax (::) is not supported in Node.js or browsers without Babel; code will fail to parse.","severity":"breaking","affected_versions":">=0.0.0"},{"fix":"Use correct subpath imports: import { seconds } from 'metrick/duration'.","message":"Importing from 'metrick' (index) only exports Unit class; unit modules are at subpaths like 'metrick/duration'.","severity":"gotcha","affected_versions":">=0.2.0"},{"fix":"Use 'metrick/data' for data units; note that megabyte = 1e6 bytes, not 2^20.","message":"Unit conversions use SI prefixes (e.g., kilograms = 1000 grams), not binary prefixes (e.g., kibibytes).","severity":"gotcha","affected_versions":">=0.2.0"}],"env_vars":null,"last_verified":"2026-04-25T00:00:00.000Z","next_check":"2026-07-24T00:00:00.000Z","problems":[{"fix":"Install and configure Babel with @babel/plugin-proposal-function-bind.","cause":"Using :: bind syntax without Babel plugin or in unsupported environment.","error":"SyntaxError: Unexpected token :"},{"fix":"Import from subpaths like 'metrick/duration' for unit functions.","cause":"Importing from 'metrick' when the package does not export units from the main entry.","error":"Module not found: Can't resolve 'metrick'"},{"fix":"Use the :: operator: 30::seconds.in(milliseconds) instead of 30.seconds.in(milliseconds).","cause":"Using .in on a number instead of a Unit object. The correct syntax is number::unit.in(targetUnit).","error":"TypeError: seconds.in is not a function"}],"ecosystem":"npm","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null}