Registry / serialization / metrick

metrick

JSON →
library0.2.0jsnpmunverified

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.

npm install metrick
INSTALL
IMPORT
SIG · METRICK
M
metrick
serializationjavascriptv0.2.0
Install
Import
Disk
Pass rate
0/ 6
Env Coverage0 / 6
glibc
1822
musl
1822
Install & Compatibility
Where this runs
tested against v? · npm install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
node 18226 runs
build_error
glibc
node 18226 runs
build_error
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

seconds
import { seconds } from 'metrick/duration'
import { seconds } from 'metrick'
Units are exported from subpath modules like 'metrick/duration' or 'metrick/data'; 'metrick' only exports the Unit class.
Unit
import Unit from 'metrick/unit'
import { Unit } from 'metrick'
Unit is the default export from 'metrick/unit'; named import from 'metrick' does not exist.
megabytes
import { megabytes } from 'metrick/data'
const { megabytes } = require('metrick');
CommonJS require is not recommended; library is primarily designed for ESM with Babel.

Demonstrates importing units, explicit conversion with ::x.in(y), implicit conversion to base unit, and creating custom units.

// Ensure babel-plugin-transform-function-bind is installed and configured in .babelrc import { seconds, minutes, milliseconds } from 'metrick/duration'; import { megabytes, gigabytes } from 'metrick/data'; // Explicit conversion const msInMinute = 1::minutes.in(milliseconds); console.log(`1 minute = ${msInMinute} ms`); // 60000 // Implicit conversion (defaults to SI base unit) const bitsInMegabyte = 1::megabytes; console.log(`1 megabyte = ${bitsInMegabyte} bits`); // 8000000 // Chain conversions const gbInMb = 1::gigabytes.in(megabytes); console.log(`1 GB = ${gbInMb} MB`); // 1000 // Create custom units import Unit from 'metrick/unit'; const lux = new Unit(); const lumen = new Unit(10.7639::lux); const brightness = 100::lumen.in(lux); console.log(`100 lumens = ${brightness} lux`); // 1076.39
Debug
Known issues
deprecatedBabel plugin transform-function-bind is deprecated in Babel 7+; use @babel/plugin-proposal-function-bind instead.
fix
Replace 'transform-function-bind' with '@babel/plugin-proposal-function-bind' in .babelrc.
affects: >=0.2.0
breakingThe function bind syntax (::) is not supported in Node.js or browsers without Babel; code will fail to parse.
fix
Always transpile code with Babel and the function bind plugin before running.
affects: >=0.0.0
gotchaImporting from 'metrick' (index) only exports Unit class; unit modules are at subpaths like 'metrick/duration'.
fix
Use correct subpath imports: import { seconds } from 'metrick/duration'.
affects: >=0.2.0
gotchaUnit conversions use SI prefixes (e.g., kilograms = 1000 grams), not binary prefixes (e.g., kibibytes).
fix
Use 'metrick/data' for data units; note that megabyte = 1e6 bytes, not 2^20.
affects: >=0.2.0
Errors
Common errors & fixes
SyntaxError: Unexpected token :
Using :: bind syntax without Babel plugin or in unsupported environment.
fix
Install and configure Babel with @babel/plugin-proposal-function-bind.
Module not found: Can't resolve 'metrick'
Importing from 'metrick' when the package does not export units from the main entry.
fix
Import from subpaths like 'metrick/duration' for unit functions.
TypeError: seconds.in is not a function
Using .in on a number instead of a Unit object. The correct syntax is number::unit.in(targetUnit).
fix
Use the :: operator: 30::seconds.in(milliseconds) instead of 30.seconds.in(milliseconds).
Upgrade
Version history
0.2.0latest on npm
Audit
Dependencies
babel-plugin-transform-function-bindrequiredRequired for the :: function bind syntax used throughout the library
Agent activity
6 hits · last 30 days
node
6
Resources
metrick — npm install metrick · libregistry