Proper data types

[skip ci]
This commit is contained in:
shamoon
2026-06-28 12:33:18 -07:00
parent c3a3939387
commit 20a855444b
3 changed files with 130 additions and 67 deletions
+53 -13
View File
@@ -1,11 +1,51 @@
import { ObjectWithId } from './object-with-id'
export type OcrZoneTarget = 'custom_field' | 'title' | 'asn' | 'created'
export type OcrBuiltinTarget = Exclude<OcrZoneTarget, 'custom_field'>
export type OcrZoneTransform =
| 'none'
| 'strip'
| 'uppercase'
| 'lowercase'
| 'numeric'
| 'strip_punctuation'
| 'date'
| 'qr_code'
export const OCR_ZONE_TARGET = {
CustomField: 'custom_field',
Title: 'title',
Asn: 'asn',
Created: 'created',
} as const satisfies Record<string, OcrZoneTarget>
export const OCR_ZONE_TRANSFORM = {
None: 'none',
Strip: 'strip',
Uppercase: 'uppercase',
Lowercase: 'lowercase',
Numeric: 'numeric',
StripPunctuation: 'strip_punctuation',
Date: 'date',
QrCode: 'qr_code',
} as const satisfies Record<string, OcrZoneTransform>
export const DEFAULT_OCR_ZONE_TARGET = OCR_ZONE_TARGET.CustomField
export const DEFAULT_OCR_ZONE_TRANSFORM = OCR_ZONE_TRANSFORM.Strip
export const DEFAULT_OCR_ZONE_LANGUAGE = 'deu+eng'
export function isOcrBuiltinTarget(value: unknown): value is OcrBuiltinTarget {
return (
value === OCR_ZONE_TARGET.Title ||
value === OCR_ZONE_TARGET.Asn ||
value === OCR_ZONE_TARGET.Created
)
}
export const OCR_BUILTIN_TARGETS = [
{ id: 'title', name: $localize`Title` },
{ id: 'asn', name: $localize`Archive serial number` },
{ id: 'created', name: $localize`Date created` },
{ id: OCR_ZONE_TARGET.Title, name: $localize`Title` },
{ id: OCR_ZONE_TARGET.Asn, name: $localize`Archive serial number` },
{ id: OCR_ZONE_TARGET.Created, name: $localize`Date created` },
]
export interface OcrTemplateZone {
@@ -19,7 +59,7 @@ export interface OcrTemplateZone {
width: number
height: number
ocr_language: string
transform: string
transform: OcrZoneTransform
date_format?: string
validation_regex: string
order: number
@@ -28,17 +68,17 @@ export interface OcrTemplateZone {
}
export const TRANSFORM_OPTIONS = [
{ id: 'none', name: $localize`None` },
{ id: 'strip', name: $localize`Strip whitespace` },
{ id: 'uppercase', name: $localize`Uppercase` },
{ id: 'lowercase', name: $localize`Lowercase` },
{ id: 'numeric', name: $localize`Numeric only` },
{ id: OCR_ZONE_TRANSFORM.None, name: $localize`None` },
{ id: OCR_ZONE_TRANSFORM.Strip, name: $localize`Strip whitespace` },
{ id: OCR_ZONE_TRANSFORM.Uppercase, name: $localize`Uppercase` },
{ id: OCR_ZONE_TRANSFORM.Lowercase, name: $localize`Lowercase` },
{ id: OCR_ZONE_TRANSFORM.Numeric, name: $localize`Numeric only` },
{
id: 'strip_punctuation',
id: OCR_ZONE_TRANSFORM.StripPunctuation,
name: $localize`Remove leading/trailing punctuation`,
},
{ id: 'date', name: $localize`Parse date` },
{ id: 'qr_code', name: $localize`Read QR/barcode` },
{ id: OCR_ZONE_TRANSFORM.Date, name: $localize`Parse date` },
{ id: OCR_ZONE_TRANSFORM.QrCode, name: $localize`Read QR/barcode` },
]
export const OCR_LANGUAGE_OPTIONS = [
@@ -79,7 +119,7 @@ export interface ZoneTestRequest {
height: number
page: number
ocr_language: string
transform: string
transform: OcrZoneTransform
date_format?: string
validation_regex: string
zone_source_width?: number