当前位置: 首页>>代码示例>>TypeScript>>正文


TypeScript js-quantities.swiftConverter函数代码示例

本文整理汇总了TypeScript中js-quantities.swiftConverter函数的典型用法代码示例。如果您正苦于以下问题:TypeScript swiftConverter函数的具体用法?TypeScript swiftConverter怎么用?TypeScript swiftConverter使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了swiftConverter函数的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。

示例1: it

        it("should convert value", () => {
          // TODO Same test but with m/h -> ft/s triggers rounding issue
          // (For the sake of speed, converter does not check and fix rounding issues)
          var converter = Qty.swiftConverter("m/h", "m/s");

          expect(converter(2500)).toEqual(Qty("2500 m/h").to("m/s").scalar);
        });
开发者ID:Kroisse,项目名称:DefinitelyTyped,代码行数:7,代码来源:js-quantities-tests.ts

示例2: expect

 expect(() => { Qty.swiftConverter("m", "s"); }).toThrow("Incompatible units");
开发者ID:Kroisse,项目名称:DefinitelyTyped,代码行数:1,代码来源:js-quantities-tests.ts

示例3: 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)
qty1.to(qty2); // converts quantity to same unit of qty2 if compatible or throws an error (new instance)

qty.inverse(); // converts quantity to its inverse ('100 m/s' => '.01 s/m')
// Inverses can be used, but there is no special checking to
// rename the units
Qty('10ohm').inverse(); // '.1/ohm' (not '.1S', although they are equivalent)
// however, the 'to' command will convert between inverses also
Qty('10ohm').to('S'); // '.1S'

var convert = Qty.swiftConverter('m/h', 'ft/s'); // Configures converter

// Converting single value
var converted = convert(2500); // => 2.278..

// Converting large array of values
var convertedSerie = convert([2500, 5000]); // => [2.278.., 4.556.., ...]

qty1.eq(qty2); // => true if both quantities are equal (1m == 100cm => true)
qty1.same(qty2); // => true if both quantities are same (1m == 100cm => false)
qty1.lt(qty2); // => true if qty1 is stricty less than qty2
qty1.lte(qty2); // => true if qty1 is less than or equal to qty2
qty1.gt(qty2); // => true if qty1 is stricty greater than qty2
qty1.gte(qty2); // => true if qty1 is greater than or equal to qty2

qty1.compareTo(qty2); // => -1 if qty1 < qty2, => 0 if qty1 == qty2, => 1 if qty1 > qty2
开发者ID:Kroisse,项目名称:DefinitelyTyped,代码行数:30,代码来源:js-quantities-tests.ts

示例4: expect

 expect(function () { Qty.swiftConverter("m", "s"); }).toThrow("Incompatible units");
开发者ID:ArtemZag,项目名称:DefinitelyTyped,代码行数:1,代码来源:js-quantities-tests.ts


注:本文中的js-quantities.swiftConverter函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。