UNPKG

@cto.af/ucd

Version:

Download, cache, and parse files from the Unicode Character Database (UCD).

67 lines (63 loc) 1.89 kB
import { UCDFile } from './ucdFile.js'; export { CodePoints, Entry, Field, FieldDef, Points, Range } from './ucdFile.js'; import { PathLike } from 'node:fs'; interface FetchOptions { etag?: string; lastModified?: string; CI?: boolean; } interface UCDoptions { /** * Where to cache downloaded database files. */ cacheDir?: PathLike; /** * Parse the file, even if you get a 304 from the web server. Changes the * status to 200 in this case. */ alwaysParse?: boolean; /** * Check for new version, even if we are in CI. Mostly useful for testing. */ checkinCI?: boolean; /** * URL prefix for Unicode Database. Filename is appended to this to get * full URL. */ prefix?: string; /** * Enable verbose logging to stdout. */ verbose?: boolean; } interface UCDversion { date: Date; version: string; lastModified: string; etag: string; } interface FailRead { status: number; etag: string; lastModified: string; } interface SuccessRead extends FailRead { status: 200; text: string; } type FileInfo = FailRead extends SuccessRead ? SuccessRead : FailRead; interface SuccessParsedFileInfo extends SuccessRead { parsed: UCDFile; } type ParsedFileInfo = SuccessParsedFileInfo | FailRead; declare function isSuccess(fi: FileInfo): fi is SuccessParsedFileInfo; declare class UCD { #private; private constructor(); static create(options?: UCDoptions): Promise<UCD>; init(): Promise<this>; rmDir(): Promise<void>; fetchUCDversion(opts?: FetchOptions): Promise<UCDversion>; parse(name: string, opts?: FetchOptions): Promise<ParsedFileInfo>; } export { type FailRead, type FetchOptions, type FileInfo, type ParsedFileInfo, type SuccessParsedFileInfo, type SuccessRead, UCD, UCDFile, type UCDoptions, type UCDversion, isSuccess };