Skip to content

Commit

Permalink
Merge branch 'main' into bigint
Browse files Browse the repository at this point in the history
  • Loading branch information
fisker committed Jan 18, 2024
2 parents 286fe0d + 2f55b19 commit 2476c9f
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
5 changes: 4 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,15 @@ const pluralize = (word, count) => (count === 1 || count === 1n) ? word : `${wor
const SECOND_ROUNDING_EPSILON = 0.000_000_1;
const ONE_DAY_IN_MILLISECONDS = 24n * 60n * 60n * 1000n;

export default function prettyMilliseconds(milliseconds, options = {}) {

Check failure on line 9 in index.js

View workflow job for this annotation

GitHub Actions / Node.js 20

More than 1 blank line not allowed.

Check failure on line 9 in index.js

View workflow job for this annotation

GitHub Actions / Node.js 18

More than 1 blank line not allowed.
export default function prettyMilliseconds(milliseconds, options) {
const isBigInt = typeof milliseconds === 'bigint';
if (!isBigInt && !Number.isFinite(milliseconds)) {
throw new TypeError('Expected a finite number or bigint');
}

options = {...options};

if (options.colonNotation) {
options.compact = false;
options.formatSubMilliseconds = false;
Expand Down
11 changes: 11 additions & 0 deletions test.js
Original file line number Diff line number Diff line change
Expand Up @@ -374,3 +374,14 @@ test('Big numbers', t => {
'492518667085565947437061434881381799446768678152999990681965689871663728164461750029012489404840762113809476584970910860915948840793052555530048073160376758865890165963154197469165726275039257381029776735493517650149543114803350542920023450224995474725473496449711570325310074468272054469179189112833218790:18:04:03:02',
);
});

test('pure', t => {
const runTest = options => {
const copy = {...options};
prettyMilliseconds(1, options);
t.deepEqual(options, copy);
};

runTest({colonNotation: true});
runTest({compact: true});
});

0 comments on commit 2476c9f

Please sign in to comment.