Skip to content

Commit 73dd09a

Browse files
committed
chore: deno fmt
1 parent d162853 commit 73dd09a

10 files changed

Lines changed: 217 additions & 78 deletions

File tree

docs/src/App.tsx

Lines changed: 64 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,24 @@
1-
import { useState, useCallback, useRef, useEffect, type ReactNode } from "react";
21
import {
3-
Duckling,
4-
type RenderMapFn,
5-
} from "@claudiu-ceia/ts-duckling";
2+
type ReactNode,
3+
useCallback,
4+
useEffect,
5+
useRef,
6+
useState,
7+
} from "react";
8+
import { Duckling, type RenderMapFn } from "@claudiu-ceia/ts-duckling";
69
import { Header } from "./components/Header";
710
import { ParserSidebar } from "./components/ParserSidebar";
811
import { AnnotatedText } from "./components/AnnotatedText";
912
import { Hovercard } from "./components/Hovercard";
1013
import { extract, type ExtractResult } from "./extract-client";
1114
import type { EntityResult } from "./types";
12-
import { PARSER_PRIORITY, PRESETS, ALL_IDS } from "./registry";
13-
import { fmtDuration, loadSelection, saveSelection, kindClasses } from "./utils";
15+
import { ALL_IDS, PARSER_PRIORITY, PRESETS } from "./registry";
16+
import {
17+
fmtDuration,
18+
kindClasses,
19+
loadSelection,
20+
saveSelection,
21+
} from "./utils";
1422
import { loadUrlText } from "./fetch-url";
1523
import { registry } from "./parsers";
1624

