@louis.jln/extract-date 3.0.0 → 4.0.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.
Files changed (76) hide show
  1. package/package.json +21 -64
  2. package/src/calculateSpecificity.d.ts +2 -0
  3. package/src/calculateSpecificity.js +15 -20
  4. package/src/createFormats.d.ts +13 -0
  5. package/src/createFormats.js +131 -364
  6. package/src/createMovingChunks.d.ts +2 -0
  7. package/src/createMovingChunks.js +10 -17
  8. package/src/days.json +22005 -0
  9. package/src/extractDate.d.ts +3 -0
  10. package/src/extractDate.js +147 -204
  11. package/src/extractRelativeDate.d.ts +2 -0
  12. package/src/extractRelativeDate.js +20 -31
  13. package/src/index.d.ts +2 -0
  14. package/src/index.js +1 -5
  15. package/src/months.json +35738 -0
  16. package/src/normalizeInput.d.ts +2 -0
  17. package/src/normalizeInput.js +15 -24
  18. package/src/resolveLocalizedNames.d.ts +2 -0
  19. package/src/resolveLocalizedNames.js +82 -0
  20. package/src/types.d.ts +20 -0
  21. package/src/types.js +1 -23
  22. package/test/extract-date/calculateSpecificity.test.d.ts +1 -0
  23. package/test/extract-date/calculateSpecificity.test.js +39 -0
  24. package/test/extract-date/createMovingChunks.test.d.ts +1 -0
  25. package/test/extract-date/createMovingChunks.test.js +28 -0
  26. package/test/extract-date/extractDate/configuration.test.d.ts +1 -0
  27. package/test/extract-date/extractDate/configuration.test.js +36 -0
  28. package/test/extract-date/extractDate/edge-cases.test.d.ts +1 -0
  29. package/test/extract-date/extractDate/edge-cases.test.js +23 -0
  30. package/test/extract-date/extractDate/fixtures.test.d.ts +1 -0
  31. package/test/extract-date/extractDate/fixtures.test.js +42 -0
  32. package/test/extract-date/extractDate/general-formats.test.d.ts +1 -0
  33. package/test/extract-date/extractDate/general-formats.test.js +45 -0
  34. package/test/extract-date/extractDate/implied-year.test.d.ts +1 -0
  35. package/test/extract-date/extractDate/implied-year.test.js +105 -0
  36. package/test/extract-date/extractDate/localised.test.d.ts +1 -0
  37. package/test/extract-date/extractDate/localised.test.js +75 -0
  38. package/test/extract-date/extractDate/multiple-dates.test.d.ts +1 -0
  39. package/test/extract-date/extractDate/multiple-dates.test.js +24 -0
  40. package/test/extract-date/extractDate/relative-dates.test.d.ts +1 -0
  41. package/test/extract-date/extractDate/relative-dates.test.js +47 -0
  42. package/test/extract-date/extractRelativeDate.test.d.ts +1 -0
  43. package/test/extract-date/extractRelativeDate.test.js +29 -0
  44. package/test/extract-date/normalizeInput.test.d.ts +1 -0
  45. package/test/extract-date/normalizeInput.test.js +14 -0
  46. package/test/fixtures/dates.json +22574 -0
  47. package/.flowconfig +0 -3
  48. package/LICENSE +0 -24
  49. package/README.md +0 -184
  50. package/bundle/extract-date.js +0 -61276
  51. package/dist/calculateSpecificity.js +0 -23
  52. package/dist/calculateSpecificity.js.flow +0 -21
  53. package/dist/calculateSpecificity.js.map +0 -1
  54. package/dist/createFormats.js +0 -165
  55. package/dist/createFormats.js.flow +0 -373
  56. package/dist/createFormats.js.map +0 -1
  57. package/dist/createMovingChunks.js +0 -20
  58. package/dist/createMovingChunks.js.flow +0 -19
  59. package/dist/createMovingChunks.js.map +0 -1
  60. package/dist/dictionary.json +0 -3792
  61. package/dist/extractDate.js +0 -148
  62. package/dist/extractDate.js.flow +0 -214
  63. package/dist/extractDate.js.map +0 -1
  64. package/dist/extractRelativeDate.js +0 -32
  65. package/dist/extractRelativeDate.js.flow +0 -34
  66. package/dist/extractRelativeDate.js.map +0 -1
  67. package/dist/index.js +0 -11
  68. package/dist/index.js.flow +0 -6
  69. package/dist/index.js.map +0 -1
  70. package/dist/normalizeInput.js +0 -22
  71. package/dist/normalizeInput.js.flow +0 -26
  72. package/dist/normalizeInput.js.map +0 -1
  73. package/dist/types.js +0 -2
  74. package/dist/types.js.flow +0 -23
  75. package/dist/types.js.map +0 -1
  76. package/src/dictionary.json +0 -3792
