@louis.jln/extract-date 3.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.
- package/.flowconfig +3 -0
- package/LICENSE +24 -0
- package/README.md +184 -0
- package/bundle/extract-date.js +61276 -0
- package/dist/calculateSpecificity.js +23 -0
- package/dist/calculateSpecificity.js.flow +21 -0
- package/dist/calculateSpecificity.js.map +1 -0
- package/dist/createFormats.js +165 -0
- package/dist/createFormats.js.flow +373 -0
- package/dist/createFormats.js.map +1 -0
- package/dist/createMovingChunks.js +20 -0
- package/dist/createMovingChunks.js.flow +19 -0
- package/dist/createMovingChunks.js.map +1 -0
- package/dist/dictionary.json +3792 -0
- package/dist/extractDate.js +148 -0
- package/dist/extractDate.js.flow +214 -0
- package/dist/extractDate.js.map +1 -0
- package/dist/extractRelativeDate.js +32 -0
- package/dist/extractRelativeDate.js.flow +34 -0
- package/dist/extractRelativeDate.js.map +1 -0
- package/dist/index.js +11 -0
- package/dist/index.js.flow +6 -0
- package/dist/index.js.map +1 -0
- package/dist/normalizeInput.js +22 -0
- package/dist/normalizeInput.js.flow +26 -0
- package/dist/normalizeInput.js.map +1 -0
- package/dist/types.js +2 -0
- package/dist/types.js.flow +23 -0
- package/dist/types.js.map +1 -0
- package/package.json +96 -0
- package/src/calculateSpecificity.js +21 -0
- package/src/createFormats.js +373 -0
- package/src/createMovingChunks.js +19 -0
- package/src/dictionary.json +3792 -0
- package/src/extractDate.js +214 -0
- package/src/extractRelativeDate.js +34 -0
- package/src/index.js +6 -0
- package/src/normalizeInput.js +26 -0
- package/src/types.js +23 -0
|
@@ -0,0 +1,148 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.default = void 0;
|
|
7
|
+
var _dateFns = require("date-fns");
|
|
8
|
+
var locales = _interopRequireWildcard(require("date-fns/locale"));
|
|
9
|
+
var _momentTimezone = _interopRequireDefault(require("moment-timezone"));
|
|
10
|
+
var _relativeDateNames = _interopRequireDefault(require("relative-date-names"));
|
|
11
|
+
var _createMovingChunks = _interopRequireDefault(require("./createMovingChunks"));
|
|
12
|
+
var _extractRelativeDate = _interopRequireDefault(require("./extractRelativeDate"));
|
|
13
|
+
var _createFormats = _interopRequireDefault(require("./createFormats"));
|
|
14
|
+
var _normalizeInput = _interopRequireDefault(require("./normalizeInput"));
|
|
15
|
+
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
16
|
+
function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); }
|
|
17
|
+
function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && {}.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
|
|
18
|
+
/* eslint-disable no-continue, no-negated-condition, import/no-namespace */
|
|
19
|
+
const defaultConfiguration = {
|
|
20
|
+
maximumAge: Infinity,
|
|
21
|
+
minimumAge: Infinity
|
|
22
|
+
};
|
|
23
|
+
const formats = (0, _createFormats.default)();
|
|
24
|
+
const dateFnsLocaleMap = {
|
|
25
|
+
en: 'enUS'
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
// eslint-disable-next-line complexity
|
|
29
|
+
var _default = (input, userConfiguration = defaultConfiguration) => {
|
|
30
|
+
const normalizedInput = (0, _normalizeInput.default)(input);
|
|
31
|
+
const configuration = {
|
|
32
|
+
...defaultConfiguration,
|
|
33
|
+
...userConfiguration
|
|
34
|
+
};
|
|
35
|
+
const locale = configuration.locale || 'en';
|
|
36
|
+
const dateFnsLocale = locales[dateFnsLocaleMap[locale] || locale];
|
|
37
|
+
if (!dateFnsLocale) {
|
|
38
|
+
throw new Error('No translation available for the target locale (date-fns).');
|
|
39
|
+
}
|
|
40
|
+
if (!_relativeDateNames.default[locale]) {
|
|
41
|
+
throw new Error('No translation available for the target locale (relative dates).');
|
|
42
|
+
}
|
|
43
|
+
if (configuration.timezone && !_momentTimezone.default.tz.zone(configuration.timezone)) {
|
|
44
|
+
throw new Error('Unrecognized timezone.');
|
|
45
|
+
}
|
|
46
|
+
if (configuration.maximumAge && configuration.maximumAge < 0) {
|
|
47
|
+
throw new Error('`maximumAge` must be a positive number.');
|
|
48
|
+
}
|
|
49
|
+
if (configuration.minimumAge && configuration.minimumAge < 0) {
|
|
50
|
+
throw new Error('`minimumAge` must be a positive number.');
|
|
51
|
+
}
|
|
52
|
+
let words = normalizedInput.split(' ');
|
|
53
|
+
const matches = [];
|
|
54
|
+
const baseDate = (0, _dateFns.parse)('12:00', 'HH:mm', new Date());
|
|
55
|
+
for (const format of formats) {
|
|
56
|
+
const movingChunks = (0, _createMovingChunks.default)(words, format.wordCount);
|
|
57
|
+
let chunkIndex = 0;
|
|
58
|
+
for (const movingChunk of movingChunks) {
|
|
59
|
+
const wordOffset = ++chunkIndex * format.wordCount;
|
|
60
|
+
const subject = movingChunk.join(' ');
|
|
61
|
+
if (format.dateFnsFormat === 'R') {
|
|
62
|
+
if (!configuration.locale) {} else if (!configuration.timezone) {} else {
|
|
63
|
+
const maybeDate = (0, _extractRelativeDate.default)(subject, configuration.locale, configuration.timezone);
|
|
64
|
+
if (maybeDate) {
|
|
65
|
+
words = words.slice(wordOffset);
|
|
66
|
+
matches.push({
|
|
67
|
+
date: maybeDate,
|
|
68
|
+
originalText: subject
|
|
69
|
+
});
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
} else if (format.dateFnsFormat === 'EEE' || format.dateFnsFormat === 'EEEE') {
|
|
73
|
+
const date = (0, _dateFns.parse)(subject, format.dateFnsFormat, baseDate, {
|
|
74
|
+
locale: dateFnsLocale
|
|
75
|
+
});
|
|
76
|
+
if ((0, _dateFns.isValid)(date)) {
|
|
77
|
+
words = words.slice(wordOffset);
|
|
78
|
+
matches.push({
|
|
79
|
+
date: (0, _dateFns.format)(date, 'yyyy-MM-dd'),
|
|
80
|
+
originalText: subject
|
|
81
|
+
});
|
|
82
|
+
}
|
|
83
|
+
} else {
|
|
84
|
+
const yearIsExplicit = typeof format.yearIsExplicit === 'boolean' ? format.yearIsExplicit : true;
|
|
85
|
+
if (yearIsExplicit) {
|
|
86
|
+
const date = (0, _dateFns.parse)(subject, format.dateFnsFormat, baseDate, {
|
|
87
|
+
locale: dateFnsLocale
|
|
88
|
+
});
|
|
89
|
+
if (!(0, _dateFns.isValid)(date)) {
|
|
90
|
+
continue;
|
|
91
|
+
}
|
|
92
|
+
const formatDirection = format.direction;
|
|
93
|
+
const configurationDirection = configuration.direction;
|
|
94
|
+
if (formatDirection && configurationDirection && format.dateFnsFormat.includes('yyyy') && formatDirection.replace('Y', '') === configurationDirection.replace('Y', '')) {} else if (format.direction && format.direction !== configuration.direction) {
|
|
95
|
+
continue;
|
|
96
|
+
}
|
|
97
|
+
if (format.direction && !configuration.direction) {
|
|
98
|
+
continue;
|
|
99
|
+
}
|
|
100
|
+
words = words.slice(wordOffset);
|
|
101
|
+
matches.push({
|
|
102
|
+
date: (0, _dateFns.format)(date, 'yyyy-MM-dd'),
|
|
103
|
+
originalText: subject
|
|
104
|
+
});
|
|
105
|
+
} else {
|
|
106
|
+
const date = (0, _dateFns.parse)(subject, format.dateFnsFormat, baseDate, {
|
|
107
|
+
locale: dateFnsLocale
|
|
108
|
+
});
|
|
109
|
+
if (!(0, _dateFns.isValid)(date)) {
|
|
110
|
+
continue;
|
|
111
|
+
}
|
|
112
|
+
const currentYear = parseInt((0, _dateFns.format)(baseDate, 'yyyy'), 10);
|
|
113
|
+
const currentMonth = parseInt((0, _dateFns.format)(baseDate, 'M'), 10) + currentYear * 12;
|
|
114
|
+
const parsedMonth = parseInt((0, _dateFns.format)(date, 'M'), 10) + parseInt((0, _dateFns.format)(date, 'yyyy'), 10) * 12;
|
|
115
|
+
const difference = parsedMonth - currentMonth;
|
|
116
|
+
let useYear;
|
|
117
|
+
if (difference >= configuration.maximumAge) {
|
|
118
|
+
useYear = currentYear - 1;
|
|
119
|
+
} else if (difference < 0 && Math.abs(difference) >= configuration.minimumAge) {
|
|
120
|
+
useYear = currentYear + 1;
|
|
121
|
+
} else {
|
|
122
|
+
useYear = currentYear;
|
|
123
|
+
}
|
|
124
|
+
const maybeDate = (0, _dateFns.parse)(useYear + '-' + (0, _dateFns.format)(date, 'MM-dd'), 'yyyy-MM-dd', baseDate, {
|
|
125
|
+
locale: dateFnsLocale
|
|
126
|
+
});
|
|
127
|
+
if (!(0, _dateFns.isValid)(maybeDate)) {
|
|
128
|
+
continue;
|
|
129
|
+
}
|
|
130
|
+
if (format.direction && format.direction !== configuration.direction) {
|
|
131
|
+
continue;
|
|
132
|
+
}
|
|
133
|
+
if (format.direction && !configuration.direction) {
|
|
134
|
+
continue;
|
|
135
|
+
}
|
|
136
|
+
words = words.slice(wordOffset);
|
|
137
|
+
matches.push({
|
|
138
|
+
date: (0, _dateFns.format)(maybeDate, 'yyyy-MM-dd'),
|
|
139
|
+
originalText: subject
|
|
140
|
+
});
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
return matches;
|
|
146
|
+
};
|
|
147
|
+
exports.default = _default;
|
|
148
|
+
//# sourceMappingURL=extractDate.js.map
|
|
@@ -0,0 +1,214 @@
|
|
|
1
|
+
// @flow
|
|
2
|
+
|
|
3
|
+
/* eslint-disable no-continue, no-negated-condition, import/no-namespace */
|
|
4
|
+
|
|
5
|
+
import {
|
|
6
|
+
format as formatDate,
|
|
7
|
+
parse as parseDate,
|
|
8
|
+
isValid as isValidDate,
|
|
9
|
+
} from 'date-fns';
|
|
10
|
+
import * as locales from 'date-fns/locale';
|
|
11
|
+
import moment from 'moment-timezone';
|
|
12
|
+
import dictionary from 'relative-date-names';
|
|
13
|
+
import createMovingChunks from './createMovingChunks';
|
|
14
|
+
import extractRelativeDate from './extractRelativeDate';
|
|
15
|
+
import createFormats from './createFormats';
|
|
16
|
+
import normalizeInput from './normalizeInput';
|
|
17
|
+
import type {
|
|
18
|
+
ConfigurationType,
|
|
19
|
+
DateMatchType,
|
|
20
|
+
UserConfigurationType,
|
|
21
|
+
} from './types';
|
|
22
|
+
|
|
23
|
+
const defaultConfiguration = {
|
|
24
|
+
maximumAge: Infinity,
|
|
25
|
+
minimumAge: Infinity,
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
const formats = createFormats();
|
|
29
|
+
|
|
30
|
+
const dateFnsLocaleMap = {
|
|
31
|
+
en: 'enUS',
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
// eslint-disable-next-line complexity
|
|
35
|
+
export default (input: string, userConfiguration: UserConfigurationType = defaultConfiguration): $ReadOnlyArray<DateMatchType> => {
|
|
36
|
+
const normalizedInput = normalizeInput(input);
|
|
37
|
+
|
|
38
|
+
const configuration: ConfigurationType = {
|
|
39
|
+
...defaultConfiguration,
|
|
40
|
+
...userConfiguration,
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
const locale = configuration.locale || 'en';
|
|
44
|
+
|
|
45
|
+
const dateFnsLocale = locales[dateFnsLocaleMap[locale] || locale];
|
|
46
|
+
|
|
47
|
+
if (!dateFnsLocale) {
|
|
48
|
+
throw new Error('No translation available for the target locale (date-fns).');
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
if (!dictionary[locale]) {
|
|
52
|
+
throw new Error('No translation available for the target locale (relative dates).');
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
if (configuration.timezone && !moment.tz.zone(configuration.timezone)) {
|
|
56
|
+
throw new Error('Unrecognized timezone.');
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
if (configuration.maximumAge && configuration.maximumAge < 0) {
|
|
60
|
+
throw new Error('`maximumAge` must be a positive number.');
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
if (configuration.minimumAge && configuration.minimumAge < 0) {
|
|
64
|
+
throw new Error('`minimumAge` must be a positive number.');
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
let words = normalizedInput.split(' ');
|
|
68
|
+
|
|
69
|
+
const matches = [];
|
|
70
|
+
|
|
71
|
+
const baseDate = parseDate('12:00', 'HH:mm', new Date());
|
|
72
|
+
|
|
73
|
+
for (const format of formats) {
|
|
74
|
+
const movingChunks = createMovingChunks(words, format.wordCount);
|
|
75
|
+
|
|
76
|
+
let chunkIndex = 0;
|
|
77
|
+
|
|
78
|
+
for (const movingChunk of movingChunks) {
|
|
79
|
+
const wordOffset = ++chunkIndex * format.wordCount;
|
|
80
|
+
|
|
81
|
+
const subject = movingChunk.join(' ');
|
|
82
|
+
|
|
83
|
+
if (format.dateFnsFormat === 'R') {
|
|
84
|
+
if (!configuration.locale) {
|
|
85
|
+
} else if (!configuration.timezone) {
|
|
86
|
+
} else {
|
|
87
|
+
const maybeDate = extractRelativeDate(subject, configuration.locale, configuration.timezone);
|
|
88
|
+
|
|
89
|
+
if (maybeDate) {
|
|
90
|
+
words = words.slice(wordOffset);
|
|
91
|
+
|
|
92
|
+
matches.push({
|
|
93
|
+
date: maybeDate,
|
|
94
|
+
originalText: subject,
|
|
95
|
+
});
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
} else if (format.dateFnsFormat === 'EEE' || format.dateFnsFormat === 'EEEE') {
|
|
99
|
+
const date = parseDate(
|
|
100
|
+
subject,
|
|
101
|
+
format.dateFnsFormat,
|
|
102
|
+
baseDate,
|
|
103
|
+
{
|
|
104
|
+
locale: dateFnsLocale,
|
|
105
|
+
},
|
|
106
|
+
);
|
|
107
|
+
|
|
108
|
+
if (isValidDate(date)) {
|
|
109
|
+
words = words.slice(wordOffset);
|
|
110
|
+
|
|
111
|
+
matches.push({
|
|
112
|
+
date: formatDate(date, 'yyyy-MM-dd'),
|
|
113
|
+
originalText: subject,
|
|
114
|
+
});
|
|
115
|
+
}
|
|
116
|
+
} else {
|
|
117
|
+
const yearIsExplicit = typeof format.yearIsExplicit === 'boolean' ? format.yearIsExplicit : true;
|
|
118
|
+
|
|
119
|
+
if (yearIsExplicit) {
|
|
120
|
+
const date = parseDate(
|
|
121
|
+
subject,
|
|
122
|
+
format.dateFnsFormat,
|
|
123
|
+
baseDate,
|
|
124
|
+
{
|
|
125
|
+
locale: dateFnsLocale,
|
|
126
|
+
},
|
|
127
|
+
);
|
|
128
|
+
|
|
129
|
+
if (!isValidDate(date)) {
|
|
130
|
+
continue;
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
const formatDirection = format.direction;
|
|
134
|
+
const configurationDirection = configuration.direction;
|
|
135
|
+
|
|
136
|
+
if (formatDirection && configurationDirection && format.dateFnsFormat.includes('yyyy') && formatDirection.replace('Y', '') === configurationDirection.replace('Y', '')) {
|
|
137
|
+
} else if (format.direction && format.direction !== configuration.direction) {
|
|
138
|
+
continue;
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
if (format.direction && !configuration.direction) {
|
|
142
|
+
continue;
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
words = words.slice(wordOffset);
|
|
146
|
+
|
|
147
|
+
matches.push({
|
|
148
|
+
date: formatDate(date, 'yyyy-MM-dd'),
|
|
149
|
+
originalText: subject,
|
|
150
|
+
});
|
|
151
|
+
} else {
|
|
152
|
+
const date = parseDate(
|
|
153
|
+
subject,
|
|
154
|
+
format.dateFnsFormat,
|
|
155
|
+
baseDate,
|
|
156
|
+
{
|
|
157
|
+
locale: dateFnsLocale,
|
|
158
|
+
},
|
|
159
|
+
);
|
|
160
|
+
|
|
161
|
+
if (!isValidDate(date)) {
|
|
162
|
+
continue;
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
const currentYear = parseInt(formatDate(baseDate, 'yyyy'), 10);
|
|
166
|
+
|
|
167
|
+
const currentMonth = parseInt(formatDate(baseDate, 'M'), 10) + currentYear * 12;
|
|
168
|
+
const parsedMonth = parseInt(formatDate(date, 'M'), 10) + parseInt(formatDate(date, 'yyyy'), 10) * 12;
|
|
169
|
+
const difference = parsedMonth - currentMonth;
|
|
170
|
+
|
|
171
|
+
let useYear;
|
|
172
|
+
|
|
173
|
+
if (difference >= configuration.maximumAge) {
|
|
174
|
+
useYear = currentYear - 1;
|
|
175
|
+
} else if (difference < 0 && Math.abs(difference) >= configuration.minimumAge) {
|
|
176
|
+
useYear = currentYear + 1;
|
|
177
|
+
} else {
|
|
178
|
+
useYear = currentYear;
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
const maybeDate = parseDate(
|
|
182
|
+
useYear + '-' + formatDate(date, 'MM-dd'),
|
|
183
|
+
'yyyy-MM-dd',
|
|
184
|
+
baseDate,
|
|
185
|
+
{
|
|
186
|
+
locale: dateFnsLocale,
|
|
187
|
+
},
|
|
188
|
+
);
|
|
189
|
+
|
|
190
|
+
if (!isValidDate(maybeDate)) {
|
|
191
|
+
continue;
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
if (format.direction && format.direction !== configuration.direction) {
|
|
195
|
+
continue;
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
if (format.direction && !configuration.direction) {
|
|
199
|
+
continue;
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
words = words.slice(wordOffset);
|
|
203
|
+
|
|
204
|
+
matches.push({
|
|
205
|
+
date: formatDate(maybeDate, 'yyyy-MM-dd'),
|
|
206
|
+
originalText: subject,
|
|
207
|
+
});
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
return matches;
|
|
214
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"extractDate.js","names":["_dateFns","require","locales","_interopRequireWildcard","_momentTimezone","_interopRequireDefault","_relativeDateNames","_createMovingChunks","_extractRelativeDate","_createFormats","_normalizeInput","e","__esModule","default","_getRequireWildcardCache","WeakMap","r","t","has","get","n","__proto__","a","Object","defineProperty","getOwnPropertyDescriptor","u","hasOwnProperty","call","i","set","defaultConfiguration","maximumAge","Infinity","minimumAge","formats","createFormats","dateFnsLocaleMap","en","_default","input","userConfiguration","normalizedInput","normalizeInput","configuration","locale","dateFnsLocale","Error","dictionary","timezone","moment","tz","zone","words","split","matches","baseDate","parseDate","Date","format","movingChunks","createMovingChunks","wordCount","chunkIndex","movingChunk","wordOffset","subject","join","dateFnsFormat","maybeDate","extractRelativeDate","slice","push","date","originalText","isValidDate","formatDate","yearIsExplicit","formatDirection","direction","configurationDirection","includes","replace","currentYear","parseInt","currentMonth","parsedMonth","difference","useYear","Math","abs","exports"],"sources":["../src/extractDate.js"],"sourcesContent":["// @flow\n\n/* eslint-disable no-continue, no-negated-condition, import/no-namespace */\n\nimport {\n format as formatDate,\n parse as parseDate,\n isValid as isValidDate,\n} from 'date-fns';\nimport * as locales from 'date-fns/locale';\nimport moment from 'moment-timezone';\nimport dictionary from 'relative-date-names';\nimport createMovingChunks from './createMovingChunks';\nimport extractRelativeDate from './extractRelativeDate';\nimport createFormats from './createFormats';\nimport normalizeInput from './normalizeInput';\nimport type {\n ConfigurationType,\n DateMatchType,\n UserConfigurationType,\n} from './types';\n\nconst defaultConfiguration = {\n maximumAge: Infinity,\n minimumAge: Infinity,\n};\n\nconst formats = createFormats();\n\nconst dateFnsLocaleMap = {\n en: 'enUS',\n};\n\n// eslint-disable-next-line complexity\nexport default (input: string, userConfiguration: UserConfigurationType = defaultConfiguration): $ReadOnlyArray<DateMatchType> => {\n const normalizedInput = normalizeInput(input);\n\n const configuration: ConfigurationType = {\n ...defaultConfiguration,\n ...userConfiguration,\n };\n\n const locale = configuration.locale || 'en';\n\n const dateFnsLocale = locales[dateFnsLocaleMap[locale] || locale];\n\n if (!dateFnsLocale) {\n throw new Error('No translation available for the target locale (date-fns).');\n }\n\n if (!dictionary[locale]) {\n throw new Error('No translation available for the target locale (relative dates).');\n }\n\n if (configuration.timezone && !moment.tz.zone(configuration.timezone)) {\n throw new Error('Unrecognized timezone.');\n }\n\n if (configuration.maximumAge && configuration.maximumAge < 0) {\n throw new Error('`maximumAge` must be a positive number.');\n }\n\n if (configuration.minimumAge && configuration.minimumAge < 0) {\n throw new Error('`minimumAge` must be a positive number.');\n }\n\n let words = normalizedInput.split(' ');\n\n const matches = [];\n\n const baseDate = parseDate('12:00', 'HH:mm', new Date());\n\n for (const format of formats) {\n const movingChunks = createMovingChunks(words, format.wordCount);\n\n let chunkIndex = 0;\n\n for (const movingChunk of movingChunks) {\n const wordOffset = ++chunkIndex * format.wordCount;\n\n const subject = movingChunk.join(' ');\n\n if (format.dateFnsFormat === 'R') {\n if (!configuration.locale) {\n } else if (!configuration.timezone) {\n } else {\n const maybeDate = extractRelativeDate(subject, configuration.locale, configuration.timezone);\n\n if (maybeDate) {\n words = words.slice(wordOffset);\n\n matches.push({\n date: maybeDate,\n originalText: subject,\n });\n }\n }\n } else if (format.dateFnsFormat === 'EEE' || format.dateFnsFormat === 'EEEE') {\n const date = parseDate(\n subject,\n format.dateFnsFormat,\n baseDate,\n {\n locale: dateFnsLocale,\n },\n );\n\n if (isValidDate(date)) {\n words = words.slice(wordOffset);\n\n matches.push({\n date: formatDate(date, 'yyyy-MM-dd'),\n originalText: subject,\n });\n }\n } else {\n const yearIsExplicit = typeof format.yearIsExplicit === 'boolean' ? format.yearIsExplicit : true;\n\n if (yearIsExplicit) {\n const date = parseDate(\n subject,\n format.dateFnsFormat,\n baseDate,\n {\n locale: dateFnsLocale,\n },\n );\n\n if (!isValidDate(date)) {\n continue;\n }\n\n const formatDirection = format.direction;\n const configurationDirection = configuration.direction;\n\n if (formatDirection && configurationDirection && format.dateFnsFormat.includes('yyyy') && formatDirection.replace('Y', '') === configurationDirection.replace('Y', '')) {\n } else if (format.direction && format.direction !== configuration.direction) {\n continue;\n }\n\n if (format.direction && !configuration.direction) {\n continue;\n }\n\n words = words.slice(wordOffset);\n\n matches.push({\n date: formatDate(date, 'yyyy-MM-dd'),\n originalText: subject,\n });\n } else {\n const date = parseDate(\n subject,\n format.dateFnsFormat,\n baseDate,\n {\n locale: dateFnsLocale,\n },\n );\n\n if (!isValidDate(date)) {\n continue;\n }\n\n const currentYear = parseInt(formatDate(baseDate, 'yyyy'), 10);\n\n const currentMonth = parseInt(formatDate(baseDate, 'M'), 10) + currentYear * 12;\n const parsedMonth = parseInt(formatDate(date, 'M'), 10) + parseInt(formatDate(date, 'yyyy'), 10) * 12;\n const difference = parsedMonth - currentMonth;\n\n let useYear;\n\n if (difference >= configuration.maximumAge) {\n useYear = currentYear - 1;\n } else if (difference < 0 && Math.abs(difference) >= configuration.minimumAge) {\n useYear = currentYear + 1;\n } else {\n useYear = currentYear;\n }\n\n const maybeDate = parseDate(\n useYear + '-' + formatDate(date, 'MM-dd'),\n 'yyyy-MM-dd',\n baseDate,\n {\n locale: dateFnsLocale,\n },\n );\n\n if (!isValidDate(maybeDate)) {\n continue;\n }\n\n if (format.direction && format.direction !== configuration.direction) {\n continue;\n }\n\n if (format.direction && !configuration.direction) {\n continue;\n }\n\n words = words.slice(wordOffset);\n\n matches.push({\n date: formatDate(maybeDate, 'yyyy-MM-dd'),\n originalText: subject,\n });\n }\n }\n }\n }\n\n return matches;\n};\n"],"mappings":";;;;;;AAIA,IAAAA,QAAA,GAAAC,OAAA;AAKA,IAAAC,OAAA,GAAAC,uBAAA,CAAAF,OAAA;AACA,IAAAG,eAAA,GAAAC,sBAAA,CAAAJ,OAAA;AACA,IAAAK,kBAAA,GAAAD,sBAAA,CAAAJ,OAAA;AACA,IAAAM,mBAAA,GAAAF,sBAAA,CAAAJ,OAAA;AACA,IAAAO,oBAAA,GAAAH,sBAAA,CAAAJ,OAAA;AACA,IAAAQ,cAAA,GAAAJ,sBAAA,C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C,IAAA6B,gBAAW,EAACN,SAAS,CAAC,EAAE;YAC3B;UACF;UAEA,IAAIV,MAAM,CAACoB,SAAS,IAAIpB,MAAM,CAACoB,SAAS,KAAKnC,aAAa,CAACmC,SAAS,EAAE;YACpE;UACF;UAEA,IAAIpB,MAAM,CAACoB,SAAS,IAAI,CAACnC,aAAa,CAACmC,SAAS,EAAE;YAChD;UACF;UAEA1B,KAAK,GAAGA,KAAK,CAACkB,KAAK,CAACN,UAAU,CAAC;UAE/BV,OAAO,CAACiB,IAAI,CAAC;YACXC,IAAI,EAAE,IAAAG,eAAU,EAACP,SAAS,EAAE,YAAY,CAAC;YACzCK,YAAY,EAAER;UAChB,CAAC,CAAC;QACJ;MACF;IACF;EACF;EAEA,OAAOX,OAAO;AAChB,CAAC;AAAAoC,OAAA,CAAA9E,OAAA,GAAA0B,QAAA","ignoreList":[]}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.default = void 0;
|
|
7
|
+
var _momentTimezone = _interopRequireDefault(require("moment-timezone"));
|
|
8
|
+
var _relativeDateNames = _interopRequireDefault(require("relative-date-names"));
|
|
9
|
+
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
10
|
+
var _default = (subject, locale, timezone) => {
|
|
11
|
+
const translation = _relativeDateNames.default[locale];
|
|
12
|
+
if (!translation) {
|
|
13
|
+
throw new Error('No translation available for the target locale.');
|
|
14
|
+
}
|
|
15
|
+
if (!_momentTimezone.default.tz.zone(timezone)) {
|
|
16
|
+
throw new Error('Unrecognized timezone.');
|
|
17
|
+
}
|
|
18
|
+
const normalizedSubject = subject.toLowerCase();
|
|
19
|
+
const now = (0, _momentTimezone.default)();
|
|
20
|
+
if (normalizedSubject === translation.day.relative.yesterday) {
|
|
21
|
+
return now.subtract(1, 'day').format('YYYY-MM-DD');
|
|
22
|
+
}
|
|
23
|
+
if (normalizedSubject === translation.day.relative.today) {
|
|
24
|
+
return now.format('YYYY-MM-DD');
|
|
25
|
+
}
|
|
26
|
+
if (normalizedSubject === translation.day.relative.tomorrow) {
|
|
27
|
+
return now.add(1, 'day').format('YYYY-MM-DD');
|
|
28
|
+
}
|
|
29
|
+
return null;
|
|
30
|
+
};
|
|
31
|
+
exports.default = _default;
|
|
32
|
+
//# sourceMappingURL=extractRelativeDate.js.map
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
// @flow
|
|
2
|
+
|
|
3
|
+
import moment from 'moment-timezone';
|
|
4
|
+
import dictionary from 'relative-date-names';
|
|
5
|
+
|
|
6
|
+
export default (subject: string, locale: string, timezone: string): ?string => {
|
|
7
|
+
const translation = dictionary[locale];
|
|
8
|
+
|
|
9
|
+
if (!translation) {
|
|
10
|
+
throw new Error('No translation available for the target locale.');
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
if (!moment.tz.zone(timezone)) {
|
|
14
|
+
throw new Error('Unrecognized timezone.');
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
const normalizedSubject = subject.toLowerCase();
|
|
18
|
+
|
|
19
|
+
const now = moment();
|
|
20
|
+
|
|
21
|
+
if (normalizedSubject === translation.day.relative.yesterday) {
|
|
22
|
+
return now.subtract(1, 'day').format('YYYY-MM-DD');
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
if (normalizedSubject === translation.day.relative.today) {
|
|
26
|
+
return now.format('YYYY-MM-DD');
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
if (normalizedSubject === translation.day.relative.tomorrow) {
|
|
30
|
+
return now.add(1, 'day').format('YYYY-MM-DD');
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
return null;
|
|
34
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"extractRelativeDate.js","names":["_momentTimezone","_interopRequireDefault","require","_relativeDateNames","e","__esModule","default","_default","subject","locale","timezone","translation","dictionary","Error","moment","tz","zone","normalizedSubject","toLowerCase","now","day","relative","yesterday","subtract","format","today","tomorrow","add","exports"],"sources":["../src/extractRelativeDate.js"],"sourcesContent":["// @flow\n\nimport moment from 'moment-timezone';\nimport dictionary from 'relative-date-names';\n\nexport default (subject: string, locale: string, timezone: string): ?string => {\n const translation = dictionary[locale];\n\n if (!translation) {\n throw new Error('No translation available for the target locale.');\n }\n\n if (!moment.tz.zone(timezone)) {\n throw new Error('Unrecognized timezone.');\n }\n\n const normalizedSubject = subject.toLowerCase();\n\n const now = moment();\n\n if (normalizedSubject === translation.day.relative.yesterday) {\n return now.subtract(1, 'day').format('YYYY-MM-DD');\n }\n\n if (normalizedSubject === translation.day.relative.today) {\n return now.format('YYYY-MM-DD');\n }\n\n if (normalizedSubject === translation.day.relative.tomorrow) {\n return now.add(1, 'day').format('YYYY-MM-DD');\n }\n\n return null;\n};\n"],"mappings":";;;;;;AAEA,IAAAA,eAAA,GAAAC,sBAAA,CAAAC,OAAA;AACA,IAAAC,kBAAA,GAAAF,sBAAA,CAAAC,OAAA;AAA6C,SAAAD,uBAAAG,CAAA,WAAAA,CAAA,IAAAA,CAAA,CAAAC,UAAA,GAAAD,CAAA,KAAAE,OAAA,EAAAF,CAAA;AAAA,IAAAG,QAAA,GAE9BA,CAACC,OAAe,EAAEC,MAAc,EAAEC,QAAgB,KAAc;EAC7E,MAAMC,WAAW,GAAGC,0BAAU,CAACH,MAAM,CAAC;EAEtC,IAAI,CAACE,WAAW,EAAE;IAChB,MAAM,IAAIE,KAAK,CAAC,iDAAiD,CAAC;EACpE;EAEA,IAAI,CAACC,uBAAM,CAACC,EAAE,CAACC,IAAI,CAACN,QAAQ,CAAC,EAAE;IAC7B,MAAM,IAAIG,KAAK,CAAC,wBAAwB,CAAC;EAC3C;EAEA,MAAMI,iBAAiB,GAAGT,OAAO,CAACU,WAAW,CAAC,CAAC;EAE/C,MAAMC,GAAG,GAAG,IAAAL,uBAAM,EAAC,CAAC;EAEpB,IAAIG,iBAAiB,KAAKN,WAAW,CAACS,GAAG,CAACC,QAAQ,CAACC,SAAS,EAAE;IAC5D,OAAOH,GAAG,CAACI,QAAQ,CAAC,CAAC,EAAE,KAAK,CAAC,CAACC,MAAM,CAAC,YAAY,CAAC;EACpD;EAEA,IAAIP,iBAAiB,KAAKN,WAAW,CAACS,GAAG,CAACC,QAAQ,CAACI,KAAK,EAAE;IACxD,OAAON,GAAG,CAACK,MAAM,CAAC,YAAY,CAAC;EACjC;EAEA,IAAIP,iBAAiB,KAAKN,WAAW,CAACS,GAAG,CAACC,QAAQ,CAACK,QAAQ,EAAE;IAC3D,OAAOP,GAAG,CAACQ,GAAG,CAAC,CAAC,EAAE,KAAK,CAAC,CAACH,MAAM,CAAC,YAAY,CAAC;EAC/C;EAEA,OAAO,IAAI;AACb,CAAC;AAAAI,OAAA,CAAAtB,OAAA,GAAAC,QAAA","ignoreList":[]}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.default = void 0;
|
|
7
|
+
var _extractDate = _interopRequireDefault(require("./extractDate"));
|
|
8
|
+
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
9
|
+
/* eslint-disable filenames/match-exported */
|
|
10
|
+
var _default = exports.default = _extractDate.default;
|
|
11
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","names":["_extractDate","_interopRequireDefault","require","e","__esModule","default","_default","exports","extractDate"],"sources":["../src/index.js"],"sourcesContent":["// @flow\n\n/* eslint-disable filenames/match-exported */\nimport extractDate from './extractDate';\n\nexport default extractDate;\n"],"mappings":";;;;;;AAGA,IAAAA,YAAA,GAAAC,sBAAA,CAAAC,OAAA;AAAwC,SAAAD,uBAAAE,CAAA,WAAAA,CAAA,IAAAA,CAAA,CAAAC,UAAA,GAAAD,CAAA,KAAAE,OAAA,EAAAF,CAAA;AADxC;AAAA,IAAAG,QAAA,GAAAC,OAAA,CAAAF,OAAA,GAGeG,oBAAW","ignoreList":[]}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.default = void 0;
|
|
7
|
+
var _default = input => {
|
|
8
|
+
let lastInput = input;
|
|
9
|
+
while (true) {
|
|
10
|
+
const result = lastInput
|
|
11
|
+
|
|
12
|
+
// 2019-02-12T00:00:00
|
|
13
|
+
.replace(/(\d+)T(\d+)/, '$1 $2').replace(/(\d+)\s\/\s(\d+)/, '$1/$2').replace(/[.:;] /g, ' ').trim().replace(/[.!#?]+$/g, '');
|
|
14
|
+
if (result === lastInput) {
|
|
15
|
+
return result;
|
|
16
|
+
}
|
|
17
|
+
lastInput = result;
|
|
18
|
+
}
|
|
19
|
+
throw new Error('Unexpected state.');
|
|
20
|
+
};
|
|
21
|
+
exports.default = _default;
|
|
22
|
+
//# sourceMappingURL=normalizeInput.js.map
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
// @flow
|
|
2
|
+
|
|
3
|
+
export default (input: string): string => {
|
|
4
|
+
let lastInput = input;
|
|
5
|
+
|
|
6
|
+
while (true) {
|
|
7
|
+
const result = lastInput
|
|
8
|
+
|
|
9
|
+
// 2019-02-12T00:00:00
|
|
10
|
+
.replace(/(\d+)T(\d+)/, '$1 $2')
|
|
11
|
+
|
|
12
|
+
.replace(/(\d+)\s\/\s(\d+)/, '$1/$2')
|
|
13
|
+
|
|
14
|
+
.replace(/[.:;] /g, ' ')
|
|
15
|
+
.trim()
|
|
16
|
+
.replace(/[.!#?]+$/g, '');
|
|
17
|
+
|
|
18
|
+
if (result === lastInput) {
|
|
19
|
+
return result;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
lastInput = result;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
throw new Error('Unexpected state.');
|
|
26
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"normalizeInput.js","names":["input","lastInput","result","replace","trim","Error","exports","default","_default"],"sources":["../src/normalizeInput.js"],"sourcesContent":["// @flow\n\nexport default (input: string): string => {\n let lastInput = input;\n\n while (true) {\n const result = lastInput\n\n // 2019-02-12T00:00:00\n .replace(/(\\d+)T(\\d+)/, '$1 $2')\n\n .replace(/(\\d+)\\s\\/\\s(\\d+)/, '$1/$2')\n\n .replace(/[.:;] /g, ' ')\n .trim()\n .replace(/[.!#?]+$/g, '');\n\n if (result === lastInput) {\n return result;\n }\n\n lastInput = result;\n }\n\n throw new Error('Unexpected state.');\n};\n"],"mappings":";;;;;;eAEgBA,KAAa,IAAa;EACxC,IAAIC,SAAS,GAAGD,KAAK;EAErB,OAAO,IAAI,EAAE;IACX,MAAME,MAAM,GAAGD;;IAEb;IAAA,CACCE,OAAO,CAAC,aAAa,EAAE,OAAO,CAAC,CAE/BA,OAAO,CAAC,kBAAkB,EAAE,OAAO,CAAC,CAEpCA,OAAO,CAAC,SAAS,EAAE,GAAG,CAAC,CACvBC,IAAI,CAAC,CAAC,CACND,OAAO,CAAC,WAAW,EAAE,EAAE,CAAC;IAE3B,IAAID,MAAM,KAAKD,SAAS,EAAE;MACxB,OAAOC,MAAM;IACf;IAEAD,SAAS,GAAGC,MAAM;EACpB;EAEA,MAAM,IAAIG,KAAK,CAAC,mBAAmB,CAAC;AACtC,CAAC;AAAAC,OAAA,CAAAC,OAAA,GAAAC,QAAA","ignoreList":[]}
|
package/dist/types.js
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
// @flow
|
|
2
|
+
|
|
3
|
+
export type DateMatchType = {|
|
|
4
|
+
+date: string,
|
|
5
|
+
|};
|
|
6
|
+
|
|
7
|
+
export type DirectionType = 'DM' | 'DMY' | 'DYM' | 'MD' | 'YDM' | 'YMD' | 'MDY';
|
|
8
|
+
|
|
9
|
+
export type UserConfigurationType = {|
|
|
10
|
+
+direction?: DirectionType,
|
|
11
|
+
+locale?: string,
|
|
12
|
+
+maximumAge?: number,
|
|
13
|
+
+minimumAge?: number,
|
|
14
|
+
+timezone?: string,
|
|
15
|
+
|};
|
|
16
|
+
|
|
17
|
+
export type ConfigurationType = {|
|
|
18
|
+
+direction?: DirectionType,
|
|
19
|
+
+locale?: string,
|
|
20
|
+
+maximumAge: number,
|
|
21
|
+
+minimumAge: number,
|
|
22
|
+
+timezone?: string,
|
|
23
|
+
|};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","names":[],"sources":["../src/types.js"],"sourcesContent":["// @flow\n\nexport type DateMatchType = {|\n +date: string,\n|};\n\nexport type DirectionType = 'DM' | 'DMY' | 'DYM' | 'MD' | 'YDM' | 'YMD' | 'MDY';\n\nexport type UserConfigurationType = {|\n +direction?: DirectionType,\n +locale?: string,\n +maximumAge?: number,\n +minimumAge?: number,\n +timezone?: string,\n|};\n\nexport type ConfigurationType = {|\n +direction?: DirectionType,\n +locale?: string,\n +maximumAge: number,\n +minimumAge: number,\n +timezone?: string,\n|};\n"],"mappings":"","ignoreList":[]}
|