Skip to content

Commit

Permalink
Do not mutate options (#67)
Browse files Browse the repository at this point in the history
  • Loading branch information
fisker committed Jan 18, 2024
1 parent 228dd07 commit 2f55b19
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
4 changes: 3 additions & 1 deletion index.js
Expand Up @@ -5,11 +5,13 @@ const pluralize = (word, count) => (count === 1 || count === 1n) ? word : `${wor

const SECOND_ROUNDING_EPSILON = 0.000_000_1;

export default function prettyMilliseconds(milliseconds, options = {}) {
export default function prettyMilliseconds(milliseconds, options) {
if (!Number.isFinite(milliseconds)) {
throw new TypeError('Expected a finite number');
}

options = {...options};

if (options.colonNotation) {
options.compact = false;
options.formatSubMilliseconds = false;
Expand Down
11 changes: 11 additions & 0 deletions test.js
Expand Up @@ -308,3 +308,14 @@ test('`colonNotation` option', t => {
t.is(format(Number.MAX_SAFE_INTEGER), '285616:151:08:59:00.9');
t.is(format(Number.MAX_VALUE), '5700447535712568547083700427941645003808085225292279557374304680873482979681895890593452082909683139015032646149857723394516742095667500822861020052921074432454921864096959420926519725467567456931340929884912090099277441972878147362726992943838905852030073647982034630974035871792165820638724934142:218:08:08:48');
});

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 2f55b19

Please sign in to comment.