@@ -1,23 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.default = void 0;
7
- var _default = dateFnsFormat => {
8
- let specificity = 0;
9
- if (dateFnsFormat.includes('yyyy')) {
10
- specificity += 40;
11
- } else if (dateFnsFormat.includes('yy')) {
12
- specificity += 20;
13
- }
14
- if (dateFnsFormat.includes('M')) {
15
- specificity += 20;
16
- }
17
- if (/d/.test(dateFnsFormat)) {
18
- specificity += 20;
19
- }
20
- return specificity + dateFnsFormat.length;
21
- };
22
- exports.default = _default;
23
- //# sourceMappingURL=calculateSpecificity.js.map
@@ -1,21 +0,0 @@
1
- // @flow
2
-
3
- export default (dateFnsFormat: string): number => {
4
- let specificity = 0;
5
-
6
- if (dateFnsFormat.includes('yyyy')) {
7
- specificity += 40;
8
- } else if (dateFnsFormat.includes('yy')) {
9
- specificity += 20;
10
- }
11
-
12
- if (dateFnsFormat.includes('M')) {
13
- specificity += 20;
14
- }
15
-
16
- if (/d/.test(dateFnsFormat)) {
17
- specificity += 20;
18
- }
19
-
20
- return specificity + dateFnsFormat.length;
21
- };
@@ -1 +0,0 @@
1
- {"version":3,"file":"calculateSpecificity.js","names":["dateFnsFormat","specificity","includes","test","length","exports","default","_default"],"sources":["../src/calculateSpecificity.js"],"sourcesContent":["// @flow\n\nexport default (dateFnsFormat: string): number => {\n let specificity = 0;\n\n if (dateFnsFormat.includes('yyyy')) {\n specificity += 40;\n } else if (dateFnsFormat.includes('yy')) {\n specificity += 20;\n }\n\n if (dateFnsFormat.includes('M')) {\n specificity += 20;\n }\n\n if (/d/.test(dateFnsFormat)) {\n specificity += 20;\n }\n\n return specificity + dateFnsFormat.length;\n};\n"],"mappings":";;;;;;eAEgBA,aAAqB,IAAa;EAChD,IAAIC,WAAW,GAAG,CAAC;EAEnB,IAAID,aAAa,CAACE,QAAQ,CAAC,MAAM,CAAC,EAAE;IAClCD,WAAW,IAAI,EAAE;EACnB,CAAC,MAAM,IAAID,aAAa,CAACE,QAAQ,CAAC,IAAI,CAAC,EAAE;IACvCD,WAAW,IAAI,EAAE;EACnB;EAEA,IAAID,aAAa,CAACE,QAAQ,CAAC,GAAG,CAAC,EAAE;IAC/BD,WAAW,IAAI,EAAE;EACnB;EAEA,IAAI,GAAG,CAACE,IAAI,CAACH,aAAa,CAAC,EAAE;IAC3BC,WAAW,IAAI,EAAE;EACnB;EAEA,OAAOA,WAAW,GAAGD,aAAa,CAACI,MAAM;AAC3C,CAAC;AAAAC,OAAA,CAAAC,OAAA,GAAAC,QAAA","ignoreList":[]}
@@ -1,165 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.default = void 0;
7
- var _cartesian = _interopRequireDefault(require("cartesian"));
8
- var _calculateSpecificity = _interopRequireDefault(require("./calculateSpecificity"));
9
- function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
10
- const formatCombinaison = combination => combination.join(' ').replace(' ,', ',').replace(/ +/, ' ').replace(/ $/, '');
11
- var _default = () => {
12
- // The reason `yearFirstDashSeparator` and `yearFirstSlashSeparator` formats do not have direction is because
13
- // there are no known regions that use yyyy-dd-MM format.
14
- // https://en.wikipedia.org/wiki/Date_format_by_country
15
- const yearFirstDashSeparator = [{
16
- dateFnsFormat: 'yyyy-MM-dd'
17
- }, {
18
- dateFnsFormat: 'yyyy-M-d'
19
- }];
20
- const yearFirstSlashSeparator = [{
21
- dateFnsFormat: 'yyyy/MM/dd'
22
- }, {
23
- dateFnsFormat: 'yyyy/M/d'
24
- }];
25
- const yearFirstDotSeparator = [{
26
- dateFnsFormat: 'yyyy.MM.dd',
27
- direction: 'YMD'
28
- }, {
29
- dateFnsFormat: 'yyyy.M.d',
30
- direction: 'YMD'
31
- }, {
32
- dateFnsFormat: 'yyyy.dd.MM',
33
- direction: 'YDM'
34
- }, {
35
- dateFnsFormat: 'yyyy.d.M',
36
- direction: 'YDM'
37
- }];
38
- const yearLastDashSeparator = [{
39
- dateFnsFormat: 'dd-MM-yyyy',
40
- direction: 'DMY'
41
- }, {
42
- dateFnsFormat: 'd-M-yyyy',
43
- direction: 'DMY'
44
- }, {
45
- dateFnsFormat: 'MM-dd-yyyy',
46
- direction: 'MDY'
47
- }, {
48
- dateFnsFormat: 'M-d-yyyy',
49
- direction: 'MDY'
50
- }];
51
- const yearLastDotSeparator = [{
52
- dateFnsFormat: 'dd.MM.yyyy',
53
- direction: 'DMY'
54
- }, {
55
- dateFnsFormat: 'd.M.yyyy',
56
- direction: 'DMY'
57
- }, {
58
- dateFnsFormat: 'MM.dd.yyyy',
59
- direction: 'MDY'
60
- }, {
61
- dateFnsFormat: 'M.d.yyyy',
62
- direction: 'MDY'
63
- }, {
64
- dateFnsFormat: 'dd.MM.yy',
65
- direction: 'DMY'
66
- }, {
67
- dateFnsFormat: 'd.M.yy',
68
- direction: 'DMY'
69
- }];
70
- const yearLastSlashSeparator = [{
71
- dateFnsFormat: 'dd/MM/yyyy',
72
- direction: 'DMY'
73
- }, {
74
- dateFnsFormat: 'd/M/yyyy',
75
- direction: 'DMY'
76
- }, {
77
- dateFnsFormat: 'MM/dd/yyyy',
78
- direction: 'MDY'
79
- }, {
80
- dateFnsFormat: 'M/d/yyyy',
81
- direction: 'MDY'
82
- }, {
83
- dateFnsFormat: 'MM/dd/yy',
84
- direction: 'MDY'
85
- }, {
86
- dateFnsFormat: 'dd/MM/yy',
87
- direction: 'DMY'
88
- }, {
89
- dateFnsFormat: 'd/M/yy',
90
- direction: 'DMY'
91
- }, {
92
- dateFnsFormat: 'M/d/yy',
93
- direction: 'MDY'
94
- }];
95
- const localised = [...(0, _cartesian.default)([['MMMM'], ['d', 'do'], [',', ''], ['yyyy'], [',', '']]).map(combination => {
96
- return {
97
- dateFnsFormat: formatCombinaison(combination)
98
- };
99
- }), ...(0, _cartesian.default)([['do', 'd'], ['MMMM', 'MMM'], ['yyyy']]).map(combination => {
100
- return {
101
- dateFnsFormat: formatCombinaison(combination)
102
- };
103
- }), ...(0, _cartesian.default)([['MMMM', 'MMM'], ['yyyy'], ['do', 'd']]).map(combination => {
104
- return {
105
- dateFnsFormat: formatCombinaison(combination)
106
- };
107
- }), {
108
- dateFnsFormat: 'MMMM yyyy EEE do'
109
- }, {
110
- dateFnsFormat: 'MMMM yyyy EEE d'
111
- }];
112
- const impliedYearLocalised = [...(0, _cartesian.default)([['EEEE', 'EEE'], ['', ','], ['MMMM', 'MMM'], ['dd', 'do', 'd']]).map(combination => {
113
- return {
114
- dateFnsFormat: formatCombinaison(combination)
115
- };
116
- }), ...(0, _cartesian.default)([['EEEE', 'EEE'], ['', ','], ['dd', 'do', 'd'], ['MMMM', 'MMM']]).map(combination => {
117
- return {
118
- dateFnsFormat: formatCombinaison(combination)
119
- };
120
- }), ...(0, _cartesian.default)([['MMMM', 'MMM'], ['dd', 'do', 'd'], [',', '']]).map(combination => {
121
- return {
122
- dateFnsFormat: formatCombinaison(combination)
123
- };
124
- }), ...(0, _cartesian.default)([['dd', 'do', 'd'], ['MMMM', 'MMM'], [',', '']]).map(combination => {
125
- return {
126
- dateFnsFormat: formatCombinaison(combination)
127
- };
128
- })];
129
- const impliedYear = [...(0, _cartesian.default)([['dd', 'd'], ['/', '-', '.'], ['MM', 'M'], [',', '']]).map(combination => {
130
- return {
131
- dateFnsFormat: combination.join('').replace(' ,', ',').replace(/ +/, ' '),
132
- direction: 'DM'
133
- };
134
- }), ...(0, _cartesian.default)([['MM', 'M'], ['/', '-', '.'], ['dd', 'd'], [',', '']]).map(combination => {
135
- return {
136
- dateFnsFormat: combination.join('').replace(' ,', ',').replace(/ +/, ' '),
137
- direction: 'MD'
138
- };
139
- })];
140
- const relative = [{
141
- dateFnsFormat: 'R',
142
- test: false
143
- }];
144
- return [{
145
- dateFnsFormat: 'yyyyMMdd'
146
- }, ...yearFirstDashSeparator, ...yearFirstDotSeparator, ...yearFirstSlashSeparator, ...yearLastDashSeparator, ...yearLastDotSeparator, ...yearLastSlashSeparator, ...localised, ...impliedYearLocalised, ...impliedYear, ...relative].map(format => {
147
- return {
148
- localised: /eee|mmm/i.test(format.dateFnsFormat),
149
- specificity: (0, _calculateSpecificity.default)(format.dateFnsFormat),
150
- wordCount: format.dateFnsFormat.replace(/[^ ]/g, '').length + 1,
151
- yearIsExplicit: format.dateFnsFormat.includes('yyyy'),
152
- ...format
153
- };
154
- }).sort((a, b) => {
155
- if (a.wordCount !== b.wordCount) {
156
- return b.wordCount - a.wordCount;
157
- }
158
- if (b.specificity === a.specificity) {
159
- return a.dateFnsFormat.localeCompare(b.dateFnsFormat);
160
- }
161
- return b.specificity - a.specificity;
162
- });
163
- };
164
- exports.default = _default;
165
- //# sourceMappingURL=createFormats.js.map
@@ -1,373 +0,0 @@
1
- // @flow
2
-
3
- import cartesian from 'cartesian';
4
- import calculateSpecificity from './calculateSpecificity';
5
-
6
- const formatCombinaison = (combination) => combination.join(' ').replace(' ,', ',').replace(/ +/, ' ').replace(/ $/, '')
7
-
8
- export default () => {
9
- // The reason `yearFirstDashSeparator` and `yearFirstSlashSeparator` formats do not have direction is because
10
- // there are no known regions that use yyyy-dd-MM format.
11
- // https://en.wikipedia.org/wiki/Date_format_by_country
12
- const yearFirstDashSeparator = [
13
- {
14
- dateFnsFormat: 'yyyy-MM-dd',
15
- },
16
- {
17
- dateFnsFormat: 'yyyy-M-d',
18
- },
19
- ];
20
-
21
- const yearFirstSlashSeparator = [
22
- {
23
- dateFnsFormat: 'yyyy/MM/dd',
24
- },
25
- {
26
- dateFnsFormat: 'yyyy/M/d',
27
- },
28
- ];
29
-
30
- const yearFirstDotSeparator = [
31
- {
32
- dateFnsFormat: 'yyyy.MM.dd',
33
- direction: 'YMD',
34
- },
35
- {
36
- dateFnsFormat: 'yyyy.M.d',
37
- direction: 'YMD',
38
- },
39
- {
40
- dateFnsFormat: 'yyyy.dd.MM',
41
- direction: 'YDM',
42
- },
43
- {
44
- dateFnsFormat: 'yyyy.d.M',
45
- direction: 'YDM',
46
- },
47
- ];
48
-
49
- const yearLastDashSeparator = [
50
- {
51
- dateFnsFormat: 'dd-MM-yyyy',
52
- direction: 'DMY',
53
- },
54
- {
55
- dateFnsFormat: 'd-M-yyyy',
56
- direction: 'DMY',
57
- },
58
- {
59
- dateFnsFormat: 'MM-dd-yyyy',
60
- direction: 'MDY',
61
- },
62
- {
63
- dateFnsFormat: 'M-d-yyyy',
64
- direction: 'MDY',
65
- },
66
- ];
67
-
68
- const yearLastDotSeparator = [
69
- {
70
- dateFnsFormat: 'dd.MM.yyyy',
71
- direction: 'DMY',
72
- },
73
- {
74
- dateFnsFormat: 'd.M.yyyy',
75
- direction: 'DMY',
76
- },
77
- {
78
- dateFnsFormat: 'MM.dd.yyyy',
79
- direction: 'MDY',
80
- },
81
- {
82
- dateFnsFormat: 'M.d.yyyy',
83
- direction: 'MDY',
84
- },
85
- {
86
- dateFnsFormat: 'dd.MM.yy',
87
- direction: 'DMY',
88
- },
89
- {
90
- dateFnsFormat: 'd.M.yy',
91
- direction: 'DMY',
92
- },
93
- ];
94
-
95
- const yearLastSlashSeparator = [
96
- {
97
- dateFnsFormat: 'dd/MM/yyyy',
98
- direction: 'DMY',
99
- },
100
- {
101
- dateFnsFormat: 'd/M/yyyy',
102
- direction: 'DMY',
103
- },
104
- {
105
- dateFnsFormat: 'MM/dd/yyyy',
106
- direction: 'MDY',
107
- },
108
- {
109
- dateFnsFormat: 'M/d/yyyy',
110
- direction: 'MDY',
111
- },
112
- {
113
- dateFnsFormat: 'MM/dd/yy',
114
- direction: 'MDY',
115
- },
116
- {
117
- dateFnsFormat: 'dd/MM/yy',
118
- direction: 'DMY',
119
- },
120
- {
121
- dateFnsFormat: 'd/M/yy',
122
- direction: 'DMY',
123
- },
124
- {
125
- dateFnsFormat: 'M/d/yy',
126
- direction: 'MDY',
127
- },
128
- ];
129
-
130
- const localised = [
131
- ...cartesian([
132
- ['MMMM'],
133
- ['d', 'do'],
134
- [',', ''],
135
- ['yyyy'],
136
- [',', ''],
137
- ])
138
- .map((combination) => {
139
- return {
140
- dateFnsFormat: formatCombinaison(combination),
141
- };
142
- }),
143
- ...cartesian([
144
- [
145
- 'do',
146
- 'd',
147
- ],
148
- [
149
- 'MMMM',
150
- 'MMM',
151
- ],
152
- [
153
- 'yyyy',
154
- ],
155
- ])
156
- .map((combination) => {
157
- return {
158
- dateFnsFormat: formatCombinaison(combination),
159
- };
160
- }),
161
- ...cartesian([
162
- [
163
- 'MMMM',
164
- 'MMM',
165
- ],
166
- [
167
- 'yyyy',
168
- ],
169
- [
170
- 'do',
171
- 'd',
172
- ],
173
- ])
174
- .map((combination) => {
175
- return {
176
- dateFnsFormat: formatCombinaison(combination),
177
- };
178
- }),
179
- {
180
- dateFnsFormat: 'MMMM yyyy EEE do',
181
- },
182
- {
183
- dateFnsFormat: 'MMMM yyyy EEE d',
184
- },
185
- ];
186
-
187
- const impliedYearLocalised = [
188
- ...cartesian([
189
- [
190
- 'EEEE',
191
- 'EEE',
192
- ],
193
- [
194
- '',
195
- ',',
196
- ],
197
- [
198
- 'MMMM',
199
- 'MMM',
200
- ],
201
- [
202
- 'dd',
203
- 'do',
204
- 'd',
205
- ],
206
- ])
207
- .map((combination) => {
208
- return {
209
- dateFnsFormat: formatCombinaison(combination),
210
- };
211
- }),
212
- ...cartesian([
213
- [
214
- 'EEEE',
215
- 'EEE',
216
- ],
217
- [
218
- '',
219
- ',',
220
- ],
221
- [
222
- 'dd',
223
- 'do',
224
- 'd',
225
- ],
226
- [
227
- 'MMMM',
228
- 'MMM',
229
- ],
230
- ])
231
- .map((combination) => {
232
- return {
233
- dateFnsFormat: formatCombinaison(combination),
234
- };
235
- }),
236
- ...cartesian([
237
- [
238
- 'MMMM',
239
- 'MMM',
240
- ],
241
- [
242
- 'dd',
243
- 'do',
244
- 'd',
245
- ],
246
- [
247
- ',',
248
- '',
249
- ],
250
- ])
251
- .map((combination) => {
252
- return {
253
- dateFnsFormat: formatCombinaison(combination),
254
- };
255
- }),
256
- ...cartesian([
257
- [
258
- 'dd',
259
- 'do',
260
- 'd',
261
- ],
262
- [
263
- 'MMMM',
264
- 'MMM',
265
- ],
266
- [
267
- ',',
268
- '',
269
- ],
270
- ])
271
- .map((combination) => {
272
- return {
273
- dateFnsFormat: formatCombinaison(combination),
274
- };
275
- }),
276
- ];
277
-
278
- const impliedYear = [
279
- ...cartesian([
280
- [
281
- 'dd',
282
- 'd',
283
- ],
284
- [
285
- '/',
286
- '-',
287
- '.',
288
- ],
289
- [
290
- 'MM',
291
- 'M',
292
- ],
293
- [
294
- ',',
295
- '',
296
- ],
297
- ])
298
- .map((combination) => {
299
- return {
300
- dateFnsFormat: combination.join('').replace(' ,', ',').replace(/ +/, ' '),
301
- direction: 'DM',
302
- };
303
- }),
304
- ...cartesian([
305
- [
306
- 'MM',
307
- 'M',
308
- ],
309
- [
310
- '/',
311
- '-',
312
- '.',
313
- ],
314
- [
315
- 'dd',
316
- 'd',
317
- ],
318
- [
319
- ',',
320
- '',
321
- ],
322
- ])
323
- .map((combination) => {
324
- return {
325
- dateFnsFormat: combination.join('').replace(' ,', ',').replace(/ +/, ' '),
326
- direction: 'MD',
327
- };
328
- }),
329
- ];
330
-
331
- const relative = [
332
- {
333
- dateFnsFormat: 'R',
334
- test: false,
335
- }
336
- ];
337
-
338
- return [
339
- {
340
- dateFnsFormat: 'yyyyMMdd',
341
- },
342
- ...yearFirstDashSeparator,
343
- ...yearFirstDotSeparator,
344
- ...yearFirstSlashSeparator,
345
- ...yearLastDashSeparator,
346
- ...yearLastDotSeparator,
347
- ...yearLastSlashSeparator,
348
- ...localised,
349
- ...impliedYearLocalised,
350
- ...impliedYear,
351
- ...relative,
352
- ]
353
- .map((format) => {
354
- return {
355
- localised: /eee|mmm/i.test(format.dateFnsFormat),
356
- specificity: calculateSpecificity(format.dateFnsFormat),
357
- wordCount: format.dateFnsFormat.replace(/[^ ]/g, '').length + 1,
358
- yearIsExplicit: format.dateFnsFormat.includes('yyyy'),
359
- ...format,
360
- };
361
- })
362
- .sort((a, b) => {
363
- if (a.wordCount !== b.wordCount) {
364
- return b.wordCount - a.wordCount;
365
- }
366
-
367
- if (b.specificity === a.specificity) {
368
- return a.dateFnsFormat.localeCompare(b.dateFnsFormat);
369
- }
370
-
371
- return b.specificity - a.specificity;
372
- });
373
- };
@@ -1 +0,0 @@
1
- {"version":3,"file":"createFormats.js","names":["_cartesian","_interopRequireDefault","require","_calculateSpecificity","e","__esModule","default","formatCombinaison","combination","join","replace","_default","yearFirstDashSeparator","dateFnsFormat","yearFirstSlashSeparator","yearFirstDotSeparator","direction","yearLastDashSeparator","yearLastDotSeparator","yearLastSlashSeparator","localised","cartesian","map","impliedYearLocalised","impliedYear","relative","test","format","specificity","calculateSpecificity","wordCount","length","yearIsExplicit","includes","sort","a","b","localeCompare","exports"],"sources":["../src/createFormats.js"],"sourcesContent":["// @flow\n\nimport cartesian from 'cartesian';\nimport calculateSpecificity from './calculateSpecificity';\n\nconst formatCombinaison = (combination) => combination.join(' ').replace(' ,', ',').replace(/ +/, ' ').replace(/ $/, '')\n\nexport default () => {\n // The reason `yearFirstDashSeparator` and `yearFirstSlashSeparator` formats do not have direction is because\n // there are no known regions that use yyyy-dd-MM format.\n // https://en.wikipedia.org/wiki/Date_format_by_country\n const yearFirstDashSeparator = [\n {\n dateFnsFormat: 'yyyy-MM-dd',\n },\n {\n dateFnsFormat: 'yyyy-M-d',\n },\n ];\n\n const yearFirstSlashSeparator = [\n {\n dateFnsFormat: 'yyyy/MM/dd',\n },\n {\n dateFnsFormat: 'yyyy/M/d',\n },\n ];\n\n const yearFirstDotSeparator = [\n {\n dateFnsFormat: 'yyyy.MM.dd',\n direction: 'YMD',\n },\n {\n dateFnsFormat: 'yyyy.M.d',\n direction: 'YMD',\n },\n {\n dateFnsFormat: 'yyyy.dd.MM',\n direction: 'YDM',\n },\n {\n dateFnsFormat: 'yyyy.d.M',\n direction: 'YDM',\n },\n ];\n\n const yearLastDashSeparator = [\n {\n dateFnsFormat: 'dd-MM-yyyy',\n direction: 'DMY',\n },\n {\n dateFnsFormat: 'd-M-yyyy',\n direction: 'DMY',\n },\n {\n dateFnsFormat: 'MM-dd-yyyy',\n direction: 'MDY',\n },\n {\n dateFnsFormat: 'M-d-yyyy',\n direction: 'MDY',\n },\n ];\n\n const yearLastDotSeparator = [\n {\n dateFnsFormat: 'dd.MM.yyyy',\n direction: 'DMY',\n },\n {\n dateFnsFormat: 'd.M.yyyy',\n direction: 'DMY',\n },\n {\n dateFnsFormat: 'MM.dd.yyyy',\n direction: 'MDY',\n },\n {\n dateFnsFormat: 'M.d.yyyy',\n direction: 'MDY',\n },\n {\n dateFnsFormat: 'dd.MM.yy',\n direction: 'DMY',\n },\n {\n dateFnsFormat: 'd.M.yy',\n direction: 'DMY',\n },\n ];\n\n const yearLastSlashSeparator = [\n {\n dateFnsFormat: 'dd/MM/yyyy',\n direction: 'DMY',\n },\n {\n dateFnsFormat: 'd/M/yyyy',\n direction: 'DMY',\n },\n {\n dateFnsFormat: 'MM/dd/yyyy',\n direction: 'MDY',\n },\n {\n dateFnsFormat: 'M/d/yyyy',\n direction: 'MDY',\n },\n {\n dateFnsFormat: 'MM/dd/yy',\n direction: 'MDY',\n },\n {\n dateFnsFormat: 'dd/MM/yy',\n direction: 'DMY',\n },\n {\n dateFnsFormat: 'd/M/yy',\n direction: 'DMY',\n },\n {\n dateFnsFormat: 'M/d/yy',\n direction: 'MDY',\n },\n ];\n\n const localised = [\n ...cartesian([\n ['MMMM'],\n ['d', 'do'],\n [',', ''],\n ['yyyy'],\n [',', ''],\n ])\n .map((combination) => {\n return {\n dateFnsFormat: formatCombinaison(combination),\n };\n }),\n ...cartesian([\n [\n 'do',\n 'd',\n ],\n [\n 'MMMM',\n 'MMM',\n ],\n [\n 'yyyy',\n ],\n ])\n .map((combination) => {\n return {\n dateFnsFormat: formatCombinaison(combination),\n };\n }),\n ...cartesian([\n [\n 'MMMM',\n 'MMM',\n ],\n [\n 'yyyy',\n ],\n [\n 'do',\n 'd',\n ],\n ])\n .map((combination) => {\n return {\n dateFnsFormat: formatCombinaison(combination),\n };\n }),\n {\n dateFnsFormat: 'MMMM yyyy EEE do',\n },\n {\n dateFnsFormat: 'MMMM yyyy EEE d',\n },\n ];\n\n const impliedYearLocalised = [\n ...cartesian([\n [\n 'EEEE',\n 'EEE',\n ],\n [\n '',\n ',',\n ],\n [\n 'MMMM',\n 'MMM',\n ],\n [\n 'dd',\n 'do',\n 'd',\n ],\n ])\n .map((combination) => {\n return {\n dateFnsFormat: formatCombinaison(combination),\n };\n }),\n ...cartesian([\n [\n 'EEEE',\n 'EEE',\n ],\n [\n '',\n ',',\n ],\n [\n 'dd',\n 'do',\n 'd',\n ],\n [\n 'MMMM',\n 'MMM',\n ],\n ])\n .map((combination) => {\n return {\n dateFnsFormat: formatCombinaison(combination),\n };\n }),\n ...cartesian([\n [\n 'MMMM',\n 'MMM',\n ],\n [\n 'dd',\n 'do',\n 'd',\n ],\n [\n ',',\n '',\n ],\n ])\n .map((combination) => {\n return {\n dateFnsFormat: formatCombinaison(combination),\n };\n }),\n ...cartesian([\n [\n 'dd',\n 'do',\n 'd',\n ],\n [\n 'MMMM',\n 'MMM',\n ],\n [\n ',',\n '',\n ],\n ])\n .map((combination) => {\n return {\n dateFnsFormat: formatCombinaison(combination),\n };\n }),\n ];\n\n const impliedYear = [\n ...cartesian([\n [\n 'dd',\n 'd',\n ],\n [\n '/',\n '-',\n '.',\n ],\n [\n 'MM',\n 'M',\n ],\n [\n ',',\n '',\n ],\n ])\n .map((combination) => {\n return {\n dateFnsFormat: combination.join('').replace(' ,', ',').replace(/ +/, ' '),\n direction: 'DM',\n };\n }),\n ...cartesian([\n [\n 'MM',\n 'M',\n ],\n [\n '/',\n '-',\n '.',\n ],\n [\n 'dd',\n 'd',\n ],\n [\n ',',\n '',\n ],\n ])\n .map((combination) => {\n return {\n dateFnsFormat: combination.join('').replace(' ,', ',').replace(/ +/, ' '),\n direction: 'MD',\n };\n }),\n ];\n\n const relative = [\n {\n dateFnsFormat: 'R',\n test: false,\n }\n ];\n\n return [\n {\n dateFnsFormat: 'yyyyMMdd',\n },\n ...yearFirstDashSeparator,\n ...yearFirstDotSeparator,\n ...yearFirstSlashSeparator,\n ...yearLastDashSeparator,\n ...yearLastDotSeparator,\n ...yearLastSlashSeparator,\n ...localised,\n ...impliedYearLocalised,\n ...impliedYear,\n ...relative,\n ]\n .map((format) => {\n return {\n localised: /eee|mmm/i.test(format.dateFnsFormat),\n specificity: calculateSpecificity(format.dateFnsFormat),\n wordCount: format.dateFnsFormat.replace(/[^ ]/g, '').length + 1,\n yearIsExplicit: format.dateFnsFormat.includes('yyyy'),\n ...format,\n };\n })\n .sort((a, b) => {\n if (a.wordCount !== b.wordCount) {\n return b.wordCount - a.wordCount;\n }\n\n if (b.specificity === a.specificity) {\n return a.dateFnsFormat.localeCompare(b.dateFnsFormat);\n }\n\n return b.specificity - a.specificity;\n });\n};\n"],"mappings":";;;;;;AAEA,IAAAA,UAAA,GAAAC,sBAAA,CAAAC,OAAA;AACA,IAAAC,qBAAA,GAAAF,sBAAA,CAAAC,OAAA;AAA0D,SAAAD,uBAAAG,CAAA,WAAAA,CAAA,IAAAA,CAAA,CAAAC,UAAA,GAAAD,CAAA,KAAAE,OAAA,EAAAF,CAAA;AAE1D,MAAMG,iBAAiB,GAAIC,WAAW,IAAKA,WAAW,CAACC,IAAI,CAAC,GAAG,CAAC,CAACC,OAAO,CAAC,IAAI,EAAE,GAAG,CAAC,CAACA,OAAO,CAAC,IAAI,EAAE,GAAG,CAAC,CAACA,OAAO,CAAC,IAAI,EAAE,EAAE,CAAC;AAAA,IAAAC,QAAA,GAEzGA,CAAA,KAAM;EACnB;EACA;EACA;EACA,MAAMC,sBAAsB,GAAG,CAC7B;IACEC,aAAa,EAAE;EACjB,CAAC,EACD;IACEA,aAAa,EAAE;EACjB,CAAC,CACF;EAED,MAAMC,uBAAuB,GAAG,CAC9B;IACED,aAAa,EAAE;EACjB,CAAC,EACD;IACEA,aAAa,EAAE;EACjB,CAAC,CACF;EAED,MAAME,qBAAqB,GAAG,CAC5B;IACEF,aAAa,EAAE,YAAY;IAC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C,cAAc,EAAEL,MAAM,CAACd,aAAa,CAACoB,QAAQ,CAAC,MAAM,CAAC;MACrD,GAAGN;IACL,CAAC;EACH,CAAC,CAAC,CACDO,IAAI,CAAC,CAACC,CAAC,EAAEC,CAAC,KAAK;IACd,IAAID,CAAC,CAACL,SAAS,KAAKM,CAAC,CAACN,SAAS,EAAE;MAC/B,OAAOM,CAAC,CAACN,SAAS,GAAGK,CAAC,CAACL,SAAS;IAClC;IAEA,IAAIM,CAAC,CAACR,WAAW,KAAKO,CAAC,CAACP,WAAW,EAAE;MACnC,OAAOO,CAAC,CAACtB,aAAa,CAACwB,aAAa,CAACD,CAAC,CAACvB,aAAa,CAAC;IACvD;IAEA,OAAOuB,CAAC,CAACR,WAAW,GAAGO,CAAC,CAACP,WAAW;EACtC,CAAC,CAAC;AACN,CAAC;AAAAU,OAAA,CAAAhC,OAAA,GAAAK,QAAA","ignoreList":[]}
@@ -1,20 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.default = void 0;
7
- var _default = (haystack, sliceLength) => {
8
- const slices = [];
9
- let index = 0;
10
- while (index < haystack.length) {
11
- const result = haystack.slice(index, index + sliceLength);
12
- if (result.length === sliceLength) {
13
- slices.push(result);
14
- }
15
- index++;
16
- }
17
- return slices;
18
- };
19
- exports.default = _default;
20
- //# sourceMappingURL=createMovingChunks.js.map
@@ -1,19 +0,0 @@
1
- // @flow
2
-
3
- export default (haystack: $ReadOnlyArray<string>, sliceLength: number): $ReadOnlyArray<$ReadOnlyArray<string>> => {
4
- const slices = [];
5
-
6
- let index = 0;
7
-
8
- while (index < haystack.length) {
9
- const result = haystack.slice(index, index + sliceLength);
10
-
11
- if (result.length === sliceLength) {
12
- slices.push(result);
13
- }
14
-
15
- index++;
16
- }
17
-
18
- return slices;
19
- };
@@ -1 +0,0 @@
1
- {"version":3,"file":"createMovingChunks.js","names":["_default","haystack","sliceLength","slices","index","length","result","slice","push","exports","default"],"sources":["../src/createMovingChunks.js"],"sourcesContent":["// @flow\n\nexport default (haystack: $ReadOnlyArray<string>, sliceLength: number): $ReadOnlyArray<$ReadOnlyArray<string>> => {\n const slices = [];\n\n let index = 0;\n\n while (index < haystack.length) {\n const result = haystack.slice(index, index + sliceLength);\n\n if (result.length === sliceLength) {\n slices.push(result);\n }\n\n index++;\n }\n\n return slices;\n};\n"],"mappings":";;;;;;eAEeA,CAACC,QAAgC,EAAEC,WAAmB,KAA6C;EAChH,MAAMC,MAAM,GAAG,EAAE;EAEjB,IAAIC,KAAK,GAAG,CAAC;EAEb,OAAOA,KAAK,GAAGH,QAAQ,CAACI,MAAM,EAAE;IAC9B,MAAMC,MAAM,GAAGL,QAAQ,CAACM,KAAK,CAACH,KAAK,EAAEA,KAAK,GAAGF,WAAW,CAAC;IAEzD,IAAII,MAAM,CAACD,MAAM,KAAKH,WAAW,EAAE;MACjCC,MAAM,CAACK,IAAI,CAACF,MAAM,CAAC;IACrB;IAEAF,KAAK,EAAE;EACT;EAEA,OAAOD,MAAM;AACf,CAAC;AAAAM,OAAA,CAAAC,OAAA,GAAAV,QAAA","ignoreList":[]}