@@ -14,6 +14,41 @@ function stripJATSTags(text: string): string {
1414 return text . replace ( / < [ ^ > ] * > / g, '' ) . trim ( ) ;
1515}
1616
17+ /**
18+ * Normalize a DOI to its canonical form (e.g., "10.1234/example")
19+ *
20+ * Supported input formats:
21+ * - Plain DOI: 10.1234/example
22+ * - With doi: prefix: doi:10.1234/example
23+ * - HTTPS doi.org: https://doi.org/10.1234/example
24+ * - HTTP doi.org: http://doi.org/10.1234/example
25+ * - With www: https://www.doi.org/10.1234/example
26+ * - dx.doi.org: https://dx.doi.org/10.1234/example
27+ * - Handle.net: https://hdl.handle.net/10.1234/example
28+ * - dx.hdl.handle.net: https://dx.hdl.handle.net/10.1234/example
29+ * - URL with doi: prefix: https://doi.org/doi:10.1234/example
30+ *
31+ * @param input - DOI in any supported format
32+ * @returns Normalized DOI starting with "10." or the original input if not recognized
33+ */
34+ export function normalizeDOI ( input : string ) : string {
35+ if ( ! input ) return input ;
36+
37+ let doi = input . trim ( ) ;
38+
39+ // Remove URL prefixes (http/https, www, dx subdomain, various hosts)
40+ // Handles: doi.org, dx.doi.org, www.doi.org, hdl.handle.net, dx.hdl.handle.net
41+ doi = doi . replace (
42+ / ^ h t t p s ? : \/ \/ (?: w w w \. ) ? (?: (?: d x \. ) ? d o i \. o r g | (?: d x \. ) ? h d l \. h a n d l e \. n e t ) \/ / i,
43+ ''
44+ ) ;
45+
46+ // Remove doi: prefix (may appear after URL stripping or standalone)
47+ doi = doi . replace ( / ^ d o i : / i, '' ) ;
48+
49+ return doi . trim ( ) ;
50+ }
51+
1752export interface DOIMetadata {
1853 title ?: string ;
1954 authors ?: string [ ] ;
@@ -26,8 +61,8 @@ export interface DOIMetadata {
2661
2762export async function resolveDOI ( doi : string ) : Promise < DOIMetadata | null > {
2863 try {
29- // Clean DOI
30- const cleanDOI = doi . replace ( / ^ ( h t t p s ? : \/ \/ ) ? ( d x \. ) ? d o i \. o r g \/ / , '' ) ;
64+ // Clean DOI using normalizeDOI for comprehensive format support
65+ const cleanDOI = normalizeDOI ( doi ) ;
3166
3267 // Try CrossRef first
3368 const response = await fetch (
0 commit comments