Something went wrong. Try again.
Something went wrong. Try again.
123456789101112131415161718192021222324252627282930import assert from "node:assert/strict";import { readFileSync } from "node:fs";import ts from "typescript";
const source = readFileSync(new URL("../src/lib/platform.ts", import.meta.url), "utf8");const { outputText } = ts.transpileModule(source, { compilerOptions: { module: ts.ModuleKind.ESNext },});const { detectPlatform } = await import( `data:text/javascript;base64,${Buffer.from(outputText).toString("base64")}`);
const cases = [ ["android", "Mozilla/5.0 (Linux; Android 15; Pixel 9)", "Linux armv8l", 5], ["ios", "Mozilla/5.0 (iPhone; CPU iPhone OS 18_0 like Mac OS X)", "iPhone", 5], ["ios", "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15) Version/18.0 Safari/605.1.15", "MacIntel", 5], ["macos", "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7)", "MacIntel", 0], ["windows", "Mozilla/5.0 (Windows NT 10.0; Win64; x64)", "Win32", 10], ["linux", "Mozilla/5.0 (X11; Linux x86_64)", "Linux x86_64", 0], ["other", "", "", 0],];for (const [expected, userAgent, platform, maxTouchPoints] of cases) { assert.equal(detectPlatform({ userAgent, platform, maxTouchPoints }), expected);}assert.equal(detectPlatform({ userAgent: "", platform: "Linux", maxTouchPoints: 5, userAgentData: { platform: "Android" },}), "android");console.log("PASS: platform detection, including Android hints and iPad desktop mode");