1 | const dayOfYearTokenRE = /^D+$/;
|
2 | const weekYearTokenRE = /^Y+$/;
|
3 |
|
4 | const throwTokens = ["D", "DD", "YY", "YYYY"];
|
5 |
|
6 | export function isProtectedDayOfYearToken(token) {
|
7 | return dayOfYearTokenRE.test(token);
|
8 | }
|
9 |
|
10 | export function isProtectedWeekYearToken(token) {
|
11 | return weekYearTokenRE.test(token);
|
12 | }
|
13 |
|
14 | export function warnOrThrowProtectedError(token, format, input) {
|
15 | const _message = message(token, format, input);
|
16 | console.warn(_message);
|
17 | if (throwTokens.includes(token)) throw new RangeError(_message);
|
18 | }
|
19 |
|
20 | function message(token, format, input) {
|
21 | const subject = token[0] === "Y" ? "years" : "days of the month";
|
22 | return `Use \`${token.toLowerCase()}\` instead of \`${token}\` (in \`${format}\`) for formatting ${subject} to the input \`${input}\`; see: https://github.com/date-fns/date-fns/blob/master/docs/unicodeTokens.md`;
|
23 | }
|