Naivete Precedes Misrepresentation

    typesafe-units
    TypeScript icon, indicating that this package has built-in type declarations

    1.0.0 • Public • Published

    typesafe-units

    unit converter with focus on type-safety, simplicity and performance.

    Key Features

    Converting

    const converted = units.from(3, "cm").to("in");
    console.log(converted);
    // Output: 1.1811

    Comparing

    const c1 = units.Convertible(100, "kilometer");
    const c2 = units.Convertible(1000, "meter");
    
    if (c1.lt(c2)) {
        console.log(`${c1} is less than ${c2}!`);
    } else if (c1.eq(c2)) {
        console.log(`${c1} and ${c2} are equal!`);
    } else {
        console.log(`${c1} is greater than ${c2}!`);
    }
    // Output: 100km is greater than 1000m!

    Formatting

    const convertible = units.Convertible(12.2323123, "kt");
    console.log(convertible.format("%.2f %s", { length: "long" }));
    // Output: 12.23 knots

    Documentation

    Read useful guides here. Read the full documentation here.

    Supported Units

    Area

    unit synonyms %
    %0m² %0m^2, %0m2, square %0meter, sq %0meter, sq %0metre, square %0metre, square %0meters, sq %0meters, sq %0metres, square %0metres

    0: SI-Prefixes from y (yocto) to Y (yotta)

    %0a %0are, %0ares

    0: c(centiare), d(deciare), da(decare), h(hectare)

    in² ″², in^2, ″^2, ″2, in2, square inch, sq inch, square inches, sq inches -
    ft² ft^2, ft2, square foot, sq foot, square feet, sq feet -
    mi² mi^2, mi2, square mile, sq mile, square miles, sq miles -
    yd² yd^2, yd2, square yard, sq yard, square yards, sq yards -
    ac acre, acres -

    Current

    unit synonyms %
    %0A %0ampere, %0ampere

    0: SI-Prefixes from y (yocto) to Y (yotta)

    Digital

    unit synonyms %
    %0B %0byte, %0bytes

    0: SI-Prefixes from k(kilo) to Y (yotta) and IEC-Prefixes from Ki (kibi) to Yi (yobi)

    %0b %0bit, %0bits

    0: SI-Prefixes from k(kilo) to Y (yotta) and IEC-Prefixes from Ki (kibi) to Yi (yobi)

    Energy

    unit synonyms %
    %0J %0joule, %0joule, %0joules

    0: SI-Prefixes from y (yocto) to Y (yotta)

    %0W%1 %0watt-%1, %0watt-%1

    0: SI-Prefixes from y (yocto) to Y (yotta)

    1: h (hour, hours), s (second, seconds)

    %0eV %0electronvolt, %0electronvolts

    0: SI-Prefixes from y (yocto) to Y (yotta)

    %0cal %0calorie, %0calories

    0: k (kilo)

    erg ergs -

    Force

    unit synonyms %
    %0N %0newton

    0: SI-Prefixes from y (yocto) to Y (yotta)

    Length

    unit synonyms %
    %0m %0meter, %0meters, %0metre, %0metres

    0: SI-Prefixes from y (yocto) to Y (yotta)

    in ″, inch, inches -
    yd yard, yards -
    ly light-year, lightyear, light-years, lightyears -
    ft foot, feet -
    mi mi., mile, miles -

    Mass

    unit synonyms %
    %0g %0gram, %0gramme, %0grams

    0: SI-Prefixes from y (yocto) to Y (yotta)

    %0mt %0metric ton, %0metric tons

    0: SI-Prefixes from da (deca) to Y (yotta)

    t ton, short ton, tons, short tons -
    oz oz av, ounce, avoirdupois ounce, ounces, avoirdupois ounces -
    lb lb av, pound, avoirdupois pound, pound-mass, pounds, avoirdupois pounds -

    Parts-Per

    unit synonyms %
    ppm parts per million, part per million -
    ppb parts per billion, part per billion -
    ppt parts per trillion, part per trillion -
    ppq parts per quadrillion, part per quadrillion -

    Power

    unit synonyms %
    %0W %0watt, %0watts

    0: SI-Prefixes from μ (micro) to Y (yotta)

    %0J/%1 %0joule/%1, %0joules/%1

    0: SI-Prefixes from μ (micro) to Y (yotta)

    1: All time units.

    Pressure

    unit synonyms %
    %0Pa %0pascal, %0pascals

    0: SI-Prefixes from μ (micro) to Y (yotta)

    bar Bar, Bars -
    torr Torr, Torrs -
    atm standard atmosphere, standard atmospheres -
    Mpsi megapound per square inch, megapounds per square inch -
    psi lb. p. sq. in., psia, psig, pound-force per square inch, pound per square inch, pounds per square inch -
    ksi kilopound per square inch, kilopounds per square inch -
    inHg inch of mercury, inches of mercury -

    Speed

    unit synonyms %
    %0m/%1 %0meter/%1, %0metre/%1, %0meter per %1, %0metre per %1, %0meters/%1, %0metres/%1, %0meters per %1, %0metres per %1

    0: SI-Prefixes from y (yocto) to Y (yotta)

    1: Any time unit

    ft/%0 foot/%0, foot per %0, feet/%0, feet per %0

    0: Any time unit

    mi/%0 mp%0, mile/%0, mile per %0, miles/%0, miles per %0

    0: Any time unit

    kt kn, knot, knots -
    Bft Beaufort -
    Ma M, mach, Mach -
    c lightspeed, light-speed -

    Temperature

    unit synonyms %
    °C degree Celsius, degrees Celsius -
    °F degree Fahrenheit, degrees Fahrenheit -
    °R degree Rankine, degrees Rankine -
    K Kelvin -

    Time

    unit synonyms %
    %0s %0second, %0seconds

    0: SI-Prefixes from y (yocto) to d (deci)

    min minute, minutes -
    h hour, hours -
    d day, days -
    wk week, weeks -
    mth month, months -
    a year, years -

    Voltage

    unit synonyms %
    %0V %0volt, %0volts

    0: SI-Prefixes from y (yocto) to Y (yotta)

    Volume

    unit synonyms %
    %0m³ %0m^3, %0m3, cubic %0meter, cubic %0meters, cubic %0metre, cubic %0metres

    0: SI-Prefixes from y (yocto) to d (deci)

    %0l %0liter, %0liters, %0litre, %0litres

    0: SI-Prefixes from m (milli) to k (kilo)

    in³ ″³, in^3, ″^3, ″3, in3, cubic inch, cubic inches -
    ft³ ft^3, ft3, cubic foot, cubic feet -
    yd³ yd^3, yd3, cubic yard, cubic yards -
    c cup, cups -
    tsp teaspoon, teaspoons -
    tbsp tablespoon, tablespoons -
    fl oz fl-oz, fluid ounce, fluid ounces -
    qt quart, quarts -
    gal gallon, gallons -

    Install

    npm i typesafe-units

    DownloadsWeekly Downloads

    1

    Version

    1.0.0

    License

    MIT

    Unpacked Size

    835 kB

    Total Files

    190

    Last publish

    Collaborators

    • harrydehix