diff --git a/README.md b/README.md index d1a3c14..dcbc354 100644 --- a/README.md +++ b/README.md @@ -105,6 +105,7 @@ pace.format('km', 'min').getPaceTimeString(); // 00:06:00 ##### Distance +- m - metre - km - kilometers - mi - miles diff --git a/src/lib/distance.js b/src/lib/distance.js index 3a23d16..0ad36c8 100644 --- a/src/lib/distance.js +++ b/src/lib/distance.js @@ -1,4 +1,8 @@ const units = { + m: { + ratio: 0.001, + name: 'metre' + }, mi: { ratio: 1.60934, name: 'miles' diff --git a/src/lib/pace.js b/src/lib/pace.js index 87d3ba1..f369a24 100644 --- a/src/lib/pace.js +++ b/src/lib/pace.js @@ -23,7 +23,7 @@ export default class Pace { * @param {Object} [optional] - optional params * @param {String} [optional.distanceUnit] - unit of distance * - default unit: km - * - available units: "km", "mi" + * - available units: "m", "km", "mi" * @param {String} [optional.timeUnit] - unit of time * - default unit: s * - available units: "ms", "s", "min" , "h" @@ -71,6 +71,7 @@ export default class Pace { * - default unit - s/km * @param {string} distanceUnit * Available units + * - m * - km * - mi * @param {string} timeUnit diff --git a/tests/distance.test.js b/tests/distance.test.js index 909bf05..2b2c411 100644 --- a/tests/distance.test.js +++ b/tests/distance.test.js @@ -3,10 +3,14 @@ import { listUnit, convertUnit } from '../src/lib/distance'; describe('Distance', () => { test('list units', () => { expect(typeof listUnit()).toBe('object'); - expect(listUnit()).toEqual(['mi', 'km']); + expect(listUnit()).toEqual(['m', 'mi', 'km']); }); - test('convertUnit', () => { + test('convertUnit - km to mi', () => { expect(convertUnit(10, 'km', 'mi')).toBeCloseTo(6.2, 1); }); + + test('convertUnit - km to m', () => { + expect(convertUnit(10, 'km', 'm')).toBe(10000); + }); }); diff --git a/tests/pacecal.test.js b/tests/pacecal.test.js index 8d7a086..43f914e 100644 --- a/tests/pacecal.test.js +++ b/tests/pacecal.test.js @@ -51,7 +51,7 @@ describe('Pace Class', () => { expect(() => { // invalid distanceUnit // eslint-disable-next-line no-unused-vars - const pace = new Pace(6, 3600, { distanceUnit: 'm', timeUnit: 'min' }); + const pace = new Pace(6, 3600, { distanceUnit: 'yard', timeUnit: 'min' }); }).toThrow(TypeError); });