Skip to main content

getLanguageFromFile()

function getLanguageFromFile(file, file_length?):
| "css"
| "markdown"
| "python"
| "text"
| "typescript"
| "json"
| "javascript"
| "xml"
| "jxml"
| "html"
| "yaml"
| "handlebars";

Given a path or filename return a language based on the file extension. Optionally accepts a file_length parameter (1 char = 2 bytes) which, if too large, will result in 'text' being returned regardless of language

Parameters

ParameterType
filestring
file_length?number

Returns

| "css" | "markdown" | "python" | "text" | "typescript" | "json" | "javascript" | "xml" | "jxml" | "html" | "yaml" | "handlebars"