@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
package/package.json CHANGED
@@ -1,19 +1,7 @@
1
1
  {
2
2
  "author": "Gajus Kuizinas <gajus@gajus.com> (http://gajus.com)",
3
- "ava": {
4
- "babel": {
5
- "compileAsTests": [
6
- "test/helpers/**/*"
7
- ]
8
- },
9
- "files": [
10
- "test/extract-date/**/*"
11
- ],
12
- "require": [
13
- "@babel/register"
14
- ]
15
- },
16
3
  "dependencies": {
4
+ "@louis.jln/extract-date": "^3.0.1",
17
5
  "cartesian": "^1.0.1",
18
6
  "date-fns": "^2.9.0",
19
7
  "moment": "^2.24.0",
@@ -22,35 +10,16 @@
22
10
  },
23
11
  "description": "Extracts date from an arbitrary text input.",
24
12
  "devDependencies": {
25
- "@ava/babel": "^1.0.0",
26
- "@babel/cli": "^7.8.4",
27
- "@babel/core": "^7.8.4",
28
- "@babel/node": "^7.8.4",
29
- "@babel/plugin-transform-flow-strip-types": "^7.8.3",
30
- "@babel/preset-env": "^7.8.4",
31
- "@babel/register": "^7.8.3",
32
- "ava": "^3.1.0",
33
- "babel-plugin-istanbul": "^6.0.0",
34
- "coveralls": "^3.0.9",
35
- "esbuild": "^0.24.0",
36
- "eslint": "^6.8.0",
37
- "eslint-config-canonical": "^18.1.0",
38
- "flow-bin": "^0.117.0",
39
- "flow-copy-source": "^2.0.9",
40
- "gitdown": "^3.1.2",
41
- "husky": "^4.2.1",
42
- "nyc": "^15.0.0",
43
- "semantic-release": "^17.0.2",
44
- "sinon": "^8.1.1"
13
+ "@types/node": "^20.0.0",
14
+ "esbuild": "^0.27.3",
15
+ "eslint": "^10.0.2",
16
+ "husky": "^9.1.7",
17
+ "typescript": "^5.9.3",
18
+ "typescript-eslint": "^8.56.1",
19
+ "vitest": "^4.0.18"
45
20
  },
46
21
  "engines": {
47
- "node": ">6"
48
- },
49
- "husky": {
50
- "hooks": {
51
- "pre-commit": "npm run lint && npm run test && npm run build",
52
- "pre-push": "gitdown ./.README/README.md --output-file ./README.md --check"
53
- }
22
+ "node": ">=20"
54
23
  },
55
24
  "keywords": [
56
25
  "date",
@@ -59,38 +28,26 @@
59
28
  "parse"
60
29
  ],
61
30
  "license": "BSD-3-Clause",
62
- "main": "./dist/index.js",
31
+ "main": "./index.js",
63
32
  "name": "@louis.jln/extract-date",
64
- "nyc": {
65
- "include": [
66
- "src/**/*.js"
67
- ],
68
- "instrument": false,
69
- "reporter": [
70
- "text-lcov"
71
- ],
72
- "require": [
73
- "@babel/register"
74
- ],
75
- "sourceMap": false
76
- },
77
33
  "repository": {
78
34
  "type": "git",
79
- "url": "git+https://github.com/gajus/extract-date.git"
35
+ "url": "git+https://github.com/LouisJULIEN/extract-date.git"
80
36
  },
81
37
  "scripts": {
82
- "build": "rm -fr ./dist && NODE_ENV=production babel ./src --out-dir ./dist --copy-files --source-maps && flow-copy-source src dist",
83
- "create-readme": "gitdown ./.README/README.md --output-file ./README.md",
84
- "lint": "eslint ./src ./test && flow",
85
- "test": "NODE_ENV=test ava --verbose --serial",
86
- "bundle": "esbuild dist/index.js --bundle --outfile=bundle/extract-date.js --format=esm"
87
- },
88
- "version": "3.0.0",
38
+ "build": "rm -fr ./dist && tsc --project tsconfig.json",
39
+ "lint": "eslint ./src ./test",
40
+ "test": "vitest run",
41
+ "typecheck": "tsc --noEmit",
42
+ "npm-publish": "rm -rf build; npm run build; cp package.json dist/package.json; cd dist; npm publish --access public",
43
+ "prepare": "husky"
44
+ },
45
+ "version": "4.0.0",
89
46
  "directories": {
90
47
  "test": "test"
91
48
  },
92
49
  "bugs": {
93
- "url": "https://github.com/gajus/extract-date/issues"
50
+ "url": "https://github.com/LouisJULIEN/extract-date/issues"
94
51
  },
