@mll-lab/js-utils 2.32.0 → 2.34.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/array.d.ts +8 -1
- package/dist/date.d.ts +5 -0
- package/dist/index.common.js +320 -1
- package/dist/index.common.js.map +1 -1
- package/dist/index.js +320 -1
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/array.d.ts
CHANGED
|
@@ -43,12 +43,19 @@ export declare function toggleElement<T>(array: Array<T>, element: T): Array<T>;
|
|
|
43
43
|
*/
|
|
44
44
|
export declare function sortByArray<T extends string | number>(subject: Array<T>, recipe: Array<T>): Array<T>;
|
|
45
45
|
/**
|
|
46
|
-
* Takes a function that maps the values to sort and returns a compare function
|
|
46
|
+
* Takes a function that maps the values to sort to strings and returns a compare function
|
|
47
47
|
* using `String.prototype.localeCompare`, usable in `Array.toSorted` or similar APIs.
|
|
48
48
|
*
|
|
49
49
|
* null, undefined and the empty string are not distinguished and first in sort order.
|
|
50
50
|
*/
|
|
51
51
|
export declare function makeStringCompareFn<TSortable>(map: (sortable: TSortable) => Maybe<string>): (a: TSortable, b: TSortable) => number;
|
|
52
|
+
/**
|
|
53
|
+
* Takes a function that maps the values to sort to numbers and returns a compare function
|
|
54
|
+
* using subtraction, usable in `Array.toSorted` or similar APIs.
|
|
55
|
+
*
|
|
56
|
+
* null and undefined are coalesced to `fallbackValue`, by default 0, and thus not distinguished and first in sort order.
|
|
57
|
+
*/
|
|
58
|
+
export declare function makeNumberCompareFn<TSortable>(map: (sortable: TSortable) => Maybe<number>, fallbackValue?: number): (a: TSortable, b: TSortable) => number;
|
|
52
59
|
/**
|
|
53
60
|
* Returns a compare function for values that are string, null or undefined,
|
|
54
61
|
* using `String.prototype.localeCompare`, usable in `Array.toSorted` or similar APIs.
|
package/dist/date.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { Maybe } from './types';
|
|
1
2
|
export declare function isToday(date: Date | string | number): boolean;
|
|
2
3
|
export declare function isFuture(date: Date | string | number): boolean;
|
|
3
4
|
export declare function isValidGermanDate(date: string): boolean;
|
|
@@ -27,3 +28,7 @@ export declare function parseDotlessDate(value: string): Date | null;
|
|
|
27
28
|
export declare function formatDotlessDate(date: Date | string | number): string;
|
|
28
29
|
export declare function formatGermanTimeHourMinute(date: string): string;
|
|
29
30
|
export declare function formatGermanFullDateTime(date: Date | string | number): string;
|
|
31
|
+
/** Does the given date match the given dateFormat? */
|
|
32
|
+
export declare function dateMatchesFormat(date: Maybe<string>,
|
|
33
|
+
/** @see https://date-fns.org/v3.6.0/docs/isMatch for allowed formats. */
|
|
34
|
+
dateFormat: string): boolean;
|
package/dist/index.common.js
CHANGED
|
@@ -9505,7 +9505,7 @@ function sortByArray(subject, recipe) {
|
|
|
9505
9505
|
return lodash.sortBy(subject, (value) => recipe.indexOf(value));
|
|
9506
9506
|
}
|
|
9507
9507
|
/**
|
|
9508
|
-
* Takes a function that maps the values to sort and returns a compare function
|
|
9508
|
+
* Takes a function that maps the values to sort to strings and returns a compare function
|
|
9509
9509
|
* using `String.prototype.localeCompare`, usable in `Array.toSorted` or similar APIs.
|
|
9510
9510
|
*
|
|
9511
9511
|
* null, undefined and the empty string are not distinguished and first in sort order.
|
|
@@ -9518,6 +9518,20 @@ function makeStringCompareFn(map) {
|
|
|
9518
9518
|
return mappedA.localeCompare(mappedB);
|
|
9519
9519
|
};
|
|
9520
9520
|
}
|
|
9521
|
+
/**
|
|
9522
|
+
* Takes a function that maps the values to sort to numbers and returns a compare function
|
|
9523
|
+
* using subtraction, usable in `Array.toSorted` or similar APIs.
|
|
9524
|
+
*
|
|
9525
|
+
* null and undefined are coalesced to `fallbackValue`, by default 0, and thus not distinguished and first in sort order.
|
|
9526
|
+
*/
|
|
9527
|
+
function makeNumberCompareFn(map, fallbackValue = 0) {
|
|
9528
|
+
return (a, b) => {
|
|
9529
|
+
var _a, _b;
|
|
9530
|
+
const mappedA = (_a = map(a)) !== null && _a !== void 0 ? _a : fallbackValue;
|
|
9531
|
+
const mappedB = (_b = map(b)) !== null && _b !== void 0 ? _b : fallbackValue;
|
|
9532
|
+
return mappedA - mappedB;
|
|
9533
|
+
};
|
|
9534
|
+
}
|
|
9521
9535
|
/**
|
|
9522
9536
|
* Returns a compare function for values that are string, null or undefined,
|
|
9523
9537
|
* using `String.prototype.localeCompare`, usable in `Array.toSorted` or similar APIs.
|
|
@@ -15003,6 +15017,300 @@ function cleanEscapedString(input) {
|
|
|
15003
15017
|
return input.match(escapedStringRegExp)[1].replace(doubleQuoteRegExp, "'");
|
|
15004
15018
|
}
|
|
15005
15019
|
|
|
15020
|
+
/**
|
|
15021
|
+
* The {@link isMatch} function options.
|
|
15022
|
+
*/
|
|
15023
|
+
|
|
15024
|
+
/**
|
|
15025
|
+
* @name isMatch
|
|
15026
|
+
* @category Common Helpers
|
|
15027
|
+
* @summary validates the date string against given formats
|
|
15028
|
+
*
|
|
15029
|
+
* @description
|
|
15030
|
+
* Return the true if given date is string correct against the given format else
|
|
15031
|
+
* will return false.
|
|
15032
|
+
*
|
|
15033
|
+
* > ⚠️ Please note that the `format` tokens differ from Moment.js and other libraries.
|
|
15034
|
+
* > See: https://github.com/date-fns/date-fns/blob/master/docs/unicodeTokens.md
|
|
15035
|
+
*
|
|
15036
|
+
* The characters in the format string wrapped between two single quotes characters (') are escaped.
|
|
15037
|
+
* Two single quotes in a row, whether inside or outside a quoted sequence, represent a 'real' single quote.
|
|
15038
|
+
*
|
|
15039
|
+
* Format of the format string is based on Unicode Technical Standard #35:
|
|
15040
|
+
* https://www.unicode.org/reports/tr35/tr35-dates.html#Date_Field_Symbol_Table
|
|
15041
|
+
* with a few additions (see note 5 below the table).
|
|
15042
|
+
*
|
|
15043
|
+
* Not all tokens are compatible. Combinations that don't make sense or could lead to bugs are prohibited
|
|
15044
|
+
* and will throw `RangeError`. For example usage of 24-hour format token with AM/PM token will throw an exception:
|
|
15045
|
+
*
|
|
15046
|
+
* ```javascript
|
|
15047
|
+
* isMatch('23 AM', 'HH a')
|
|
15048
|
+
* //=> RangeError: The format string mustn't contain `HH` and `a` at the same time
|
|
15049
|
+
* ```
|
|
15050
|
+
*
|
|
15051
|
+
* See the compatibility table: https://docs.google.com/spreadsheets/d/e/2PACX-1vQOPU3xUhplll6dyoMmVUXHKl_8CRDs6_ueLmex3SoqwhuolkuN3O05l4rqx5h1dKX8eb46Ul-CCSrq/pubhtml?gid=0&single=true
|
|
15052
|
+
*
|
|
15053
|
+
* Accepted format string patterns:
|
|
15054
|
+
* | Unit |Prior| Pattern | Result examples | Notes |
|
|
15055
|
+
* |---------------------------------|-----|---------|-----------------------------------|-------|
|
|
15056
|
+
* | Era | 140 | G..GGG | AD, BC | |
|
|
15057
|
+
* | | | GGGG | Anno Domini, Before Christ | 2 |
|
|
15058
|
+
* | | | GGGGG | A, B | |
|
|
15059
|
+
* | Calendar year | 130 | y | 44, 1, 1900, 2017, 9999 | 4 |
|
|
15060
|
+
* | | | yo | 44th, 1st, 1900th, 9999999th | 4,5 |
|
|
15061
|
+
* | | | yy | 44, 01, 00, 17 | 4 |
|
|
15062
|
+
* | | | yyy | 044, 001, 123, 999 | 4 |
|
|
15063
|
+
* | | | yyyy | 0044, 0001, 1900, 2017 | 4 |
|
|
15064
|
+
* | | | yyyyy | ... | 2,4 |
|
|
15065
|
+
* | Local week-numbering year | 130 | Y | 44, 1, 1900, 2017, 9000 | 4 |
|
|
15066
|
+
* | | | Yo | 44th, 1st, 1900th, 9999999th | 4,5 |
|
|
15067
|
+
* | | | YY | 44, 01, 00, 17 | 4,6 |
|
|
15068
|
+
* | | | YYY | 044, 001, 123, 999 | 4 |
|
|
15069
|
+
* | | | YYYY | 0044, 0001, 1900, 2017 | 4,6 |
|
|
15070
|
+
* | | | YYYYY | ... | 2,4 |
|
|
15071
|
+
* | ISO week-numbering year | 130 | R | -43, 1, 1900, 2017, 9999, -9999 | 4,5 |
|
|
15072
|
+
* | | | RR | -43, 01, 00, 17 | 4,5 |
|
|
15073
|
+
* | | | RRR | -043, 001, 123, 999, -999 | 4,5 |
|
|
15074
|
+
* | | | RRRR | -0043, 0001, 2017, 9999, -9999 | 4,5 |
|
|
15075
|
+
* | | | RRRRR | ... | 2,4,5 |
|
|
15076
|
+
* | Extended year | 130 | u | -43, 1, 1900, 2017, 9999, -999 | 4 |
|
|
15077
|
+
* | | | uu | -43, 01, 99, -99 | 4 |
|
|
15078
|
+
* | | | uuu | -043, 001, 123, 999, -999 | 4 |
|
|
15079
|
+
* | | | uuuu | -0043, 0001, 2017, 9999, -9999 | 4 |
|
|
15080
|
+
* | | | uuuuu | ... | 2,4 |
|
|
15081
|
+
* | Quarter (formatting) | 120 | Q | 1, 2, 3, 4 | |
|
|
15082
|
+
* | | | Qo | 1st, 2nd, 3rd, 4th | 5 |
|
|
15083
|
+
* | | | QQ | 01, 02, 03, 04 | |
|
|
15084
|
+
* | | | QQQ | Q1, Q2, Q3, Q4 | |
|
|
15085
|
+
* | | | QQQQ | 1st quarter, 2nd quarter, ... | 2 |
|
|
15086
|
+
* | | | QQQQQ | 1, 2, 3, 4 | 4 |
|
|
15087
|
+
* | Quarter (stand-alone) | 120 | q | 1, 2, 3, 4 | |
|
|
15088
|
+
* | | | qo | 1st, 2nd, 3rd, 4th | 5 |
|
|
15089
|
+
* | | | qq | 01, 02, 03, 04 | |
|
|
15090
|
+
* | | | qqq | Q1, Q2, Q3, Q4 | |
|
|
15091
|
+
* | | | qqqq | 1st quarter, 2nd quarter, ... | 2 |
|
|
15092
|
+
* | | | qqqqq | 1, 2, 3, 4 | 3 |
|
|
15093
|
+
* | Month (formatting) | 110 | M | 1, 2, ..., 12 | |
|
|
15094
|
+
* | | | Mo | 1st, 2nd, ..., 12th | 5 |
|
|
15095
|
+
* | | | MM | 01, 02, ..., 12 | |
|
|
15096
|
+
* | | | MMM | Jan, Feb, ..., Dec | |
|
|
15097
|
+
* | | | MMMM | January, February, ..., December | 2 |
|
|
15098
|
+
* | | | MMMMM | J, F, ..., D | |
|
|
15099
|
+
* | Month (stand-alone) | 110 | L | 1, 2, ..., 12 | |
|
|
15100
|
+
* | | | Lo | 1st, 2nd, ..., 12th | 5 |
|
|
15101
|
+
* | | | LL | 01, 02, ..., 12 | |
|
|
15102
|
+
* | | | LLL | Jan, Feb, ..., Dec | |
|
|
15103
|
+
* | | | LLLL | January, February, ..., December | 2 |
|
|
15104
|
+
* | | | LLLLL | J, F, ..., D | |
|
|
15105
|
+
* | Local week of year | 100 | w | 1, 2, ..., 53 | |
|
|
15106
|
+
* | | | wo | 1st, 2nd, ..., 53th | 5 |
|
|
15107
|
+
* | | | ww | 01, 02, ..., 53 | |
|
|
15108
|
+
* | ISO week of year | 100 | I | 1, 2, ..., 53 | 5 |
|
|
15109
|
+
* | | | Io | 1st, 2nd, ..., 53th | 5 |
|
|
15110
|
+
* | | | II | 01, 02, ..., 53 | 5 |
|
|
15111
|
+
* | Day of month | 90 | d | 1, 2, ..., 31 | |
|
|
15112
|
+
* | | | do | 1st, 2nd, ..., 31st | 5 |
|
|
15113
|
+
* | | | dd | 01, 02, ..., 31 | |
|
|
15114
|
+
* | Day of year | 90 | D | 1, 2, ..., 365, 366 | 7 |
|
|
15115
|
+
* | | | Do | 1st, 2nd, ..., 365th, 366th | 5 |
|
|
15116
|
+
* | | | DD | 01, 02, ..., 365, 366 | 7 |
|
|
15117
|
+
* | | | DDD | 001, 002, ..., 365, 366 | |
|
|
15118
|
+
* | | | DDDD | ... | 2 |
|
|
15119
|
+
* | Day of week (formatting) | 90 | E..EEE | Mon, Tue, Wed, ..., Su | |
|
|
15120
|
+
* | | | EEEE | Monday, Tuesday, ..., Sunday | 2 |
|
|
15121
|
+
* | | | EEEEE | M, T, W, T, F, S, S | |
|
|
15122
|
+
* | | | EEEEEE | Mo, Tu, We, Th, Fr, Sa, Su | |
|
|
15123
|
+
* | ISO day of week (formatting) | 90 | i | 1, 2, 3, ..., 7 | 5 |
|
|
15124
|
+
* | | | io | 1st, 2nd, ..., 7th | 5 |
|
|
15125
|
+
* | | | ii | 01, 02, ..., 07 | 5 |
|
|
15126
|
+
* | | | iii | Mon, Tue, Wed, ..., Su | 5 |
|
|
15127
|
+
* | | | iiii | Monday, Tuesday, ..., Sunday | 2,5 |
|
|
15128
|
+
* | | | iiiii | M, T, W, T, F, S, S | 5 |
|
|
15129
|
+
* | | | iiiiii | Mo, Tu, We, Th, Fr, Sa, Su | 5 |
|
|
15130
|
+
* | Local day of week (formatting) | 90 | e | 2, 3, 4, ..., 1 | |
|
|
15131
|
+
* | | | eo | 2nd, 3rd, ..., 1st | 5 |
|
|
15132
|
+
* | | | ee | 02, 03, ..., 01 | |
|
|
15133
|
+
* | | | eee | Mon, Tue, Wed, ..., Su | |
|
|
15134
|
+
* | | | eeee | Monday, Tuesday, ..., Sunday | 2 |
|
|
15135
|
+
* | | | eeeee | M, T, W, T, F, S, S | |
|
|
15136
|
+
* | | | eeeeee | Mo, Tu, We, Th, Fr, Sa, Su | |
|
|
15137
|
+
* | Local day of week (stand-alone) | 90 | c | 2, 3, 4, ..., 1 | |
|
|
15138
|
+
* | | | co | 2nd, 3rd, ..., 1st | 5 |
|
|
15139
|
+
* | | | cc | 02, 03, ..., 01 | |
|
|
15140
|
+
* | | | ccc | Mon, Tue, Wed, ..., Su | |
|
|
15141
|
+
* | | | cccc | Monday, Tuesday, ..., Sunday | 2 |
|
|
15142
|
+
* | | | ccccc | M, T, W, T, F, S, S | |
|
|
15143
|
+
* | | | cccccc | Mo, Tu, We, Th, Fr, Sa, Su | |
|
|
15144
|
+
* | AM, PM | 80 | a..aaa | AM, PM | |
|
|
15145
|
+
* | | | aaaa | a.m., p.m. | 2 |
|
|
15146
|
+
* | | | aaaaa | a, p | |
|
|
15147
|
+
* | AM, PM, noon, midnight | 80 | b..bbb | AM, PM, noon, midnight | |
|
|
15148
|
+
* | | | bbbb | a.m., p.m., noon, midnight | 2 |
|
|
15149
|
+
* | | | bbbbb | a, p, n, mi | |
|
|
15150
|
+
* | Flexible day period | 80 | B..BBB | at night, in the morning, ... | |
|
|
15151
|
+
* | | | BBBB | at night, in the morning, ... | 2 |
|
|
15152
|
+
* | | | BBBBB | at night, in the morning, ... | |
|
|
15153
|
+
* | Hour [1-12] | 70 | h | 1, 2, ..., 11, 12 | |
|
|
15154
|
+
* | | | ho | 1st, 2nd, ..., 11th, 12th | 5 |
|
|
15155
|
+
* | | | hh | 01, 02, ..., 11, 12 | |
|
|
15156
|
+
* | Hour [0-23] | 70 | H | 0, 1, 2, ..., 23 | |
|
|
15157
|
+
* | | | Ho | 0th, 1st, 2nd, ..., 23rd | 5 |
|
|
15158
|
+
* | | | HH | 00, 01, 02, ..., 23 | |
|
|
15159
|
+
* | Hour [0-11] | 70 | K | 1, 2, ..., 11, 0 | |
|
|
15160
|
+
* | | | Ko | 1st, 2nd, ..., 11th, 0th | 5 |
|
|
15161
|
+
* | | | KK | 01, 02, ..., 11, 00 | |
|
|
15162
|
+
* | Hour [1-24] | 70 | k | 24, 1, 2, ..., 23 | |
|
|
15163
|
+
* | | | ko | 24th, 1st, 2nd, ..., 23rd | 5 |
|
|
15164
|
+
* | | | kk | 24, 01, 02, ..., 23 | |
|
|
15165
|
+
* | Minute | 60 | m | 0, 1, ..., 59 | |
|
|
15166
|
+
* | | | mo | 0th, 1st, ..., 59th | 5 |
|
|
15167
|
+
* | | | mm | 00, 01, ..., 59 | |
|
|
15168
|
+
* | Second | 50 | s | 0, 1, ..., 59 | |
|
|
15169
|
+
* | | | so | 0th, 1st, ..., 59th | 5 |
|
|
15170
|
+
* | | | ss | 00, 01, ..., 59 | |
|
|
15171
|
+
* | Seconds timestamp | 40 | t | 512969520 | |
|
|
15172
|
+
* | | | tt | ... | 2 |
|
|
15173
|
+
* | Fraction of second | 30 | S | 0, 1, ..., 9 | |
|
|
15174
|
+
* | | | SS | 00, 01, ..., 99 | |
|
|
15175
|
+
* | | | SSS | 000, 001, ..., 999 | |
|
|
15176
|
+
* | | | SSSS | ... | 2 |
|
|
15177
|
+
* | Milliseconds timestamp | 20 | T | 512969520900 | |
|
|
15178
|
+
* | | | TT | ... | 2 |
|
|
15179
|
+
* | Timezone (ISO-8601 w/ Z) | 10 | X | -08, +0530, Z | |
|
|
15180
|
+
* | | | XX | -0800, +0530, Z | |
|
|
15181
|
+
* | | | XXX | -08:00, +05:30, Z | |
|
|
15182
|
+
* | | | XXXX | -0800, +0530, Z, +123456 | 2 |
|
|
15183
|
+
* | | | XXXXX | -08:00, +05:30, Z, +12:34:56 | |
|
|
15184
|
+
* | Timezone (ISO-8601 w/o Z) | 10 | x | -08, +0530, +00 | |
|
|
15185
|
+
* | | | xx | -0800, +0530, +0000 | |
|
|
15186
|
+
* | | | xxx | -08:00, +05:30, +00:00 | 2 |
|
|
15187
|
+
* | | | xxxx | -0800, +0530, +0000, +123456 | |
|
|
15188
|
+
* | | | xxxxx | -08:00, +05:30, +00:00, +12:34:56 | |
|
|
15189
|
+
* | Long localized date | NA | P | 05/29/1453 | 5,8 |
|
|
15190
|
+
* | | | PP | May 29, 1453 | |
|
|
15191
|
+
* | | | PPP | May 29th, 1453 | |
|
|
15192
|
+
* | | | PPPP | Sunday, May 29th, 1453 | 2,5,8 |
|
|
15193
|
+
* | Long localized time | NA | p | 12:00 AM | 5,8 |
|
|
15194
|
+
* | | | pp | 12:00:00 AM | |
|
|
15195
|
+
* | Combination of date and time | NA | Pp | 05/29/1453, 12:00 AM | |
|
|
15196
|
+
* | | | PPpp | May 29, 1453, 12:00:00 AM | |
|
|
15197
|
+
* | | | PPPpp | May 29th, 1453 at ... | |
|
|
15198
|
+
* | | | PPPPpp | Sunday, May 29th, 1453 at ... | 2,5,8 |
|
|
15199
|
+
* Notes:
|
|
15200
|
+
* 1. "Formatting" units (e.g. formatting quarter) in the default en-US locale
|
|
15201
|
+
* are the same as "stand-alone" units, but are different in some languages.
|
|
15202
|
+
* "Formatting" units are declined according to the rules of the language
|
|
15203
|
+
* in the context of a date. "Stand-alone" units are always nominative singular.
|
|
15204
|
+
* In `format` function, they will produce different result:
|
|
15205
|
+
*
|
|
15206
|
+
* `format(new Date(2017, 10, 6), 'do LLLL', {locale: cs}) //=> '6. listopad'`
|
|
15207
|
+
*
|
|
15208
|
+
* `format(new Date(2017, 10, 6), 'do MMMM', {locale: cs}) //=> '6. listopadu'`
|
|
15209
|
+
*
|
|
15210
|
+
* `isMatch` will try to match both formatting and stand-alone units interchangably.
|
|
15211
|
+
*
|
|
15212
|
+
* 2. Any sequence of the identical letters is a pattern, unless it is escaped by
|
|
15213
|
+
* the single quote characters (see below).
|
|
15214
|
+
* If the sequence is longer than listed in table:
|
|
15215
|
+
* - for numerical units (`yyyyyyyy`) `isMatch` will try to match a number
|
|
15216
|
+
* as wide as the sequence
|
|
15217
|
+
* - for text units (`MMMMMMMM`) `isMatch` will try to match the widest variation of the unit.
|
|
15218
|
+
* These variations are marked with "2" in the last column of the table.
|
|
15219
|
+
*
|
|
15220
|
+
* 3. `QQQQQ` and `qqqqq` could be not strictly numerical in some locales.
|
|
15221
|
+
* These tokens represent the shortest form of the quarter.
|
|
15222
|
+
*
|
|
15223
|
+
* 4. The main difference between `y` and `u` patterns are B.C. years:
|
|
15224
|
+
*
|
|
15225
|
+
* | Year | `y` | `u` |
|
|
15226
|
+
* |------|-----|-----|
|
|
15227
|
+
* | AC 1 | 1 | 1 |
|
|
15228
|
+
* | BC 1 | 1 | 0 |
|
|
15229
|
+
* | BC 2 | 2 | -1 |
|
|
15230
|
+
*
|
|
15231
|
+
* Also `yy` will try to guess the century of two digit year by proximity with `referenceDate`:
|
|
15232
|
+
*
|
|
15233
|
+
* `isMatch('50', 'yy') //=> true`
|
|
15234
|
+
*
|
|
15235
|
+
* `isMatch('75', 'yy') //=> true`
|
|
15236
|
+
*
|
|
15237
|
+
* while `uu` will use the year as is:
|
|
15238
|
+
*
|
|
15239
|
+
* `isMatch('50', 'uu') //=> true`
|
|
15240
|
+
*
|
|
15241
|
+
* `isMatch('75', 'uu') //=> true`
|
|
15242
|
+
*
|
|
15243
|
+
* The same difference is true for local and ISO week-numbering years (`Y` and `R`),
|
|
15244
|
+
* except local week-numbering years are dependent on `options.weekStartsOn`
|
|
15245
|
+
* and `options.firstWeekContainsDate` (compare [setISOWeekYear](https://date-fns.org/docs/setISOWeekYear)
|
|
15246
|
+
* and [setWeekYear](https://date-fns.org/docs/setWeekYear)).
|
|
15247
|
+
*
|
|
15248
|
+
* 5. These patterns are not in the Unicode Technical Standard #35:
|
|
15249
|
+
* - `i`: ISO day of week
|
|
15250
|
+
* - `I`: ISO week of year
|
|
15251
|
+
* - `R`: ISO week-numbering year
|
|
15252
|
+
* - `o`: ordinal number modifier
|
|
15253
|
+
* - `P`: long localized date
|
|
15254
|
+
* - `p`: long localized time
|
|
15255
|
+
*
|
|
15256
|
+
* 6. `YY` and `YYYY` tokens represent week-numbering years but they are often confused with years.
|
|
15257
|
+
* You should enable `options.useAdditionalWeekYearTokens` to use them. See: https://github.com/date-fns/date-fns/blob/master/docs/unicodeTokens.md
|
|
15258
|
+
*
|
|
15259
|
+
* 7. `D` and `DD` tokens represent days of the year but they are ofthen confused with days of the month.
|
|
15260
|
+
* You should enable `options.useAdditionalDayOfYearTokens` to use them. See: https://github.com/date-fns/date-fns/blob/master/docs/unicodeTokens.md
|
|
15261
|
+
*
|
|
15262
|
+
* 8. `P+` tokens do not have a defined priority since they are merely aliases to other tokens based
|
|
15263
|
+
* on the given locale.
|
|
15264
|
+
*
|
|
15265
|
+
* using `en-US` locale: `P` => `MM/dd/yyyy`
|
|
15266
|
+
* using `en-US` locale: `p` => `hh:mm a`
|
|
15267
|
+
* using `pt-BR` locale: `P` => `dd/MM/yyyy`
|
|
15268
|
+
* using `pt-BR` locale: `p` => `HH:mm`
|
|
15269
|
+
*
|
|
15270
|
+
* Values will be checked in the descending order of its unit's priority.
|
|
15271
|
+
* Units of an equal priority overwrite each other in the order of appearance.
|
|
15272
|
+
*
|
|
15273
|
+
* If no values of higher priority are matched (e.g. when matching string 'January 1st' without a year),
|
|
15274
|
+
* the values will be taken from today's using `new Date()` date which works as a context of parsing.
|
|
15275
|
+
*
|
|
15276
|
+
* The result may vary by locale.
|
|
15277
|
+
*
|
|
15278
|
+
* If `formatString` matches with `dateString` but does not provides tokens, `referenceDate` will be returned.
|
|
15279
|
+
*
|
|
15280
|
+
* @typeParam DateType - The `Date` type, the function operates on. Gets inferred from passed arguments. Allows to use extensions like [`UTCDate`](https://github.com/date-fns/utc).
|
|
15281
|
+
*
|
|
15282
|
+
* @param dateStr - The date string to verify
|
|
15283
|
+
* @param format - The string of tokens
|
|
15284
|
+
* @param options - An object with options.
|
|
15285
|
+
* see: https://github.com/date-fns/date-fns/blob/master/docs/unicodeTokens.md
|
|
15286
|
+
* see: https://github.com/date-fns/date-fns/blob/master/docs/unicodeTokens.md
|
|
15287
|
+
*
|
|
15288
|
+
* @returns Is format string a match for date string?
|
|
15289
|
+
*
|
|
15290
|
+
* @throws `options.locale` must contain `match` property
|
|
15291
|
+
* @throws use `yyyy` instead of `YYYY` for formatting years; see: https://github.com/date-fns/date-fns/blob/master/docs/unicodeTokens.md
|
|
15292
|
+
* @throws use `yy` instead of `YY` for formatting years; see: https://github.com/date-fns/date-fns/blob/master/docs/unicodeTokens.md
|
|
15293
|
+
* @throws use `d` instead of `D` for formatting days of the month; see: https://github.com/date-fns/date-fns/blob/master/docs/unicodeTokens.md
|
|
15294
|
+
* @throws use `dd` instead of `DD` for formatting days of the month; see: https://github.com/date-fns/date-fns/blob/master/docs/unicodeTokens.md
|
|
15295
|
+
* @throws format string contains an unescaped latin alphabet character
|
|
15296
|
+
*
|
|
15297
|
+
* @example
|
|
15298
|
+
* // Match 11 February 2014 from middle-endian format:
|
|
15299
|
+
* const result = isMatch('02/11/2014', 'MM/dd/yyyy')
|
|
15300
|
+
* //=> true
|
|
15301
|
+
*
|
|
15302
|
+
* @example
|
|
15303
|
+
* // Match 28th of February in Esperanto locale in the context of 2010 year:
|
|
15304
|
+
* import eo from 'date-fns/locale/eo'
|
|
15305
|
+
* const result = isMatch('28-a de februaro', "do 'de' MMMM", {
|
|
15306
|
+
* locale: eo
|
|
15307
|
+
* })
|
|
15308
|
+
* //=> true
|
|
15309
|
+
*/
|
|
15310
|
+
function isMatch(dateStr, formatStr, options) {
|
|
15311
|
+
return isValid(parse(dateStr, formatStr, new Date(), options));
|
|
15312
|
+
}
|
|
15313
|
+
|
|
15006
15314
|
var formatDistanceLocale = {
|
|
15007
15315
|
lessThanXSeconds: {
|
|
15008
15316
|
standalone: {
|
|
@@ -15556,6 +15864,15 @@ function formatGermanTimeHourMinute(date) {
|
|
|
15556
15864
|
function formatGermanFullDateTime(date) {
|
|
15557
15865
|
return format(date, 'dd.MM.yyyy HH:mm:ss');
|
|
15558
15866
|
}
|
|
15867
|
+
/** Does the given date match the given dateFormat? */
|
|
15868
|
+
function dateMatchesFormat(date,
|
|
15869
|
+
/** @see https://date-fns.org/v3.6.0/docs/isMatch for allowed formats. */
|
|
15870
|
+
dateFormat) {
|
|
15871
|
+
if (!date) {
|
|
15872
|
+
return false;
|
|
15873
|
+
}
|
|
15874
|
+
return isMatch(date, dateFormat);
|
|
15875
|
+
}
|
|
15559
15876
|
|
|
15560
15877
|
/**
|
|
15561
15878
|
* Detects if a mobile device is used
|
|
@@ -15877,6 +16194,7 @@ exports.SECONDLESS_DATE_TIME_FORMAT = SECONDLESS_DATE_TIME_FORMAT;
|
|
|
15877
16194
|
exports.callSequentially = callSequentially;
|
|
15878
16195
|
exports.ceil = ceil;
|
|
15879
16196
|
exports.containSameValues = containSameValues;
|
|
16197
|
+
exports.dateMatchesFormat = dateMatchesFormat;
|
|
15880
16198
|
exports.downloadBlob = downloadBlob;
|
|
15881
16199
|
exports.errorMessage = errorMessage;
|
|
15882
16200
|
exports.firstDecimalDigit = firstDecimalDigit;
|
|
@@ -15919,6 +16237,7 @@ exports.isZeroish = isZeroish;
|
|
|
15919
16237
|
exports.joinNonEmpty = joinNonEmpty;
|
|
15920
16238
|
exports.last = last;
|
|
15921
16239
|
exports.localeCompareStrings = localeCompareStrings;
|
|
16240
|
+
exports.makeNumberCompareFn = makeNumberCompareFn;
|
|
15922
16241
|
exports.makeStringCompareFn = makeStringCompareFn;
|
|
15923
16242
|
exports.mapSequentially = mapSequentially;
|
|
15924
16243
|
exports.parseDate = parseDate;
|