Skip to content

Commit

Permalink
Add Feet-to-meters and Fathoms-to-meters (#13)
Browse files Browse the repository at this point in the history
  • Loading branch information
iholck authored Mar 2, 2024
1 parent 5de00a1 commit d0ae966
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 6 deletions.
10 changes: 10 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@
// TEMPERATURES
// Celcius
CELCIUS_IN_KELVIN: 273.15,
// Length
METER_IN_FEET: 3.2808,
METER_IN_FATHOM: 0.5468,
};

function checksum(sentencePart) {
Expand Down Expand Up @@ -145,7 +148,14 @@
if (outputFormat == 'c') return value - utils.RATIOS.CELCIUS_IN_KELVIN;
if (outputFormat == 'f') return (1.8 * (value - 273)) + 32;
}
// LENGTH
if (inputFormat == 'ft') {
if (outputFormat == 'm') return value / utils.RATIOS.METER_IN_FEET;
}

if (inputFormat == 'fa') {
if (outputFormat == 'm') return value / utils.RATIOS.METER_IN_FATHOM;
}
// Just return input if input/output formats are not recognised.
return value;
};
Expand Down
27 changes: 21 additions & 6 deletions test/transform.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
var chai = require("chai");
var expect = chai.expect;
var utils = require('../index');
var chai = require("chai");
var expect = chai.expect;
var utils = require('../index');

describe('Transform', function() {
it('KM -> NM', function(done) {
Expand Down Expand Up @@ -118,18 +118,33 @@ describe('Transform', function() {
expect(value).to.equal(57.295779578552306);
done();
});

it('CELCIUS -> KELVIN', function(done) {
var value = utils.transform(0, 'c', 'k');
expect(value).to.be.a('number');
expect(value).to.equal(273.15);
done();
});
});

it('KELVIN -> CELCIUS', function(done) {
var value = utils.transform(0, 'k', 'c');
expect(value).to.be.a('number');
expect(value).to.equal(-273.15);
done()
});

it('FEET -> METERS', function(done) {
var value = utils.transform(33, 'ft', 'm');
expect(value).to.be.a('number');
expect(value).to.equal(10.05852231163131);
done()
});

it('FATHOMS -> METERS', function(done) {
var value = utils.transform(10, 'fa', 'm');
expect(value).to.be.a('number');
expect(value).to.equal(18.288222384784202);
done()
});

});

0 comments on commit d0ae966

Please sign in to comment.