(cp: number)
| 113 | * @returns The corresponding encoding name as a string, or null if no mapping exists. |
| 114 | */ |
| 115 | export function windowsCodePageToEncoding(cp: number): string | null { |
| 116 | // Most common mappings; extend as needed |
| 117 | const map: { [key: number]: string } = { |
| 118 | 437: 'cp437', |
| 119 | 850: 'cp850', |
| 120 | 852: 'cp852', |
| 121 | 866: 'cp866', |
| 122 | 874: 'windows-874', |
| 123 | 932: 'shift_jis', |
| 124 | 936: 'gb2312', |
| 125 | 949: 'euc-kr', |
| 126 | 950: 'big5', |
| 127 | 1200: 'utf-16le', |
| 128 | 1201: 'utf-16be', |
| 129 | 1250: 'windows-1250', |
| 130 | 1251: 'windows-1251', |
| 131 | 1252: 'windows-1252', |
| 132 | 1253: 'windows-1253', |
| 133 | 1254: 'windows-1254', |
| 134 | 1255: 'windows-1255', |
| 135 | 1256: 'windows-1256', |
| 136 | 1257: 'windows-1257', |
| 137 | 1258: 'windows-1258', |
| 138 | 65001: 'utf-8', |
| 139 | }; |
| 140 | |
| 141 | if (map[cp]) { |
| 142 | return map[cp]; |
| 143 | } |
| 144 | |
| 145 | console.warn(`Unable to determine encoding for windows code page ${cp}.`); |
| 146 | return null; // Return null if no mapping found |
| 147 | } |
| 148 | |
| 149 | /** |
| 150 | * Attempts to detect encoding from a buffer using chardet. |
no outgoing calls
no test coverage detected