📄 src/udc/index.ts
D-OPEN SOVEREIGN
1/*
2 * Copyright (c) 2026 DataPond D-Library Pty Ltd. ("The Sanctuary")
3 * Non-Profit Public Library — The World Library
4 * 
5 * D-SAFE Certification issued by POND Enterprise.
6 * Published under the D-Open Code Sovereign Licence v1.0 framework
7 * DataPond D-Library All exclusive Right reserved on modifiying the code - CC Attribution to data pond, Non modifiable, Non Commercial.
8 * https://registry.world.bibliotech.com/licence
9 * Source code donated to DataPond D-Library by it's author: data pond.
10 * 
11 * Technical Guardian ("The Shield"): Pond Enterprise Pty Ltd. (ACN 694 747 987)
12 * All liability claims about D-SAFE certification issues coming from the published D-Safe direction must be addressed with Pond Enterprise Pty Ltd.
13 * Code Modification automatically voids the certified liability protection provided by Pond Enterprise.
14 */
15import type { StandardAdapter, ValidationResult }
16  from '@the_library/canonical-schemas/types/StandardAdapter';
17
18interface UDCProps extends Record<string, string | null> { udcNotation: string | null; }
19
20type UDCApis = Record<string, never>;
21
22export const UDCAdapter: StandardAdapter<UDCProps, UDCApis> = {
23  standardId: 'udc',
24  uriScheme:  'UDC',
25
26  normalize(value: string): string {
27    return value.trim();
28  },
29
30  display(value: string): string {
31    return UDCAdapter.normalize(value);
32  },
33
34  validate(value: string | null | undefined): ValidationResult {
35    if (!value) return { valid: false, error: 'UDC notation is absent' };
36    const normalized = UDCAdapter.normalize(value);
37    if (!/^[0-9\.\-\:\+\/\(\)\[\]\=\*\"\s]+$/.test(normalized))
38      return { valid: false, error: `UDC notation does not match pattern: ${normalized}` };
39    return { valid: true };
40  },
41
42  toLinkedDataUri(value: string): string {
43    return `https://udcsummary.info/php/index.php?c=${UDCAdapter.normalize(value)}`;
44  },
45
46  apis: {},
47};
48