Skip to content

Commit

Permalink
refactor: standardise helper & fix types checks
Browse files Browse the repository at this point in the history
- Standardise helper's function signature and body
  To match what is generated by default when creating a new helper.

- Fix types errors provided by implicit TypeScript checks
  This will help whenever the project is migrated to TS
  • Loading branch information
MrChocolatine committed Feb 12, 2023
1 parent bc16cb9 commit a9d7543
Showing 1 changed file with 12 additions and 11 deletions.
23 changes: 12 additions & 11 deletions addon/helpers/reading-time.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,19 @@ import { helper } from '@ember/component/helper';
import readingTime from 'reading-time';
import humanizeDuration from 'humanize-duration';

export default helper((params /*, hash*/) => {
let stats = readingTime(params[0] ?? '');
let options = params[1];
export default helper(function helperReadingTime(positional /*, named*/) {
const stats = readingTime(String(positional[0]));
const userOptions = positional[1];

const defaultOptions = {
round: true,
/** @type {['m']} */
units: ['m'],
language: 'en',
};

return humanizeDuration(
stats.time < 60000 ? 60000 : stats.time,
Object.assign(
{
round: true,
units: ['m'],
language: 'en',
},
options
)
Object.assign({}, defaultOptions, userOptions)
);
});

0 comments on commit a9d7543

Please sign in to comment.