DEV Community

R (RYUSLOG DEV)
R (RYUSLOG DEV)

Posted on

Fifteen developer tools, zero dependencies

Fifteen developer tools, zero dependencies

Most "online JSON formatter" pages send your payload to a server, keep it for a while, and hope you don't think about it. Building tools that don't need to is mostly a matter of knowing which platform APIs already exist, and being willing to write the small amount of maths that a library would otherwise hide.

ryuslog.com/tools now has fifteen of them — JSON, YAML, diff, regex, SQL, CSV, JWT, Base64, URL, hash, cURL, UUID, timestamps, cron and colour/contrast. All of them run entirely in the tab: no upload, no account, no server round trip. This is what that actually takes, and where the sharp edges are.

The rule that shapes everything

Every tool is one pure function from input to output, with the DOM kept at the edges:

type ToolResult<T> = { ok: true; value: T } | { ok: false; error: string; at?: number };

export function formatJson(input: string, opts: JsonOptions): ToolResult<string> { /* … */ }
Enter fullscreen mode Exit fullscreen mode

That shape buys three things at once. The engine is testable without a browser, the UI is a thin shell that renders ToolResult, and an error carries a position so the editor can underline the offending character instead of saying "invalid input".

The rest is browser API archaeology.

Web Crypto: generous, with two gaps

crypto.subtle.digest covers SHA-1, SHA-256, SHA-384 and SHA-512, is fast, and returns an ArrayBuffer you hex-encode yourself:

async function sha256(text: string) {
  const buf = await crypto.subtle.digest('SHA-256', new TextEncoder().encode(text));
  return [...new Uint8Array(buf)].map((b) => b.toString(16).padStart(2, '0')).join('');
}
Enter fullscreen mode Exit fullscreen mode

Two gaps matter for developer tooling:

  • MD5 is not there. Plenty of legacy checksums still need it, so the hash generator computes MD5 in plain TypeScript and uses subtle for the SHA family.
  • Nothing is timing-safe for you. Verifying an HMAC (as a JWT signature check would) is importKey + sign + a byte-wise comparison — === on hex strings leaks timing, and comparing base64url strings is worse because of padding.

There is also a third gap that trips people up: subtle is only available in a secure context, so the same code silently fails on http://192.168.x.x during development.

OKLCH in about forty lines

The colour tool converts HEX → RGB → HSL → OKLCH and back, and checks WCAG contrast. OKLCH is where the maths is:

const toLinear = (c: number) => (c <= 0.04045 ? c / 12.92 : ((c + 0.055) / 1.055) ** 2.4);

// linear sRGB -> Oklab
const l = 0.4122214708 * r + 0.5363325363 * g + 0.0514459929 * b;
const m = 0.2119034982 * r + 0.6806995451 * g + 0.1073969566 * b;
const s = 0.0883024619 * r + 0.2817188376 * g + 0.6299787005 * b;

const l_ = Math.cbrt(l), m_ = Math.cbrt(m), s_ = Math.cbrt(s);

const L = 0.2104542553 * l_ + 0.7936177850 * m_ - 0.0040720468 * s_;
const a = 1.9779984951 * l_ - 2.4285922050 * m_ + 0.4505937099 * s_;
const bb = 0.0259040371 * l_ + 0.7827717662 * m_ - 0.8086757660 * s_;

const C = Math.hypot(a, bb);
const H = (Math.atan2(bb, a) * 180) / Math.PI;
Enter fullscreen mode Exit fullscreen mode

Two things that only show up when you build the inverse:

  • Round trips leave the gamut. OKLCH can express colours sRGB cannot, so converting back produces components outside [0, 1]. Clamping each channel shifts the hue; reducing chroma at constant lightness is the honest fix, and the UI needs to say when it happened.
  • Contrast is not computed on the hex. WCAG's ratio is (L1 + 0.05) / (L2 + 0.05) over relative luminance, which is the linear-light value weighted 0.2126 R + 0.7152 G + 0.0722 B. Skipping the linearisation is the classic bug: it passes pairs that fail AA in a real browser. And if a colour has alpha, composite it over the background first.

