📄 src/ddc/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 DDCProps extends Record<string, string | null> { ddcNotation: string | null; }
19
20type DDCApis = Record<string, never>;
21
22export const DDCAdapter: StandardAdapter<DDCProps, DDCApis> = {
23 standardId: 'ddc',
24 uriScheme: 'DDC',
25
26 normalize(value: string): string {
27 let trimmed = value.trim();
28 if (trimmed.includes('.')) trimmed = trimmed.replace(/\.?0+$/, '');
29 return trimmed;
30 },
31
32 display(value: string): string {
33 return DDCAdapter.normalize(value);
34 },
35
36 validate(value: string | null | undefined): ValidationResult {
37 if (!value) return { valid: false, error: 'DDC notation is absent' };
38 const normalized = DDCAdapter.normalize(value);
39 if (!/^[0-9]{3}(\.[0-9]+)?$/.test(normalized))
40 return { valid: false, error: `DDC notation does not match pattern: ${normalized}` };
41 return { valid: true };
42 },
43
44 toLinkedDataUri(value: string): string {
45 return `https://id.loc.gov/authorities/classification/${DDCAdapter.normalize(value)}`;
46 },
47
48 apis: {},
49};
50