diff --git a/MMM-CTA.js b/MMM-CTA.js
index f0c4cd9..e427da7 100644
--- a/MMM-CTA.js
+++ b/MMM-CTA.js
@@ -15,6 +15,7 @@ Module.register('MMM-CTA', {
maxResultsBus: 5,
maxResultsTrain: 5,
routeIcons: true,
+ suffixStyle: 'long',
stops: [],
},
@@ -109,10 +110,22 @@ Module.register('MMM-CTA', {
if (minutesInt === 0) {
return 'DUE';
}
- if (minutesInt === 1) {
- return `${minutesInt.toString()} min`;
- }
+ return this.minutesWithSuffix(minutesInt);
+ },
- return `${minutesInt.toString()} mins`;
+ minutesWithSuffix(minutes) {
+ switch (this.config.suffixStyle) {
+ case 'none':
+ return minutes.toString();
+ case 'short':
+ return `${minutes.toString()}m`;
+ case 'long':
+ default:
+ if (minutes === 1) {
+ return `${minutes.toString()} min`;
+ }
+
+ return `${minutes.toString()} mins`;
+ }
},
});
diff --git a/README.md b/README.md
index fdd658f..7954eda 100644
--- a/README.md
+++ b/README.md
@@ -46,19 +46,20 @@ var config = {
## Configuration options
-| Option | Required? | Description |
-| ----------------- | ------------ | ---------------------------------------------------------------------- |
-| `busApiKey` | **Required** | See [Obtaining CTA API keys](#obtaining-cta-api-keys) |
-| `trainApiKey` | **Required** | See [Obtaining CTA API keys](#obtaining-cta-api-keys) |
-| `stops` | **Required** | Array of stops to display. See [`stops` option](#stops-option) |
-| `updateInterval` | *Optional* | Refresh time in milliseconds
Default 60000 milliseconds (1 minute) |
-| `maxResultsBus` | *Optional* | Maximum number of bus results to display
Default `5` |
-| `maxResultsTrain` | *Optional* | Maximum number of train results to display
Default `5` |
-| `routeIcons` | *Optional* | True/False - Display icons next to routes.
Default `true` |
+| Option | Required? | Description |
+| ----------------- | ------------ | ----------------------------------------------------------------------------------- |
+| `busApiKey` | **Required** | See [Obtaining CTA API keys](#obtaining-cta-api-keys) |
+| `trainApiKey` | **Required** | See [Obtaining CTA API keys](#obtaining-cta-api-keys) |
+| `stops` | **Required** | Array of stops to display. See [`stops` option](#stops-option) |
+| `updateInterval` | *Optional* | Refresh time in milliseconds
Default 60000 milliseconds (1 minute) |
+| `maxResultsBus` | *Optional* | Maximum number of bus results to display
Default `5` |
+| `maxResultsTrain` | *Optional* | Maximum number of train results to display
Default `5` |
+| `routeIcons` | *Optional* | True/False - Display icons next to routes.
Default `true` |
+| `suffixStyle` | *Optional* | Style of suffix for the arrival time. `long`, `short`, or `none`
Default `long` |
### `stops` option
-The `stops` option is an array of objects. Each object represents a stop to display.
+The `stops` option is an array of objects. Each object represents a stop to display.
```js
{
diff --git a/__tests__/MMM-CTA.spec.js b/__tests__/MMM-CTA.spec.js
index 1944173..024f81e 100644
--- a/__tests__/MMM-CTA.spec.js
+++ b/__tests__/MMM-CTA.spec.js
@@ -24,6 +24,7 @@ it('has a default config', () => {
maxResultsTrain: 5,
maxResultsBus: 5,
routeIcons: true,
+ suffixStyle: 'long',
stops: [],
});
});
@@ -281,3 +282,43 @@ describe('socketNotificationReceived', () => {
});
});
});
+
+describe('minutesWithSuffix', () => {
+ describe('suffix style is long', () => {
+ beforeEach(() => {
+ MMMCTA.setConfig({ suffixStyle: 'long' });
+ });
+
+ it('returns min for singular', () => {
+ expect(MMMCTA.minutesWithSuffix(1)).toBe('1 min');
+ });
+
+ it('returns mins for plural', () => {
+ expect(MMMCTA.minutesWithSuffix(2)).toBe('2 mins');
+ });
+ });
+
+ describe('suffix style is short', () => {
+ beforeEach(() => {
+ MMMCTA.setConfig({ suffixStyle: 'short' });
+ });
+
+ it('returns m for singular', () => {
+ expect(MMMCTA.minutesWithSuffix(1)).toBe('1m');
+ });
+
+ it('returns m for plural', () => {
+ expect(MMMCTA.minutesWithSuffix(2)).toBe('2m');
+ });
+ });
+
+ describe('suffix style is none', () => {
+ beforeEach(() => {
+ MMMCTA.setConfig({ suffixStyle: 'none' });
+ });
+
+ it('returns number', () => {
+ expect(MMMCTA.minutesWithSuffix(1)).toBe('1');
+ });
+ });
+});