opening_hours 3.12.0 → 3.14.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/CHANGELOG.md +128 -0
- package/LICENSES/AGPL-3.0-or-later.txt +235 -0
- package/LICENSES/ODbL-1.0.txt +540 -0
- package/Makefile +2 -0
- package/README.md +16 -1
- package/REUSE.toml +31 -1
- package/build/opening_hours.esm.mjs +26673 -6220
- package/build/opening_hours.esm.mjs.map +1 -1
- package/build/opening_hours.js +26673 -6220
- package/package.json +26 -24
- package/site/js/countryToLanguageMapping.js +4 -0
- package/site/js/helpers.js +17 -9
- package/site/js/i18n-resources.js +6 -1
- package/site/js/main.js +8 -3
- package/site/js/opening_hours_table.js +26 -29
- package/site/js/theme.js +2 -6
- package/site/js/yohours_model.js +3 -0
- package/src/locales/i18n.js +93 -53
- package/types/index.d.ts +42 -0
- package/LICENSES/CC-BY-SA-4.0.txt +0 -349
- package/LICENSES/LGPL-3.0-or-later.txt +0 -144
package/package.json
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
"type": "commonjs",
|
|
4
4
|
"types": "./types/index.d.ts",
|
|
5
5
|
"description": "Library to parse and process opening_hours tag from OpenStreetMap data",
|
|
6
|
-
"version": "3.
|
|
6
|
+
"version": "3.14.0",
|
|
7
7
|
"main": "./build/opening_hours.js",
|
|
8
8
|
"module": "./build/opening_hours.esm.mjs",
|
|
9
9
|
"sideEffects": false,
|
|
@@ -66,38 +66,40 @@
|
|
|
66
66
|
"check-updates": "npm-check-updates --upgrade"
|
|
67
67
|
},
|
|
68
68
|
"dependencies": {
|
|
69
|
-
"i18next": "^
|
|
70
|
-
"suncalc": "^
|
|
69
|
+
"i18next": "^26.3.6",
|
|
70
|
+
"suncalc": "^2.0.0"
|
|
71
71
|
},
|
|
72
72
|
"devDependencies": {
|
|
73
|
-
"@commitlint/cli": "^
|
|
74
|
-
"@commitlint/config-conventional": "^
|
|
75
|
-
"@eslint/js": "^
|
|
76
|
-
"@eslint/markdown": "^
|
|
77
|
-
"@rollup/plugin-commonjs": "^29.0.
|
|
73
|
+
"@commitlint/cli": "^21.2.1",
|
|
74
|
+
"@commitlint/config-conventional": "^21.2.0",
|
|
75
|
+
"@eslint/js": "^10.0.1",
|
|
76
|
+
"@eslint/markdown": "^8.0.3",
|
|
77
|
+
"@rollup/plugin-commonjs": "^29.0.3",
|
|
78
78
|
"@rollup/plugin-json": "^6.1.0",
|
|
79
79
|
"@rollup/plugin-node-resolve": "^16.0.3",
|
|
80
|
-
"@rollup/plugin-terser": "^0.
|
|
81
|
-
"@rollup/plugin-yaml": "^
|
|
82
|
-
"@stylistic/eslint-plugin": "^5.
|
|
83
|
-
"
|
|
84
|
-
"
|
|
80
|
+
"@rollup/plugin-terser": "^1.0.0",
|
|
81
|
+
"@rollup/plugin-yaml": "^5.0.0",
|
|
82
|
+
"@stylistic/eslint-plugin": "^5.10.0",
|
|
83
|
+
"cldr-dates-full": "^48.2.0",
|
|
84
|
+
"cldr-localenames-full": "^48.2.0",
|
|
85
|
+
"commit-and-tag-version": "^12.7.3",
|
|
86
|
+
"commitizen": "^4.3.2",
|
|
85
87
|
"cz-conventional-changelog": "^3.3.0",
|
|
86
|
-
"doctoc": "^2.
|
|
87
|
-
"eslint": "^
|
|
88
|
-
"full-icu": "^1.
|
|
88
|
+
"doctoc": "^2.5.0",
|
|
89
|
+
"eslint": "^10.7.0",
|
|
90
|
+
"full-icu": "^1.6.0",
|
|
89
91
|
"glob": "^13.0.6",
|
|
90
|
-
"globals": "^17.
|
|
92
|
+
"globals": "^17.7.0",
|
|
91
93
|
"husky": "^9.1.7",
|
|
92
|
-
"lint-staged": "^
|
|
93
|
-
"npm-check-updates": "^
|
|
94
|
+
"lint-staged": "^17.0.8",
|
|
95
|
+
"npm-check-updates": "^22.2.9",
|
|
94
96
|
"package-json-validator-cli": "^0.1.11",
|
|
95
|
-
"rollup": "^4.
|
|
96
|
-
"terser": "^5.
|
|
97
|
+
"rollup": "^4.62.2",
|
|
98
|
+
"terser": "^5.49.0",
|
|
97
99
|
"timekeeper": "^2.3.1",
|
|
98
|
-
"typescript": "^
|
|
99
|
-
"typescript-eslint": "^8.
|
|
100
|
-
"yaml": "^2.
|
|
100
|
+
"typescript": "^6.0.3",
|
|
101
|
+
"typescript-eslint": "^8.63.0",
|
|
102
|
+
"yaml": "^2.9.0",
|
|
101
103
|
"yargs": "^18.0.0"
|
|
102
104
|
},
|
|
103
105
|
"engines": {
|
package/site/js/helpers.js
CHANGED
|
@@ -1,5 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* SPDX-FileCopyrightText: © 2014 Robin Schneider <ypid@riseup.net>
|
|
3
|
+
*
|
|
4
|
+
* SPDX-License-Identifier: LGPL-3.0-only
|
|
5
|
+
*/
|
|
1
6
|
// Import dependencies
|
|
2
|
-
import i18next from '../../node_modules/i18next/dist/esm/i18next.
|
|
7
|
+
import i18next from '../../node_modules/i18next/dist/esm/i18next.js';
|
|
3
8
|
import { OpeningHoursTable } from './opening_hours_table.js';
|
|
4
9
|
import { mapCountryToLanguage } from './countryToLanguageMapping.js';
|
|
5
10
|
import { updateTimeButtonLabels } from './main.js';
|
|
@@ -46,15 +51,18 @@ export function josm(url_param) {
|
|
|
46
51
|
}
|
|
47
52
|
// }}}
|
|
48
53
|
|
|
49
|
-
//
|
|
50
|
-
export function
|
|
51
|
-
const
|
|
52
|
-
const
|
|
53
|
-
|
|
54
|
+
// ISO 8601 calendar week number {{{
|
|
55
|
+
export function getISOWeekNumber(date) {
|
|
56
|
+
const millisecondsPerDay = 24 * 60 * 60 * 1000;
|
|
57
|
+
const utcDate = new Date(Date.UTC(date.getFullYear(), date.getMonth(), date.getDate()));
|
|
58
|
+
|
|
59
|
+
// ISO week uses Monday=1..Sunday=7 and anchors weeks on Thursday.
|
|
60
|
+
const isoDay = utcDate.getUTCDay() || 7;
|
|
61
|
+
utcDate.setUTCDate(utcDate.getUTCDate() + 4 - isoDay);
|
|
54
62
|
|
|
55
|
-
const
|
|
56
|
-
|
|
57
|
-
return Math.
|
|
63
|
+
const isoYearStart = new Date(Date.UTC(utcDate.getUTCFullYear(), 0, 1));
|
|
64
|
+
const dayOfYear = Math.floor((utcDate - isoYearStart) / millisecondsPerDay) + 1;
|
|
65
|
+
return Math.ceil(dayOfYear / 7);
|
|
58
66
|
}
|
|
59
67
|
// }}}
|
|
60
68
|
|
|
@@ -1,5 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* SPDX-FileCopyrightText: © 2013 Robin Schneider <ypid@riseup.net>
|
|
3
|
+
*
|
|
4
|
+
* SPDX-License-Identifier: LGPL-3.0-only
|
|
5
|
+
*/
|
|
1
6
|
// Import i18next for use in helper functions
|
|
2
|
-
import i18next from '../../node_modules/i18next/dist/esm/i18next.
|
|
7
|
+
import i18next from '../../node_modules/i18next/dist/esm/i18next.js';
|
|
3
8
|
|
|
4
9
|
// localization {{{
|
|
5
10
|
export const resources = { // English is fallback language.
|
package/site/js/main.js
CHANGED
|
@@ -1,7 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* SPDX-FileCopyrightText: © 2025 Kristjan ESPERANTO <https://github.com/KristjanESPERANTO>
|
|
3
|
+
*
|
|
4
|
+
* SPDX-License-Identifier: LGPL-3.0-only
|
|
5
|
+
*/
|
|
1
6
|
// Import all required modules
|
|
2
|
-
import i18next from '../../node_modules/i18next/dist/esm/i18next.
|
|
7
|
+
import i18next from '../../node_modules/i18next/dist/esm/i18next.js';
|
|
3
8
|
import { resources, detectLanguage, getUserSelectTranslateHTMLCode, changeLanguage } from './i18n-resources.js';
|
|
4
|
-
import { Evaluate, EX, josm, toggle,
|
|
9
|
+
import { Evaluate, EX, josm, toggle, getISOWeekNumber, newValue, currentDateTime } from './helpers.js';
|
|
5
10
|
|
|
6
11
|
// Configuration constants
|
|
7
12
|
window.default_lat = 48.7769;
|
|
@@ -72,7 +77,7 @@ export function updateTimeButtonLabels(date) {
|
|
|
72
77
|
if (minuteLabel) minuteLabel.textContent = u2(currentDateTime.minute);
|
|
73
78
|
|
|
74
79
|
if (weekLabel && date) {
|
|
75
|
-
weekLabel.textContent = `W${u2(
|
|
80
|
+
weekLabel.textContent = `W${u2(getISOWeekNumber(date))}`;
|
|
76
81
|
}
|
|
77
82
|
|
|
78
83
|
if (wdayDisplay && date) {
|
|
@@ -1,5 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* SPDX-FileCopyrightText: © 2013 Robin Schneider <ypid@riseup.net>
|
|
3
|
+
*
|
|
4
|
+
* SPDX-License-Identifier: LGPL-3.0-only
|
|
5
|
+
*/
|
|
1
6
|
// Import dependencies
|
|
2
|
-
import i18next from '../../node_modules/i18next/dist/esm/i18next.
|
|
7
|
+
import i18next from '../../node_modules/i18next/dist/esm/i18next.js';
|
|
3
8
|
|
|
4
9
|
export const OpeningHoursTable = {
|
|
5
10
|
|
|
@@ -12,6 +17,16 @@ export const OpeningHoursTable = {
|
|
|
12
17
|
return date.toLocaleString(i18next.language, { weekday: 'short' });
|
|
13
18
|
},
|
|
14
19
|
|
|
20
|
+
// Returns a date's local time as a percentage of the day (0–100).
|
|
21
|
+
dayPercent(date) {
|
|
22
|
+
return (date.getHours() * 60 + date.getMinutes()) / 1440 * 100;
|
|
23
|
+
},
|
|
24
|
+
|
|
25
|
+
// Formats a date's local time as "HH:MM".
|
|
26
|
+
formatHM(date) {
|
|
27
|
+
return date.toLocaleString('en', { hourCycle: 'h23', hour: '2-digit', minute: '2-digit' });
|
|
28
|
+
},
|
|
29
|
+
|
|
15
30
|
formatdate (now, nextchange, from) {
|
|
16
31
|
const now_daystart = new Date(now.getFullYear(), now.getMonth(), now.getDate());
|
|
17
32
|
const nextdays = (nextchange.getTime() - now_daystart.getTime()) / 1000 / 60 / 60 / 24;
|
|
@@ -113,7 +128,7 @@ export const OpeningHoursTable = {
|
|
|
113
128
|
// Calculate current time position for "now" marker (percentage of day)
|
|
114
129
|
// Use evalDate instead of new Date() to show the evaluation time, not browser time
|
|
115
130
|
const now = evalDate || new Date();
|
|
116
|
-
const nowPercent =
|
|
131
|
+
const nowPercent = this.dayPercent(now);
|
|
117
132
|
|
|
118
133
|
const tableData = [];
|
|
119
134
|
|
|
@@ -137,30 +152,23 @@ export const OpeningHoursTable = {
|
|
|
137
152
|
while (has_next_change && it.advance() && curdate.getTime() - date.getTime() < 24 * 60 * 60 * 1000) {
|
|
138
153
|
curdate = it.getDate();
|
|
139
154
|
|
|
140
|
-
|
|
141
|
-
|
|
155
|
+
// Use local clock time (not elapsed ms) so bars stay aligned
|
|
156
|
+
// with labels on DST transition days.
|
|
157
|
+
const crossesMidnight = prevdate.getDay() !== curdate.getDay();
|
|
142
158
|
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
}
|
|
146
|
-
|
|
147
|
-
fr *= 100 / 1000 / 60 / 60 / 24;
|
|
148
|
-
to *= 100 / 1000 / 60 / 60 / 24;
|
|
159
|
+
const from = this.dayPercent(prevdate);
|
|
160
|
+
const to = crossesMidnight ? 100 : this.dayPercent(curdate);
|
|
149
161
|
|
|
150
162
|
const stateClass = is_open ? 'open' : (unknown ? 'unknown' : 'closed');
|
|
151
|
-
|
|
152
|
-
const
|
|
153
|
-
const timeToDate = prevdate.getDay() !== curdate.getDay() ? null : curdate;
|
|
154
|
-
const timeTo = timeToDate
|
|
155
|
-
? `${String(timeToDate.getHours()).padStart(2, '0')}:${String(timeToDate.getMinutes()).padStart(2, '0')}`
|
|
156
|
-
: '24:00';
|
|
163
|
+
const timeFrom = this.formatHM(prevdate);
|
|
164
|
+
const timeTo = crossesMidnight ? '24:00' : this.formatHM(curdate);
|
|
157
165
|
|
|
158
166
|
// Use current state_string for this period (before advancing)
|
|
159
167
|
const currentStateString = state_string;
|
|
160
168
|
const tooltip = `${i18next.t(`words.${currentStateString}`)}: ${timeFrom} - ${timeTo}`;
|
|
161
169
|
|
|
162
170
|
rowData.times.push(
|
|
163
|
-
`<div class="timebar ${stateClass}" style="width:${to -
|
|
171
|
+
`<div class="timebar ${stateClass}" style="width:${to - from}%" title="${tooltip}"></div>`
|
|
164
172
|
);
|
|
165
173
|
|
|
166
174
|
if (is_open || unknown) {
|
|
@@ -232,14 +240,6 @@ export const OpeningHoursTable = {
|
|
|
232
240
|
return `<table class="opening-hours-table">${headerRow}${rows}</table>`;
|
|
233
241
|
},
|
|
234
242
|
|
|
235
|
-
getReadableState (startString, endString, oh, past) {
|
|
236
|
-
if (past === true) past = 'd';
|
|
237
|
-
else past = '';
|
|
238
|
-
|
|
239
|
-
const output = '';
|
|
240
|
-
return `${startString + output + endString}.`;
|
|
241
|
-
},
|
|
242
|
-
|
|
243
243
|
drawTableAndComments (oh, it, evalDate) {
|
|
244
244
|
const prevdate = it.getDate();
|
|
245
245
|
const unknown = it.getUnknown();
|
|
@@ -357,10 +357,7 @@ export const OpeningHoursTable = {
|
|
|
357
357
|
const change_daystart = new Date(changeDate.getFullYear(), changeDate.getMonth(), changeDate.getDate());
|
|
358
358
|
const daysDiff = Math.round((change_daystart.getTime() - now_daystart.getTime()) / (1000 * 60 * 60 * 24));
|
|
359
359
|
|
|
360
|
-
|
|
361
|
-
const hours = String(changeDate.getHours()).padStart(2, '0');
|
|
362
|
-
const minutes = String(changeDate.getMinutes()).padStart(2, '0');
|
|
363
|
-
const timeStr = `${hours}:${minutes}`;
|
|
360
|
+
const timeStr = this.formatHM(changeDate);
|
|
364
361
|
|
|
365
362
|
if (daysDiff === 0) {
|
|
366
363
|
return `${i18next.t('words.today')} ${timeStr}`;
|
package/site/js/theme.js
CHANGED
|
@@ -44,12 +44,8 @@
|
|
|
44
44
|
const theme = getThemePreference();
|
|
45
45
|
setTheme(theme);
|
|
46
46
|
|
|
47
|
-
// Set up toggle button
|
|
48
|
-
|
|
49
|
-
document.addEventListener('DOMContentLoaded', initToggleButton);
|
|
50
|
-
} else {
|
|
51
|
-
initToggleButton();
|
|
52
|
-
}
|
|
47
|
+
// Set up toggle button (script loads with defer, so DOM is ready)
|
|
48
|
+
initToggleButton();
|
|
53
49
|
|
|
54
50
|
function initToggleButton() {
|
|
55
51
|
const toggleBtn = document.getElementById('theme-toggle');
|
package/site/js/yohours_model.js
CHANGED
package/src/locales/i18n.js
CHANGED
|
@@ -1,62 +1,102 @@
|
|
|
1
|
-
|
|
1
|
+
/**
|
|
2
|
+
* SPDX-FileCopyrightText: © 2025 Kristjan ESPERANTO <https://github.com/KristjanESPERANTO>
|
|
3
|
+
*
|
|
4
|
+
* SPDX-License-Identifier: LGPL-3.0-only
|
|
5
|
+
*/
|
|
6
|
+
import resources from './translations.yaml';
|
|
2
7
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
},
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
_translate: function(locale, key, variables) {
|
|
22
|
-
// Handle array of keys (fallback mechanism)
|
|
23
|
-
const keys = Array.isArray(key) ? key : [key];
|
|
8
|
+
/**
|
|
9
|
+
* Replace `{{varName}}` (or `{{-varName}}`) placeholders in a translation string.
|
|
10
|
+
* The `-` prefix is a legacy i18next no-HTML-escape marker; it has no effect here.
|
|
11
|
+
*
|
|
12
|
+
* @param {string} str - Translation string containing `{{…}}` placeholders.
|
|
13
|
+
* @param {Object} vars - Map of placeholder names to replacement values.
|
|
14
|
+
* @returns {string}
|
|
15
|
+
*/
|
|
16
|
+
function interpolate(str, vars) {
|
|
17
|
+
return str.replace(/{{-?([^{}]*)}}/g, function(match, varName) {
|
|
18
|
+
const name = varName.trim();
|
|
19
|
+
if (name in vars) {
|
|
20
|
+
return vars[name];
|
|
21
|
+
}
|
|
22
|
+
return match;
|
|
23
|
+
});
|
|
24
|
+
}
|
|
24
25
|
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
26
|
+
/**
|
|
27
|
+
* Extract the base language subtag from a locale tag (e.g. 'de-DE' → 'de').
|
|
28
|
+
*
|
|
29
|
+
* Accepts BCP 47 tags (e.g. 'de-DE') and POSIX identifiers per ISO 15897 (e.g. 'de_DE').
|
|
30
|
+
* For non-strings, returns 'en' (the default fallback locale).
|
|
31
|
+
*
|
|
32
|
+
* @param {string|null|undefined} locale - Locale tag.
|
|
33
|
+
* @returns {string} Base language, e.g. 'de'.
|
|
34
|
+
*/
|
|
35
|
+
function baseLanguage(locale) {
|
|
36
|
+
if (locale && typeof locale === 'string') {
|
|
37
|
+
return locale.split(/[-_]/)[0];
|
|
38
|
+
}
|
|
39
|
+
return 'en';
|
|
40
|
+
}
|
|
30
41
|
|
|
31
|
-
|
|
32
|
-
|
|
42
|
+
/**
|
|
43
|
+
* Build the locale fallback chain for a given locale tag.
|
|
44
|
+
*
|
|
45
|
+
* 'de-DE' → ['de-DE', 'de', 'en']
|
|
46
|
+
* 'de' → ['de', 'en']
|
|
47
|
+
* null → ['en']
|
|
48
|
+
*
|
|
49
|
+
* @param {string|null|undefined} locale - BCP 47 locale tag.
|
|
50
|
+
* @returns {string[]}
|
|
51
|
+
*/
|
|
52
|
+
function localeChain(locale) {
|
|
53
|
+
const base = baseLanguage(locale);
|
|
54
|
+
// Deduplicate entries like ['de', 'de', 'en'] or ['en', 'en'].
|
|
55
|
+
return [...new Set([locale, base, 'en'].filter(Boolean))];
|
|
56
|
+
}
|
|
33
57
|
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
58
|
+
/**
|
|
59
|
+
* Walk the resource tree for the first locale in the fallback chain that has
|
|
60
|
+
* a translation for the given key.
|
|
61
|
+
*
|
|
62
|
+
* Tree shape: resources[locale][section][…key segments]
|
|
63
|
+
*
|
|
64
|
+
* @param {string|null|undefined} locale - BCP 47 locale tag.
|
|
65
|
+
* @param {string} section - 'texts' or 'pretty'.
|
|
66
|
+
* @param {string} key - Translation key (dot-separated for nesting).
|
|
67
|
+
* @returns {*} Matched value, or `undefined` if not found anywhere in the chain.
|
|
68
|
+
*/
|
|
69
|
+
function lookup(locale, section, key) {
|
|
70
|
+
const keyPath = key.split('.');
|
|
71
|
+
for (const loc of localeChain(locale)) {
|
|
72
|
+
let value = resources[loc]?.[section];
|
|
73
|
+
for (const segment of keyPath) value = value?.[segment];
|
|
74
|
+
// Return as soon as we find a value defined by the resource tree.
|
|
75
|
+
if (value !== undefined) return value;
|
|
76
|
+
}
|
|
77
|
+
return undefined;
|
|
78
|
+
}
|
|
46
79
|
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
80
|
+
/**
|
|
81
|
+
* Translate a key into the requested locale, falling back through the locale
|
|
82
|
+
* chain to English. Returns the key itself when no translation is found.
|
|
83
|
+
*
|
|
84
|
+
* @param {string|null|undefined} locale - BCP 47 locale tag (e.g. 'de', 'de-DE').
|
|
85
|
+
* @param {string} section - 'texts' (error/warning messages) or
|
|
86
|
+
* 'pretty' (prettified output tokens).
|
|
87
|
+
* @param {string} key - Translation key (dot-separated for nesting).
|
|
88
|
+
* @param {Object} [vars] - Variables to interpolate via `{{varName}}`.
|
|
89
|
+
* @returns {string}
|
|
90
|
+
*/
|
|
91
|
+
export function translate(locale, section, key, vars) {
|
|
92
|
+
const result = lookup(locale, section, key);
|
|
51
93
|
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
if (current === undefined || current === null) return undefined;
|
|
56
|
-
current = current[key];
|
|
94
|
+
if (typeof result === 'string') {
|
|
95
|
+
if (vars) {
|
|
96
|
+
return interpolate(result, vars);
|
|
57
97
|
}
|
|
58
|
-
return
|
|
98
|
+
return result;
|
|
59
99
|
}
|
|
60
|
-
};
|
|
61
100
|
|
|
62
|
-
|
|
101
|
+
return key;
|
|
102
|
+
}
|
package/types/index.d.ts
CHANGED
|
@@ -1,4 +1,45 @@
|
|
|
1
1
|
declare module 'opening_hours' {
|
|
2
|
+
export type opening_hours_warning_type =
|
|
3
|
+
| 'adding_0'
|
|
4
|
+
| 'additional_rule_separator_not_used_after_time_wrapping_midnight'
|
|
5
|
+
| 'additional_rule_which_evaluates_to_closed'
|
|
6
|
+
| 'ambiguous_word'
|
|
7
|
+
| 'combine_rules'
|
|
8
|
+
| 'default_state'
|
|
9
|
+
| 'empty_comment'
|
|
10
|
+
| 'hour_min_separator'
|
|
11
|
+
| 'interpreted_as_year'
|
|
12
|
+
| 'no_colon_after'
|
|
13
|
+
| 'nothing_useful'
|
|
14
|
+
| 'omit_ko'
|
|
15
|
+
| 'period_one'
|
|
16
|
+
| 'period_one_year_plus'
|
|
17
|
+
| 'please_use_ok_for_ko'
|
|
18
|
+
| 'public_holiday'
|
|
19
|
+
| 'rant_degree_sign_used_for_zero'
|
|
20
|
+
| 'separator_for_readability'
|
|
21
|
+
| 'strange_24_7'
|
|
22
|
+
| 'switched'
|
|
23
|
+
| 'use_multi'
|
|
24
|
+
| 'vague'
|
|
25
|
+
| 'value_ends_with_token'
|
|
26
|
+
| 'without_minutes'
|
|
27
|
+
| 'word_error_correction'
|
|
28
|
+
| 'year_past'
|
|
29
|
+
| 'zero_calculation'
|
|
30
|
+
|
|
31
|
+
export interface opening_hours_warning {
|
|
32
|
+
type: opening_hours_warning_type
|
|
33
|
+
message: string
|
|
34
|
+
/** The string the `position` offset refers to. This is the input value,
|
|
35
|
+
* except for selector-reordering warnings where it is the prettified value. */
|
|
36
|
+
value: string
|
|
37
|
+
/** Character offset into `value` where the warning points (the spot the
|
|
38
|
+
* `<--- ` marker is placed at in `getWarnings()`). `null` if it could not
|
|
39
|
+
* be determined. */
|
|
40
|
+
position: number | null
|
|
41
|
+
}
|
|
42
|
+
|
|
2
43
|
export class opening_hours {
|
|
3
44
|
constructor(
|
|
4
45
|
value: string,
|
|
@@ -31,6 +72,7 @@ declare module 'opening_hours' {
|
|
|
31
72
|
date?: Date
|
|
32
73
|
): [boolean, Date, boolean, string | undefined, number | undefined]
|
|
33
74
|
getWarnings(): string[]
|
|
75
|
+
getStructuredWarnings(): opening_hours_warning[]
|
|
34
76
|
isEqualTo(
|
|
35
77
|
second_oh_object: opening_hours,
|
|
36
78
|
start_date?: Date
|