tilfluktsrom/pwa/node_modules/core-js-compat/helpers.js
Ole-Morten Duesund e8428de775 Add progressive web app companion for cross-platform access
Vite + TypeScript PWA that mirrors the Android app's core features:
- Pre-processed shelter data (build-time UTM33N→WGS84 conversion)
- Leaflet map with shelter markers, user location, and offline tiles
- Canvas compass arrow (ported from DirectionArrowView.kt)
- IndexedDB shelter cache with 7-day staleness check
- Service worker with CacheFirst tiles and precached app shell
- i18n for en, nb, nn (ported from Android strings.xml)
- iOS/Android compass handling with low-pass filter
- Respects user map interaction (no auto-snap on pan/zoom)
- Build revision cache-breaker for reliable SW updates

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-08 17:41:38 +01:00

65 lines
1.8 KiB
JavaScript

'use strict';
// eslint-disable-next-line es/no-object-hasown -- safe
const has = Object.hasOwn || Function.call.bind({}.hasOwnProperty);
const VERSION_PATTERN = /(\d+)(?:\.(\d+))?(?:\.(\d+))?/;
class SemVer {
constructor(input) {
const match = VERSION_PATTERN.exec(input);
if (!match) throw new TypeError(`Invalid version: ${ input }`);
const [, $major, $minor, $patch] = match;
this.major = +$major;
this.minor = $minor ? +$minor : 0;
this.patch = $patch ? +$patch : 0;
}
toString() {
return `${ this.major }.${ this.minor }.${ this.patch }`;
}
}
function semver(input) {
return input instanceof SemVer ? input : new SemVer(input);
}
function compare($a, operator, $b) {
const a = semver($a);
const b = semver($b);
for (const component of ['major', 'minor', 'patch']) {
if (a[component] < b[component]) return operator === '<' || operator === '<=' || operator === '!=';
if (a[component] > b[component]) return operator === '>' || operator === '>=' || operator === '!=';
} return operator === '==' || operator === '<=' || operator === '>=';
}
function filterOutStabilizedProposals(modules) {
const modulesSet = new Set(modules);
for (const $module of modulesSet) {
if ($module.startsWith('esnext.') && modulesSet.has($module.replace(/^esnext\./, 'es.'))) {
modulesSet.delete($module);
}
}
return [...modulesSet];
}
function intersection(list, order) {
const set = list instanceof Set ? list : new Set(list);
return order.filter(name => set.has(name));
}
function sortObjectByKey(object, fn) {
return Object.keys(object).sort(fn).reduce((memo, key) => {
memo[key] = object[key];
return memo;
}, {});
}
module.exports = {
compare,
filterOutStabilizedProposals,
has,
intersection,
semver,
sortObjectByKey,
};