95
- "homepage": "https://github.com/gajus/extract-date#readme"
52
+ "homepage": "https://github.com/LouisJULIEN/extract-date"
96
53
  }
@@ -0,0 +1,2 @@
1
+ declare const _default: (dateFnsFormat: string) => number;
2
+ export default _default;
@@ -1,21 +1,16 @@
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;
1
+ export default (dateFnsFormat) => {
2
+ let specificity = 0;
3
+ if (dateFnsFormat.includes('yyyy')) {
4
+ specificity += 40;
5
+ }
6
+ else if (dateFnsFormat.includes('yy')) {
7
+ specificity += 20;
8
+ }
9
+ if (dateFnsFormat.includes('M')) {
10
+ specificity += 20;
11
+ }
12
+ if (/d/.test(dateFnsFormat)) {
13
+ specificity += 20;
14
+ }
15
+ return specificity + dateFnsFormat.length;
21
16
  };
@@ -0,0 +1,13 @@
1
+ type FormatEntry = {
2
+ dateFnsFormat: string;
3
+ direction?: string;
4
+ test?: boolean;
5
+ };
6
+ type Format = FormatEntry & {
7
+ localised: boolean;
8
+ specificity: number;
9
+ wordCount: number;
10
+ yearIsExplicit: boolean;
11
+ };
12
+ declare const _default: () => Format[];
13
+ export default _default;
@@ -1,373 +1,140 @@
1
- // @flow
2
-
3
1
  import cartesian from 'cartesian';
