SPB Git

spb/tendril Public

Tendril — web ingestion platform (scrape/crawl/map/search) on macOS Apple Silicon: WebKit fidelity, authenticated pages, deterministic testable extraction. A self-hosted Firecrawl alternative.

JavaScript 82.6% TypeScript 11.8% HTML 5.3%
946 B · 35 lines typescript
Raw Blame History
1// author: simon-pierre boucher <contact@spboucher.ai>2import type { TendrilError } from "./errors.js";34export type Ok<T> = { readonly ok: true; readonly value: T };5export type Err<E> = { readonly ok: false; readonly error: E };6export type Result<T, E = TendrilError> = Ok<T> | Err<E>;78export function ok<T>(value: T): Ok<T> {9  return { ok: true, value };10}1112export function err<E>(error: E): Err<E> {13  return { ok: false, error };14}1516export function isOk<T, E>(r: Result<T, E>): r is Ok<T> {17  return r.ok;18}1920export function isErr<T, E>(r: Result<T, E>): r is Err<E> {21  return !r.ok;22}2324export function map<T, U, E>(r: Result<T, E>, f: (value: T) => U): Result<U, E> {25  return r.ok ? ok(f(r.value)) : r;26}2728export function mapErr<T, E, F>(r: Result<T, E>, f: (error: E) => F): Result<T, F> {29  return r.ok ? r : err(f(r.error));30}3132export function unwrapOr<T, E>(r: Result<T, E>, fallback: T): T {33  return r.ok ? r.value : fallback;34}35