Format detection sounds simple until the inputs overlap.
A numeric string might be a Unix timestamp, an identifier, or valid-looking Base64. A normal word can use only Base64 characters. JSON often arrives wrapped in Markdown fences or surrounded by an LLM explanation.
For QuickTiny Smart Actions, I wanted the browser to suggest the right tool without uploading the pasted value or calling an AI model.
The detection order
The order is intentional:
- Valid JSON objects or arrays
- Fenced, wrapped, or conservatively repairable JSON
- Plausible Unix timestamps in seconds or milliseconds
- URL-encoded text with valid percent escapes
- Base64 with additional plausibility checks
- Multiline or list-like text
- Plain text as the fallback
Stronger signals run before weaker ones.
JSON first
Strict parsing is the highest-confidence check:
function isJsonObjectOrArray(value) {
try {
const parsed = JSON.parse(value);
return parsed !== null && typeof parsed === "object";
} catch {
return false;
}
}
The repair path is deliberately limited. It can remove Markdown fences, extract a complete object or array from surrounding text, remove trailing commas, and quote simple keys.
It should not invent missing values or guess a schema.
Timestamps before Base64
A loose Base64 regex will match many numeric strings. I exclude pure numbers from Base64 detection and test timestamps by magnitude first.
The value must also fall within a plausible date range. That prevents every short integer from being labeled as a date.
Base64 needs more than a regex
Character-set matching is only the beginning. The detector also checks:
- Minimum length
- Padding shape
- Impossible remainder lengths
- Whether decoding succeeds
- The proportion of printable decoded bytes
- Whether the input is only numeric
Even then, Base64 is a suggestion—not a certainty.
URL-encoded values
The input must contain valid percent-encoded byte sequences, and decoding must succeed. A normal sentence containing a percent sign should not be routed to a URL decoder.
Lists and plain text
Multiline input is useful for cleaning, sorting, and duplicate removal. Everything else falls back to word counting, text cleanup, and case conversion.
Privacy boundary
All detection runs in the browser. QuickTiny records only categorical events such as “detected Base64,” never the pasted value.
This is why deterministic heuristics were a better fit than an AI API for this feature: they are fast, explainable, local, and cheap.
The main lesson
The goal is not to classify every string confidently. The goal is to provide a useful suggestion while keeping the user in control.
Try the live detector:
https://quicktinyv2.vercel.app/
Full methodology:
https://quicktinyv2.vercel.app/how-smart-actions-detects-pasted-content
If you find a non-sensitive value that routes to the wrong tool, I’d genuinely like to see it.
Top comments (0)