All files / src abs.ts

100% Statements 8/8
100% Branches 1/1
100% Functions 1/1
100% Lines 7/7

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20  1x 1x 1x                 1x 6x 2x     3x    
import { Duration, DurationInput } from './types';
import { isNegative } from './isNegative';
import { negate } from './negate';
import { parse } from './parse';
 
/**
 * Get the absolute value of a duration.
 *
 * @example
 * abs({ days: -1, seconds: 1 })
 * // { days: 1, seconds: -1 }
 */
export const abs = (duration: DurationInput): Duration => {
	if (isNegative(duration)) {
		return negate(duration);
	}
 
	return parse(duration);
};