* 获取文件对应的解析器 * @param filePath 文件路径 * @returns 匹配的解析器,如果无法识别则返回 null
(filePath: string)
| 104 | * @returns 匹配的解析器,如果无法识别则返回 null |
| 105 | */ |
| 106 | getParser(filePath: string): Parser | null { |
| 107 | const ext = getExtension(filePath) |
| 108 | const headContent = readFileHead(filePath) |
| 109 | |
| 110 | for (const { feature, parser } of this.formats) { |
| 111 | if (this.matchFeature(feature, ext, headContent, filePath)) { |
| 112 | return parser |
| 113 | } |
| 114 | } |
| 115 | |
| 116 | return null |
| 117 | } |
| 118 | |
| 119 | /** |
| 120 | * 嗅探所有匹配的格式(按优先级排序) |
no test coverage detected