UNPKG

1.2 kBJavaScriptView Raw
1"use strict";
2Object.defineProperty(exports, "__esModule", { value: true });
3exports.SingularRelativeTimeUnit = void 0;
4var ecma402_abstract_1 = require("@formatjs/ecma402-abstract");
5/**
6 * https://tc39.es/proposal-intl-relative-time/#sec-singularrelativetimeunit
7 * @param unit
8 */
9function SingularRelativeTimeUnit(unit) {
10 (0, ecma402_abstract_1.invariant)((0, ecma402_abstract_1.Type)(unit) === 'String', 'unit must be a string');
11 if (unit === 'seconds')
12 return 'second';
13 if (unit === 'minutes')
14 return 'minute';
15 if (unit === 'hours')
16 return 'hour';
17 if (unit === 'days')
18 return 'day';
19 if (unit === 'weeks')
20 return 'week';
21 if (unit === 'months')
22 return 'month';
23 if (unit === 'quarters')
24 return 'quarter';
25 if (unit === 'years')
26 return 'year';
27 if (unit !== 'second' &&
28 unit !== 'minute' &&
29 unit !== 'hour' &&
30 unit !== 'day' &&
31 unit !== 'week' &&
32 unit !== 'month' &&
33 unit !== 'quarter' &&
34 unit !== 'year') {
35 throw new RangeError('invalid unit');
36 }
37 return unit;
38}
39exports.SingularRelativeTimeUnit = SingularRelativeTimeUnit;