Skip to main content

@0xintuition/atom-parser

Version: V2
View Markdown

What it's for​

Detect and normalize IIDs, text, JSON objects and arrays, URLs, IPFS URIs, addresses, names, and ISBNs into a ParseResult. Parsing identifies the input's shape; it does not resolve the entity, assign a canonical classification, or create an atom on-chain.

When to use it​

Use local detection before choosing a classification plugin or asking a reader to confirm an input. Set remoteFetch: false for local processing. URL and IPFS inspection is enabled by default, so a parser call is not inherently offline.

Install​

npm install @0xintuition/atom-parser@0.1.1

The package ships ESM and CommonJS builds. Use Node 22+ or Bun for the complete parser workflow, which relies on Fetch and Web Streams. The CommonJS build includes the ESM-only multiformats dependency, so require() needs no loader workaround. Local parsing can disable remote inspection with { remoteFetch: false }. See module-format compatibility.

Entry points​

SubpathPurpose
.Parser, local detection, IID candidates, remote inspection, and types
./typesParse results, options, remote outcomes, and ParseError
./detectLocal input detection
./remoteBounded remote inspection and content detection
./parseparseAtom entry point
./iidInspect IID-shaped candidates
./ssrfDestination checks and pinned HTTP transport contracts
./testing/dnsInject DNS behavior for isolated tests

Depends on and works with​

Runtime package dependency: iid. Peer dependencies: none. The runtime dependency graph lists Intuition packages; the package manifest additionally declares multiformats and viem as ordinary dependencies.

Pass parsed evidence into an explicitly configured classification engine. A structured-document candidate can contain schema types and URL hints, but those hints are not a persisted classification.

Example​

This bounded fixed URL is normalized without fetching a page. Narrow on kind before reading variant-specific fields.

import { parseAtom, ParseError } from '@0xintuition/atom-parser';

export const parsed = await parseAtom('https://example.com/catalog', {
remoteFetch: false,
maxInputBytes: 1024,
});
if (parsed.kind === 'url') {
console.log(parsed.canonicalUrl, parsed.remote === undefined);
}

try {
await parseAtom('', { remoteFetch: false });
} catch (error) {
if (!(error instanceof ParseError)) throw error;
console.log(error.code);
}

The URL has no remote result, and empty input throws ParseError with code EMPTY_INPUT. Other input errors include INPUT_TOO_LARGE and invalid gateway configuration. parseIidCandidate returns undefined for non-IID input; an invalid IID-shaped candidate has valid: false, a reason, and no canonical IID. Detection is not proof that an identifier belongs to a particular entity.

Default limits are 16,384 input bytes, three redirects, 1 MiB response bytes, and 256 KiB inspected bytes. The request deadline is five seconds, or eight for IPFS; connectTimeoutMs does not enforce a separate connection deadline. IPFS inspection requires an explicit gateway. Remote outcomes include success, skipped, denied, timeout, error, oversized, and redirect-limit exhaustion; inspect warnings and the outcome before using remote evidence.

The pinned Node transport resolves and vets destinations, pins the approved address, and repeats checks on redirects. The older transport paragraph in the README does not describe this implementation; the linked source and transport test do. A custom transport must preserve the pinned-request contract, and your host still owns egress controls.

See also Classify and enrich atoms.

Source​

Package README, public parser, and pinned-transport test.

Applies to V2 · @0xintuition/atom-parser 0.1.1