4
- import calculateSpecificity from './calculateSpecificity';
5
-
6
- const formatCombinaison = (combination) => combination.join(' ').replace(' ,', ',').replace(/ +/, ' ').replace(/ $/, '')
7
-
2
+ import calculateSpecificity from '@/calculateSpecificity';
3
+ const formatCombinaison = (combination) => combination.join(' ').replace(' ,', ',').replace(/ +/, ' ').replace(/ $/, '');
8
4
  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 {
5
+ const yearFirstDashSeparator = [
6
+ { dateFnsFormat: 'yyyy-MM-dd' },
7
+ { dateFnsFormat: 'yyyy-M-d' },
8
+ ];
9
+ const yearFirstSlashSeparator = [
10
+ { dateFnsFormat: 'yyyy/MM/dd' },
11
+ { dateFnsFormat: 'yyyy/M/d' },
12
+ ];
13
+ const yearFirstDotSeparator = [
14
+ { dateFnsFormat: 'yyyy.MM.dd', direction: 'YMD' },
15
+ { dateFnsFormat: 'yyyy.M.d', direction: 'YMD' },
16
+ { dateFnsFormat: 'yyyy.dd.MM', direction: 'YDM' },
17
+ { dateFnsFormat: 'yyyy.d.M', direction: 'YDM' },
18
+ ];
19
+ const yearLastDashSeparator = [
20
+ { dateFnsFormat: 'dd-MM-yyyy', direction: 'DMY' },
21
+ { dateFnsFormat: 'd-M-yyyy', direction: 'DMY' },
22
+ { dateFnsFormat: 'MM-dd-yyyy', direction: 'MDY' },
23
+ { dateFnsFormat: 'M-d-yyyy', direction: 'MDY' },
24
+ ];
25
+ const yearLastDotSeparator = [
26
+ { dateFnsFormat: 'dd.MM.yyyy', direction: 'DMY' },
27
+ { dateFnsFormat: 'd.M.yyyy', direction: 'DMY' },
28
+ { dateFnsFormat: 'MM.dd.yyyy', direction: 'MDY' },
29
+ { dateFnsFormat: 'M.d.yyyy', direction: 'MDY' },
30
+ { dateFnsFormat: 'dd.MM.yy', direction: 'DMY' },
31
+ { dateFnsFormat: 'd.M.yy', direction: 'DMY' },
32
+ ];
33
+ const yearLastSlashSeparator = [
34
+ { dateFnsFormat: 'dd/MM/yyyy', direction: 'DMY' },
35
+ { dateFnsFormat: 'd/M/yyyy', direction: 'DMY' },
36
+ { dateFnsFormat: 'MM/dd/yyyy', direction: 'MDY' },
37
+ { dateFnsFormat: 'M/d/yyyy', direction: 'MDY' },
38
+ { dateFnsFormat: 'MM/dd/yy', direction: 'MDY' },
39
+ { dateFnsFormat: 'dd/MM/yy', direction: 'DMY' },
40
+ { dateFnsFormat: 'd/M/yy', direction: 'DMY' },
41
+ { dateFnsFormat: 'M/d/yy', direction: 'MDY' },
42
+ ];
43
+ const localised = [
44
+ ...cartesian([
45
+ ['MMMM'],
46
+ ['d', 'do'],
47
+ [',', ''],
48
+ ['yyyy'],
49
+ [',', ''],
50
+ ]).map((combination) => ({ dateFnsFormat: formatCombinaison(combination) })),
51
+ ...cartesian([
52
+ ['do', 'd'],
53
+ ['MMMM', 'MMM'],
54
+ ['yyyy'],
55
+ ]).map((combination) => ({ dateFnsFormat: formatCombinaison(combination) })),
56
+ ...cartesian([
57
+ ['MMMM', 'MMM'],
58
+ ['yyyy'],
59
+ ['do', 'd'],
60
+ ]).map((combination) => ({ dateFnsFormat: formatCombinaison(combination) })),
61
+ { dateFnsFormat: 'MMMM yyyy EEE do' },
62
+ { dateFnsFormat: 'MMMM yyyy EEE d' },
63
+ ];
64
+ const impliedYearLocalised = [
65
+ ...cartesian([
66
+ ['EEEE', 'EEE'],
67
+ ['', ','],
68
+ ['MMMM', 'MMM'],
69
+ ['dd', 'do', 'd'],
70
+ ]).map((combination) => ({ dateFnsFormat: formatCombinaison(combination) })),
71
+ ...cartesian([
72
+ ['EEEE', 'EEE'],
73
+ ['', ','],
74
+ ['dd', 'do', 'd'],
75
+ ['MMMM', 'MMM'],
76
+ ]).map((combination) => ({ dateFnsFormat: formatCombinaison(combination) })),
77
+ ...cartesian([
78
+ ['MMMM', 'MMM'],
79
+ ['dd', 'do', 'd'],
80
+ [',', ''],
81
+ ]).map((combination) => ({ dateFnsFormat: formatCombinaison(combination) })),
82
+ ...cartesian([
83
+ ['dd', 'do', 'd'],
84
+ ['MMMM', 'MMM'],
85
+ [',', ''],
86
+ ]).map((combination) => ({ dateFnsFormat: formatCombinaison(combination) })),
87
+ ];
88
+ const impliedYear = [
89
+ ...cartesian([
90
+ ['dd', 'd'],
91
+ ['/', '-', '.'],
92
+ ['MM', 'M'],
93
+ [',', ''],
94
+ ]).map((combination) => ({
95
+ dateFnsFormat: combination.join('').replace(' ,', ',').replace(/ +/, ' '),
96
+ direction: 'DM',
97
+ })),
98
+ ...cartesian([
99
+ ['MM', 'M'],
100
+ ['/', '-', '.'],
101
+ ['dd', 'd'],
102
+ [',', ''],
103
+ ]).map((combination) => ({
104
+ dateFnsFormat: combination.join('').replace(' ,', ',').replace(/ +/, ' '),
105
+ direction: 'MD',
106
+ })),
107
+ ];
108
+ const relative = [
109
+ { dateFnsFormat: 'R', test: false },
110
+ ];
111
+ return [
112
+ { dateFnsFormat: 'yyyyMMdd' },
113
+ ...yearFirstDashSeparator,
114
+ ...yearFirstDotSeparator,
115
+ ...yearFirstSlashSeparator,
116
+ ...yearLastDashSeparator,
117
+ ...yearLastDotSeparator,
118
+ ...yearLastSlashSeparator,
119
+ ...localised,
120
+ ...impliedYearLocalised,
121
+ ...impliedYear,
122
+ ...relative,
123
+ ]
124
+ .map((format) => ({
355
125
  localised: /eee|mmm/i.test(format.dateFnsFormat),
356
126
  specificity: calculateSpecificity(format.dateFnsFormat),
357
127
  wordCount: format.dateFnsFormat.replace(/[^ ]/g, '').length + 1,
358
128
  yearIsExplicit: format.dateFnsFormat.includes('yyyy'),
359
129
  ...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;
130
+ }))
131
+ .sort((a, b) => {
132
+ if (a.wordCount !== b.wordCount) {
133
+ return b.wordCount - a.wordCount;
134
+ }
135
+ if (b.specificity === a.specificity) {
136
+ return a.dateFnsFormat.localeCompare(b.dateFnsFormat);
137
+ }
138
+ return b.specificity - a.specificity;
372
139
  });
373
140
  };
@@ -0,0 +1,2 @@
1
+ declare const _default: (haystack: readonly string[], sliceLength: number) => readonly (readonly string[])[];
2
+ export default _default;