Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
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)
qty.to('m'); // converts quantity to meter if compatible or throws an error (new instance)
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)
qty.to('m'); // converts quantity to meter if compatible or throws an error (new instance)
it("should return array of alternative names for unit", () => {
expect(Qty.getAliases("m")).toContain("meter");
expect(Qty.getAliases("meter")).toContain("metre");
expect(Qty.getAliases("N")).toContain("newton");
});
});
it("should return array of alternative names for unit", () => {
expect(Qty.getAliases("m")).toContain("meter");
expect(Qty.getAliases("meter")).toContain("metre");
expect(Qty.getAliases("N")).toContain("newton");
});
});
it("should return array of alternative names for unit", () => {
expect(Qty.getAliases("m")).toContain("meter");
expect(Qty.getAliases("meter")).toContain("metre");
expect(Qty.getAliases("N")).toContain("newton");
});
});
it("should return array of alternative names for unit", () => {
expect(Qty.getAliases("m")).toContain("meter");
expect(Qty.getAliases("meter")).toContain("metre");
expect(Qty.getAliases("N")).toContain("newton");
});
});
it("should return array of alternative names for unit", () => {
expect(Qty.getAliases("m")).toContain("meter");
expect(Qty.getAliases("meter")).toContain("metre");
expect(Qty.getAliases("N")).toContain("newton");
});
});
it("should return array of alternative names for unit", () => {
expect(Qty.getAliases("m")).toContain("meter");
expect(Qty.getAliases("meter")).toContain("metre");
expect(Qty.getAliases("N")).toContain("newton");
});
});