Skip to content

Commit

Permalink
Remove tilde prefix from compact output (#42)
Browse files Browse the repository at this point in the history
  • Loading branch information
arnellebalane committed Feb 12, 2020
1 parent 7dcd14a commit 4e3c6a6
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 25 deletions.
4 changes: 2 additions & 2 deletions index.d.ts
Expand Up @@ -26,7 +26,7 @@ declare namespace prettyMilliseconds {
readonly keepDecimalsOnWholeSeconds?: boolean;

/**
Only show the first unit: `1h 10m` → `~1h`.
Only show the first unit: `1h 10m` → `1h`.
Also ensures that `millisecondsDecimalDigits` and `secondsDecimalDigits` are both set to `0`.
Expand Down Expand Up @@ -99,7 +99,7 @@ prettyMilliseconds(133);
// `compact` option
prettyMilliseconds(1337, {compact: true});
//=> '~1s'
//=> '1s'
// `verbose` option
prettyMilliseconds(1335669000, {verbose: true});
Expand Down
2 changes: 1 addition & 1 deletion index.js
Expand Up @@ -113,7 +113,7 @@ module.exports = (milliseconds, options = {}) => {
}

if (options.compact) {
return '~' + result[0];
return result[0];
}

if (typeof options.unitCount === 'number') {
Expand Down
4 changes: 2 additions & 2 deletions readme.md
Expand Up @@ -24,7 +24,7 @@ prettyMilliseconds(133);

// `compact` option
prettyMilliseconds(1337, {compact: true});
//=> '~1s'
//=> '1s'

// `verbose` option
prettyMilliseconds(1335669000, {verbose: true});
Expand Down Expand Up @@ -87,7 +87,7 @@ Useful when you are showing a number of seconds spent on an operation and don't
Type: `boolean`\
Default: `false`

Only show the first unit: `1h 10m``~1h`.
Only show the first unit: `1h 10m``1h`.

Also ensures that `millisecondsDecimalDigits` and `secondsDecimalDigits` are both set to `0`.

Expand Down
40 changes: 20 additions & 20 deletions test.js
Expand Up @@ -19,10 +19,10 @@ test('prettify milliseconds', t => {
});

test('have a compact option', t => {
t.is(prettyMilliseconds(1000 + 4, {compact: true}), '~1s');
t.is(prettyMilliseconds(1000 * 60 * 60 * 999, {compact: true}), '~41d');
t.is(prettyMilliseconds(1000 * 60 * 60 * 24 * 465, {compact: true}), '~1y');
t.is(prettyMilliseconds(1000 * 60 * 67 * 24 * 465, {compact: true}), '~1y');
t.is(prettyMilliseconds(1000 + 4, {compact: true}), '1s');
t.is(prettyMilliseconds(1000 * 60 * 60 * 999, {compact: true}), '41d');
t.is(prettyMilliseconds(1000 * 60 * 60 * 24 * 465, {compact: true}), '1y');
t.is(prettyMilliseconds(1000 * 60 * 67 * 24 * 465, {compact: true}), '1y');
});

test('have a unitCount option', t => {
Expand Down Expand Up @@ -97,19 +97,19 @@ test('work with verbose and compact options', t => {
compact: true
});

t.is(fn(1000), '~1 second');
t.is(fn(1000 + 400), '~1 second');
t.is(fn((1000 * 2) + 400), '~2 seconds');
t.is(fn(1000 * 5), '~5 seconds');
t.is(fn(1000 * 55), '~55 seconds');
t.is(fn(1000 * 67), '~1 minute');
t.is(fn(1000 * 60 * 5), '~5 minutes');
t.is(fn(1000 * 60 * 67), '~1 hour');
t.is(fn(1000 * 60 * 60 * 12), '~12 hours');
t.is(fn(1000 * 60 * 60 * 40), '~1 day');
t.is(fn(1000 * 60 * 60 * 999), '~41 days');
t.is(fn(1000 * 60 * 60 * 24 * 465), '~1 year');
t.is(fn(1000 * 60 * 67 * 24 * 750), '~2 years');
t.is(fn(1000), '1 second');
t.is(fn(1000 + 400), '1 second');
t.is(fn((1000 * 2) + 400), '2 seconds');
t.is(fn(1000 * 5), '5 seconds');
t.is(fn(1000 * 55), '55 seconds');
t.is(fn(1000 * 67), '1 minute');
t.is(fn(1000 * 60 * 5), '5 minutes');
t.is(fn(1000 * 60 * 67), '1 hour');
t.is(fn(1000 * 60 * 60 * 12), '12 hours');
t.is(fn(1000 * 60 * 60 * 40), '1 day');
t.is(fn(1000 * 60 * 60 * 999), '41 days');
t.is(fn(1000 * 60 * 60 * 24 * 465), '1 year');
t.is(fn(1000 * 60 * 67 * 24 * 750), '2 years');
});

test('work with verbose and unitCount options', t => {
Expand Down Expand Up @@ -173,9 +173,9 @@ test('work with verbose and formatSubMilliseconds options', t => {
});

test('compact option overrides unitCount option', t => {
t.is(prettyMilliseconds(1000 * 60 * 67 * 24 * 465, {verbose: true, compact: true, unitCount: 1}), '~1 year');
t.is(prettyMilliseconds(1000 * 60 * 67 * 24 * 465, {verbose: true, compact: true, unitCount: 2}), '~1 year');
t.is(prettyMilliseconds(1000 * 60 * 67 * 24 * 465, {verbose: true, compact: true, unitCount: 3}), '~1 year');
t.is(prettyMilliseconds(1000 * 60 * 67 * 24 * 465, {verbose: true, compact: true, unitCount: 1}), '1 year');
t.is(prettyMilliseconds(1000 * 60 * 67 * 24 * 465, {verbose: true, compact: true, unitCount: 2}), '1 year');
t.is(prettyMilliseconds(1000 * 60 * 67 * 24 * 465, {verbose: true, compact: true, unitCount: 3}), '1 year');
});

test('work with separateMilliseconds and formatSubMilliseconds options', t => {
Expand Down

0 comments on commit 4e3c6a6

Please sign in to comment.