How to use the js-quantities.getUnits function in js-quantities

To help you get started, we’ve selected a few js-quantities examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github DefinitelyTyped / DefinitelyTyped / js-quantities / js-quantities-tests.ts View on Github external
qty = Qty(1.5); // number as initializing value

qty = Qty('1 attoparsec/microfortnight');

let qtyCopy: Qty;

qtyCopy = Qty(qty); // quantity could be copied when used as initializing value

Qty.parse('1 m'); // => 1 meter
Qty.parse('foo'); // => null

Qty.getKinds(); // => Array of names of every well-known kind of units

Qty.getUnits('currency'); // => [ 'dollar', 'cents' ]
// Or all alphabetically sorted
Qty.getUnits(); // => [ 'acre','Ah','ampere','AMU','angstrom']

Qty.getAliases('m'); // => [ 'm', 'meter', 'meters', 'metre', 'metres' ]

const qty1 = Qty('1m');
const qty2 = Qty('2m');

qty1.isCompatible(qty2); // => true or false

qty.kind(); // => 'length', 'area', etc...

qty.isUnitless(); // => true or false
qty.isBase(); // => true if quantity is represented with base units

qty.toBase(); // converts to SI units (10 cm => 0.1 m) (new instance)

qty.toFloat(); // returns scalar of unitless quantity (otherwise throws error)
github DefinitelyTyped / DefinitelyTyped / types / js-quantities / js-quantities-tests.ts View on Github external
qty = Qty('1.5'); // unitless quantity
qty = Qty(1.5); // number as initializing value

qty = Qty('1 attoparsec/microfortnight');

let qtyCopy: Qty;

qtyCopy = Qty(qty); // quantity could be copied when used as initializing value

Qty.parse('1 m'); // => 1 meter
Qty.parse('foo'); // => null

Qty.getKinds(); // => Array of names of every well-known kind of units

Qty.getUnits('currency'); // => [ 'dollar', 'cents' ]
// Or all alphabetically sorted
Qty.getUnits(); // => [ 'acre','Ah','ampere','AMU','angstrom']

Qty.getAliases('m'); // => [ 'm', 'meter', 'meters', 'metre', 'metres' ]

const qty1 = Qty('1m');
const qty2 = Qty('2m');

qty1.isCompatible(qty2); // => true or false

qty.kind(); // => 'length', 'area', etc...

qty.isUnitless(); // => true or false
qty.isBase(); // => true if quantity is represented with base units

qty.toBase(); // converts to SI units (10 cm => 0.1 m) (new instance)
github DefinitelyTyped / DefinitelyTyped / js-quantities / js-quantities-tests.ts View on Github external
qty = Qty('1.5'); // unitless quantity
qty = Qty(1.5); // number as initializing value

qty = Qty('1 attoparsec/microfortnight');

let qtyCopy: Qty;

qtyCopy = Qty(qty); // quantity could be copied when used as initializing value

Qty.parse('1 m'); // => 1 meter
Qty.parse('foo'); // => null

Qty.getKinds(); // => Array of names of every well-known kind of units

Qty.getUnits('currency'); // => [ 'dollar', 'cents' ]
// Or all alphabetically sorted
Qty.getUnits(); // => [ 'acre','Ah','ampere','AMU','angstrom']

Qty.getAliases('m'); // => [ 'm', 'meter', 'meters', 'metre', 'metres' ]

const qty1 = Qty('1m');
const qty2 = Qty('2m');

qty1.isCompatible(qty2); // => true or false

qty.kind(); // => 'length', 'area', etc...

qty.isUnitless(); // => true or false
qty.isBase(); // => true if quantity is represented with base units

qty.toBase(); // converts to SI units (10 cm => 0.1 m) (new instance)
github DefinitelyTyped / DefinitelyTyped / types / js-quantities / js-quantities-tests.ts View on Github external
qty = Qty(1.5); // number as initializing value

qty = Qty('1 attoparsec/microfortnight');

let qtyCopy: Qty;

qtyCopy = Qty(qty); // quantity could be copied when used as initializing value

Qty.parse('1 m'); // => 1 meter
Qty.parse('foo'); // => null

Qty.getKinds(); // => Array of names of every well-known kind of units

Qty.getUnits('currency'); // => [ 'dollar', 'cents' ]
// Or all alphabetically sorted
Qty.getUnits(); // => [ 'acre','Ah','ampere','AMU','angstrom']

Qty.getAliases('m'); // => [ 'm', 'meter', 'meters', 'metre', 'metres' ]

const qty1 = Qty('1m');
const qty2 = Qty('2m');

qty1.isCompatible(qty2); // => true or false

qty.kind(); // => 'length', 'area', etc...

qty.isUnitless(); // => true or false
qty.isBase(); // => true if quantity is represented with base units

qty.toBase(); // converts to SI units (10 cm => 0.1 m) (new instance)

qty.toFloat(); // returns scalar of unitless quantity (otherwise throws error)
github DefinitelyTyped / DefinitelyTyped / types / js-quantities / js-quantities-tests.ts View on Github external
it("should return an array of units of kind", () => {
      expect(Qty.getUnits("currency")).toContain("dollar");
    });
    it("should return an array of all units without arg", () => {
github DefinitelyTyped / DefinitelyTyped / js-quantities / js-quantities-tests.ts View on Github external
it("should return an array of all units without arg", () => {
      expect(Qty.getUnits()).toContain("sievert");
    });
    it("should throw unknown kind", () => {
github DefinitelyTyped / DefinitelyTyped / js-quantities / js-quantities-tests.ts View on Github external
it("should return an array of units of kind", () => {
      expect(Qty.getUnits("currency")).toContain("dollar");
    });
    it("should return an array of all units without arg", () => {
github DefinitelyTyped / DefinitelyTyped / types / js-quantities / js-quantities-tests.ts View on Github external
it("should return an array of all units without arg", () => {
      expect(Qty.getUnits()).toContain("sievert");
    });
    it("should throw unknown kind", () => {
github DefinitelyTyped / DefinitelyTyped / types / js-quantities / js-quantities-tests.ts View on Github external
      expect(() => { Qty.getUnits('bogusKind'); }).toThrow("Kind not recognized");
    });
github DefinitelyTyped / DefinitelyTyped / js-quantities / js-quantities-tests.ts View on Github external
      expect(() => { Qty.getUnits('bogusKind'); }).toThrow("Kind not recognized");
    });