Cron: the next run time is not "now plus five minutes"

Explaining */15 9-17 * * 1-5 in English is easy. Producing the next six run times is where implementations diverge, because:

  • day-of-month and day-of-week combine with OR, not AND, when both are restricted;
  • 0 and 7 are both Sunday;
  • February 30th has to be skipped, not incremented;
  • a DST jump can make a wall-clock time not exist, or exist twice.

Iterating minute by minute for up to a year is 525,600 checks — fine for one expression, wasteful for six results. Iterating the sets (month → day → hour → minute) is both faster and easier to keep correct. Showing the answer in local time and UTC is the cheapest way to defuse "but it runs at 3am".

Try it on the cron parser.

Diff: trim first, then spend the budget

A textbook LCS table for two 5,000-line files is 25 million cells. Before any of that, trim the common prefix and suffix — on a config diff, that's usually 90% of the file:

let start = 0;
while (start < a.length && start < b.length && a[start] === b[start]) start++;
let endA = a.length - 1, endB = b.length - 1;
while (endA >= start && endB >= start && a[endA] === b[endB]) { endA--; endB--; }
Enter fullscreen mode Exit fullscreen mode

What remains is the actual edit region, where the LCS table is small. When it isn't, the choices are Myers' O(ND) algorithm (fast when the change is small, quadratic when it isn't) or anchoring on unique lines first, as patience diff does. The diff tool also ignores whitespace on request, which is the single most useful option in code review.

JSON → TypeScript, with optionality

Inferring interfaces is a recursion with a merge step. The interesting part is what to do with arrays of objects that differ:

type Shape =
  | { kind: 'object'; props: Map<string, Shape>; seen: number }
  | { kind: 'array'; item: Shape }
  | { kind: 'scalar'; ts: string };
Enter fullscreen mode Exit fullscreen mode

Merge each object into the accumulator, count how many elements contained each key, and mark a key optional when it appears in fewer than all of them. null becomes | null, numbers stay number (unless the literal set is small and closed), and keys that aren't valid identifiers get quoted. The JSON formatter emits the result with nested interfaces named from the path, because Data, Data2, Data3 is what makes generated types useless.

cURL → code is a shell problem, not an HTTP one

Half of that tool is tokenising: \ line continuations, 'single quoted' vs "double quoted $VAR", -H 'A: b' vs -H'A: b'. Only then do you map flags — -X, --data-raw, --data-urlencode, -u, --cookie, -F, --compressed — and emit fetch, Python requests, or Go net/http. Getting --data-urlencode wrong turns a form body into a JSON body and the generated snippet silently fails, which is exactly the bug people use such a tool to avoid.

The UI details that decide whether the tab stays open

  • Run on input, debounced. 120 ms feels instant and keeps typing smooth; a "Run" button feels like 1998 and hides the feedback loop.
  • Errors carry a position. Unexpected token } in JSON at position 42 is useless without underlining character 42.
  • State in the URL hash. #json?input=… makes a result shareable and survives a reload; keep it out of server logs, which the hash does by construction.
  • No layout shift. Reserve the output pane's height before the first result; jumping content is what makes a tool feel broken.
  • Contrast in the UI itself. A contrast checker with unreadable labels is a bad joke, and dark mode needs its own pass.

What the platform still doesn't do for you

navigator.clipboard.writeText needs a secure context and a user gesture; anything else falls back to a hidden textarea and document.execCommand('copy'). Downloads are a Blob plus URL.createObjectURL, and you must revokeObjectURL or leak the file for the life of the tab. And "no server" means no history and no sync — localStorage is the only memory you get, so treat it as a convenience, never as storage.

Fifteen tools later, the thing I'd tell someone starting the same project: the browser gives you more than you think (crypto, URL, Intl, structured clone, workers) and less than you hope (no MD5, no timing-safe compare, no diff, no colour science). Both halves are small, and neither needs a dependency.

The tools are at ryuslog.com/tools; longer write-ups on the same site go deeper on the specifics, for example resource requests, limits and OOMKilled and useEffect dependencies and race conditions.

Top comments (0)