@@ -29,8 +37,12 @@ export function App() {
2937
const [url, setUrl] = useState("");
3038
const [loading, setLoading] = useState(false);
3139

32-
const [hovercardEntities, setHovercardEntities] = useState<EntityResult[]>([]);
33-
const [hovercardAnchor, setHovercardAnchor] = useState<HTMLElement | null>(null);
40+
const [hovercardEntities, setHovercardEntities] = useState<EntityResult[]>(
41+
[],
42+
);
43+
const [hovercardAnchor, setHovercardAnchor] = useState<HTMLElement | null>(
44+
null,
45+
);
3446

3547
const abortRef = useRef<AbortController | null>(null);
3648
const timerRef = useRef<ReturnType<typeof setTimeout>>(undefined);
@@ -69,7 +81,11 @@ export function App() {
6981
return (
7082
<span
7183
key={`${entity.start}-${entity.end}-${entity.kind}`}
72-
className={`ent relative cursor-pointer rounded-md px-1 py-0.5 text-slate-900 outline-1 ${kindClasses(entity.kind)}${hasChildren ? " border-b-2 border-dashed border-slate-400/40" : ""}`}
84+
className={`ent relative cursor-pointer rounded-md px-1 py-0.5 text-slate-900 outline-1 ${
85+
kindClasses(entity.kind)
86+
}${
87+
hasChildren ? " border-b-2 border-dashed border-slate-400/40" : ""
88+
}`}
7389
onClick={(ev: React.MouseEvent<HTMLSpanElement>) => {
7490
ev.stopPropagation();
7591
// Show all entities contained within this span
@@ -149,9 +165,7 @@ export function App() {
149165
if (controller.signal.aborted) return;
150166

151167
setSegments(segs);
152-
const suffix = result.truncated
153-
? ` (prefix ${result.length} chars)`
154-
: "";
168+
const suffix = result.truncated ? ` (prefix ${result.length} chars)` : "";
155169
setTiming(`${fmtDuration(result.ms)}${suffix}`);
156170
setStatus("");
157171
} catch (err) {
@@ -263,19 +277,28 @@ export function App() {
263277

264278
<main className="mx-auto max-w-7xl px-6 py-6">
265279
<div className="grid grid-cols-1 gap-4 lg:grid-cols-[360px_1fr]">
266-
<ParserSidebar selected={selected} onSelectionChange={onSelectionChange} />
280+
<ParserSidebar
281+
selected={selected}
282+
onSelectionChange={onSelectionChange}
283+
/>
267284

268285
<div className="space-y-4">
269286
{/* Input section */}
270287
<section className="rounded-2xl border border-slate-200 bg-white shadow-sm">
271288
<div className="flex items-center justify-between border-b border-slate-200 px-4 py-3">
272-
<h2 className="text-sm font-semibold tracking-wide text-slate-900">Input</h2>
273-
<div className="text-sm text-slate-500">{input.length} chars</div>
289+
<h2 className="text-sm font-semibold tracking-wide text-slate-900">
290+
Input
291+
</h2>
292+
<div className="text-sm text-slate-500">
293+
{input.length} chars
294+
</div>
274295
</div>
275296
<div className="p-4">
276297
<div className="grid grid-cols-1 gap-3 md:grid-cols-[160px_1fr]">
277298
<label className="text-sm text-slate-600">
278-
<div className="mb-1 font-medium text-slate-700">Preset</div>
299+
<div className="mb-1 font-medium text-slate-700">
300+
Preset
301+
</div>
279302
<select
280303
value={preset}
281304
onChange={(e) => handlePreset(e.target.value)}
@@ -289,14 +312,17 @@ export function App() {
289312
</label>
290313

291314
<div>
292-
<div className="mb-1 text-sm font-medium text-slate-700">Max chars</div>
315+
<div className="mb-1 text-sm font-medium text-slate-700">
316+
Max chars
317+
</div>
293318
<div className="flex items-center gap-2">
294319
<input
295320
type="number"
296321
min={500}
297322
step={500}
298323
value={maxChars}
299-
onChange={(e) => setMaxChars(Number(e.target.value) || 8000)}
324+
onChange={(e) =>
325+
setMaxChars(Number(e.target.value) || 8000)}
300326
className="w-32 rounded-xl border border-slate-200 bg-white px-3 py-2 text-sm font-semibold text-slate-900 shadow-sm focus:border-teal-300 focus:outline-none focus:ring-4 focus:ring-teal-200/40"
301327
/>
302328
<label className="flex items-center gap-2 text-sm font-medium text-slate-700">
@@ -319,7 +345,9 @@ export function App() {
319345
type="text"
320346
value={url}
321347
onChange={(e) => setUrl(e.target.value)}
322-
onKeyDown={(e) => { if (e.key === "Enter") handleLoadUrl(); }}
348+
onKeyDown={(e) => {
349+
if (e.key === "Enter") handleLoadUrl();
350+
}}
323351
placeholder="https://en.wikipedia.org/wiki/Perceptual_hashing"
324352
className="w-full rounded-xl border border-slate-200 bg-white px-3 py-2 text-sm font-medium text-slate-900 shadow-sm placeholder:text-slate-400 focus:border-teal-300 focus:outline-none focus:ring-4 focus:ring-teal-200/40"
325353
/>
@@ -336,7 +364,10 @@ export function App() {
336364

337365
<textarea
338366
value={input}
339-
onChange={(e) => { setInput(e.target.value); setPreset(""); }}
367+
onChange={(e) => {
368+
setInput(e.target.value);
369+
setPreset("");
370+
}}
340371
disabled={spinning}
341372
spellCheck={false}
342373
className="mt-4 h-56 w-full resize-y rounded-2xl border border-slate-200 bg-white p-4 font-mono text-sm leading-relaxed text-slate-900 shadow-sm focus:border-teal-300 focus:outline-none focus:ring-4 focus:ring-teal-200/40 disabled:bg-slate-50 disabled:text-slate-500 disabled:cursor-not-allowed"
@@ -348,13 +379,17 @@ export function App() {
348379
{/* Preview section */}
349380
<section className="rounded-2xl border border-slate-200 bg-white shadow-sm">
350381
<div className="flex items-center justify-between border-b border-slate-200 px-4 py-3">
351-
<h2 className="text-sm font-semibold tracking-wide text-slate-900">Preview</h2>
382+
<h2 className="text-sm font-semibold tracking-wide text-slate-900">
383+
Preview
384+
</h2>
352385
<div className="flex items-center gap-3 text-sm text-slate-500">
353386
<span>{entities.length} matches</span>
354387
{elapsed && (
355388
<>
356389
<span className="text-slate-300"></span>
357-
<span className="font-mono text-teal-600 tabular-nums">{elapsed}</span>
390+
<span className="font-mono text-teal-600 tabular-nums">
391+
{elapsed}
392+
</span>
358393
</>
359394
)}
360395
{timing && !elapsed && (
@@ -379,7 +414,9 @@ export function App() {
379414
Annotated text
380415
</div>
381416
<div className="mt-2">
382-
<AnnotatedText segments={segments.length > 0 ? segments : [input]} />
417+
<AnnotatedText
418+
segments={segments.length > 0 ? segments : [input]}
419+
/>
383420
</div>
384421

385422
{showJson && (
@@ -401,7 +438,10 @@ export function App() {
401438
<Hovercard
402439
entities={hovercardEntities}
403440
anchor={hovercardAnchor}
404-
onClose={() => { setHovercardEntities([]); setHovercardAnchor(null); }}
441+
onClose={() => {
442+
setHovercardEntities([]);
443+
setHovercardAnchor(null);
444+
}}
405445
/>
406446
</>
407447
);

docs/src/components/Header.tsx

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,12 @@ export function Header({ children }: Props) {
2424
rel="noreferrer"
2525
className="inline-flex items-center gap-2 rounded-full border border-slate-200 bg-white px-3 py-1 text-sm font-medium text-slate-700 hover:border-slate-300 hover:text-slate-900"
2626
>
27-
<svg viewBox="0 0 16 16" width="16" height="16" aria-hidden="true">
27+
<svg
28+
viewBox="0 0 16 16"
29+
width="16"
30+
height="16"
31+
aria-hidden="true"
32+
>
2833
<path
2934
fill="currentColor"
3035
d="M8 0C3.58 0 0 3.58 0 8c0 3.54 2.29 6.53 5.47 7.59.4.07.55-.17.55-.38 0-.19-.01-.82-.01-1.49-2.01.37-2.53-.49-2.69-.94-.09-.23-.48-.94-.82-1.13-.28-.15-.68-.52-.01-.53.63-.01 1.08.58 1.23.82.72 1.21 1.87.87 2.33.66.07-.52.28-.87.51-1.07-1.78-.2-3.64-.89-3.64-3.95 0-.87.31-1.59.82-2.15-.08-.2-.36-1.02.08-2.12 0 0 .67-.21 2.2.82.64-.18 1.32-.27 2-.27.68 0 1.36.09 2 .27 1.53-1.04 2.2-.82 2.2-.82.44 1.1.16 1.92.08 2.12.51.56.82 1.27.82 2.15 0 3.07-1.87 3.75-3.65 3.95.29.25.54.73.54 1.48 0 1.07-.01 1.93-.01 2.2 0 .21.15.46.55.38A8.013 8.013 0 0 0 16 8c0-4.42-3.58-8-8-8Z"
@@ -34,8 +39,9 @@ export function Header({ children }: Props) {
3439
</a>
3540
</div>
3641
<p className="mt-1 max-w-2xl text-sm leading-relaxed text-slate-600">
37-
A tiny, deterministic entity extractor for TypeScript/Deno, inspired
38-
by Duckling. This version uses parser-combinator grammars (no ML).
42+
A tiny, deterministic entity extractor for TypeScript/Deno,
43+
inspired by Duckling. This version uses parser-combinator
44+
grammars (no ML).
3945
</p>
4046
</div>
4147
</div>

docs/src/components/Hovercard.tsx

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { useState, useEffect, useRef } from "react";
1+
import { useEffect, useRef, useState } from "react";
22
import type { EntityResult } from "../types";
33

44
type Props = {
@@ -25,7 +25,10 @@ export function Hovercard({ entities, anchor, onClose }: Props) {
2525
if (top + c.height + margin > window.innerHeight) {
2626
top = a.top - c.height - 10;
2727
}
28-
top = Math.max(margin, Math.min(top, window.innerHeight - c.height - margin));
28+
top = Math.max(
29+
margin,
30+
Math.min(top, window.innerHeight - c.height - margin),
31+
);
2932

3033
let left = a.left;
3134
if (left + c.width + margin > window.innerWidth) {
@@ -64,8 +67,9 @@ export function Hovercard({ entities, anchor, onClose }: Props) {
6467
Match
6568
</div>
6669
<div className="mt-1 truncate font-mono text-sm text-slate-900">
67-
{match.kind} &nbsp;"{match.text.length > 60 ? `${match.text.slice(0, 60)}…` : match.text}"
68-
&nbsp;[{match.start},{match.end}]
70+
{match.kind} &nbsp;"{match.text.length > 60
71+
? `${match.text.slice(0, 60)}…`
72+
: match.text}" &nbsp;[{match.start},{match.end}]
6973
</div>
7074
{entities.length > 1 && (
7175
<div className="mt-2 flex flex-wrap gap-2">

docs/src/components/ParserSidebar.tsx

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { ParserCheckbox } from "./ParserCheckbox";
2-
import { PARSER_REGISTRY, ALL_IDS, PII_IDS } from "../registry";
2+
import { ALL_IDS, PARSER_REGISTRY, PII_IDS } from "../registry";
33

44
type Props = {
55
selected: Set<string>;
@@ -26,10 +26,20 @@ export function ParserSidebar({ selected, onSelectionChange }: Props) {
2626
</div>
2727
<div className="p-4">
2828
<div className="flex flex-wrap gap-2 pb-3">
29-
<QuickBtn label="All" onClick={() => onSelectionChange(new Set(ALL_IDS))} />
29+
<QuickBtn
30+
label="All"
31+
onClick={() => onSelectionChange(new Set(ALL_IDS))}
32+
/>
3033
<QuickBtn label="None" onClick={() => onSelectionChange(new Set())} />
31-
<QuickBtn label="PII" onClick={() => onSelectionChange(new Set(PII_IDS))} />
32-
<QuickBtn label="Default" onClick={() => onSelectionChange(new Set(ALL_IDS))} active />
34+
<QuickBtn
35+
label="PII"
36+
onClick={() => onSelectionChange(new Set(PII_IDS))}
37+
/>
38+
<QuickBtn
39+
label="Default"
40+
onClick={() => onSelectionChange(new Set(ALL_IDS))}
41+
active
42+
/>
3343
</div>
3444
<div className="space-y-2" role="list">
3545
{PARSER_REGISTRY.map((p) => (
@@ -52,7 +62,13 @@ export function ParserSidebar({ selected, onSelectionChange }: Props) {
5262
);
5363
}
5464

55-
function QuickBtn({ label, onClick, active }: { label: string; onClick: () => void; active?: boolean }) {
65+
function QuickBtn(
66+
{ label, onClick, active }: {
67+
label: string;
68+
onClick: () => void;
69+
active?: boolean;
70+
},
71+
) {
5672
return (
5773
<button
5874
type="button"

docs/src/extract-client.ts

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,4 @@
1-
import {
2-
Duckling,
3-
type AsyncScanOptions,
4-
} from "@claudiu-ceia/ts-duckling";
1+
import { type AsyncScanOptions, Duckling } from "@claudiu-ceia/ts-duckling";
52
import type { EntityResult } from "./types";
63
import { registry } from "./parsers";
74

docs/src/fetch-url.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,10 @@ export async function loadUrlText(raw: string): Promise<LoadResult> {
4848
const t0 = performance.now();
4949
const html = await fetchHtml(url);
5050
const doc = new DOMParser().parseFromString(html, "text/html");
51-
const parsed = new Readability(doc, { baseURI: url } as ConstructorParameters<typeof Readability>[1]).parse();
51+
const parsed = new Readability(
52+
doc,
53+
{ baseURI: url } as ConstructorParameters<typeof Readability>[1],
54+
).parse();
5255
const text = parsed?.textContent?.trim()
5356
? parsed.textContent.trim()
5457
: (doc.body?.innerText || "").trim();

docs/src/parsers.ts

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,20 @@
11
import type { Parser } from "@claudiu-ceia/combine";
22
import {
3-
Range,
4-
Time,
5-
Temperature,
6-
Quantity,
7-
Location,
8-
URL,
3+
ApiKey,
4+
CreditCard,
95
Email,
106
Institution,
7+
IPAddress,
118
Language,
9+
Location,
1210
Phone,
13-
IPAddress,
11+
Quantity,
12+
Range,
1413
SSN,
15-
CreditCard,
14+
Temperature,
15+
Time,
16+
URL,
1617
UUID,
17-
ApiKey,
1818
} from "@claudiu-ceia/ts-duckling";
1919

2020
// eslint-disable-next-line @typescript-eslint/no-explicit-any

0 commit comments

Comments
 (0)