本文整理匯總了TypeScript中js-quantities.getKinds函數的典型用法代碼示例。如果您正苦於以下問題:TypeScript getKinds函數的具體用法?TypeScript getKinds怎麽用?TypeScript getKinds使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了getKinds函數的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。
示例1: it
it("should not contain duplicate kind names", () => {
var kinds = Qty.getKinds();
var map: { [key: string]: number } = {};
kinds.forEach(kind => {
map[kind] = 1;
});
expect(kinds.length).toEqual(Object.keys(map).length);
});
示例2: Qty
qty = Qty('1 m^2 kg^2 J^2/s^2 A');
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