How to use the js-quantities.Error 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 / types / js-quantities / js-quantities-tests.ts View on Github external
Qty('100 tempC').div(qty);        // throws error
Qty('100 tempC*unit');            // throws error
Qty('100 tempC/unit');            // throws error
Qty('100 unit/tempC');            // throws error
Qty('100 tempC').inverse();       // throws error

Qty('100 tempC').to('degC'); // => 100 degC

Qty('100 degC').to('tempC'); // => -173.15 tempC

Qty('0 tempC').add('100 degC'); // => 100 tempC

try {
  // code triggering an error inside JS-quantities
} catch (e) {
  if (e instanceof Qty.Error) {
    // ...
  } else {
    // ...
  }
}

// From project spec

describe("js-quantities", () => {
  "use strict";

  describe("initialization", () => {
    it("should create unit only", () => {
      const qty = Qty("m");
      expect(qty.numerator).toEqual(["<meter>"]);
      expect(qty.scalar).toBe(1);</meter>
github DefinitelyTyped / DefinitelyTyped / js-quantities / js-quantities-tests.ts View on Github external
Qty('100 tempC').div(qty);        // throws error
Qty('100 tempC*unit');            // throws error
Qty('100 tempC/unit');            // throws error
Qty('100 unit/tempC');            // throws error
Qty('100 tempC').inverse();       // throws error

Qty('100 tempC').to('degC'); // =&gt; 100 degC

Qty('100 degC').to('tempC'); // =&gt; -173.15 tempC

Qty('0 tempC').add('100 degC'); // =&gt; 100 tempC

try {
  // code triggering an error inside JS-quantities
} catch (e) {
  if (e instanceof Qty.Error) {
    // ...
  } else {
    // ...
  }
}

// From project spec

describe("js-quantities", () =&gt; {
  "use strict";

  describe("initialization", () =&gt; {
    it("should create unit only", () =&gt; {
      const qty = Qty("m");
      expect(qty.numerator).toEqual(["<meter>"]);
      expect(qty.scalar).toBe(1);</meter>