You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
38 lines
1.4 KiB
38 lines
1.4 KiB
// ─────────────────────────────────────────────
|
|
// Type guards de primitivos
|
|
// ─────────────────────────────────────────────
|
|
|
|
import type {CurrencyValue, MediaRef, MetadataField, MetadataFieldType} from "@/mtas/lib/types.ts";
|
|
|
|
export function isCurrencyValue(v: unknown): v is CurrencyValue {
|
|
if (typeof v !== 'object' || v === null) return false;
|
|
const c = v as Record<string, unknown>;
|
|
return typeof c['amount'] === 'number' && typeof c['currency'] === 'string' && c['currency'].length > 0;
|
|
}
|
|
|
|
export function isMediaRef(v: unknown): v is MediaRef {
|
|
if (typeof v !== 'object' || v === null) return false;
|
|
const m = v as Record<string, unknown>;
|
|
return typeof m['url'] === 'string' && m['url'].length > 0;
|
|
}
|
|
|
|
|
|
|
|
export function isValidUrl(value: string): boolean {
|
|
try { new URL(value); return true; } catch { return false; }
|
|
}
|
|
|
|
const KNOWN_TYPES: MetadataFieldType[] = [
|
|
'string','number','boolean','ling','date','datetime',
|
|
'url','currency','image','video','audio','pdf','file','group',
|
|
];
|
|
|
|
|
|
|
|
export function isMetadataField(v: unknown): v is MetadataField {
|
|
if (typeof v !== 'object' || v === null) return false;
|
|
const f = v as Record<string, unknown>;
|
|
return KNOWN_TYPES.includes(f['type'] as MetadataFieldType);
|
|
}
|
|
|