| 1 | const BY_EXTENSION: Record<string, string> = { |
| 2 | ts: "TypeScript", |
| 3 | tsx: "TypeScript", |
| 4 | mts: "TypeScript", |
| 5 | cts: "TypeScript", |
| 6 | js: "JavaScript", |
| 7 | jsx: "JavaScript", |
| 8 | mjs: "JavaScript", |
| 9 | cjs: "JavaScript", |
| 10 | py: "Python", |
| 11 | rb: "Ruby", |
| 12 | go: "Go", |
| 13 | rs: "Rust", |
| 14 | java: "Java", |
| 15 | kt: "Kotlin", |
| 16 | kts: "Kotlin", |
| 17 | swift: "Swift", |
| 18 | c: "C", |
| 19 | h: "C", |
| 20 | cc: "C++", |
| 21 | cpp: "C++", |
| 22 | cxx: "C++", |
| 23 | hpp: "C++", |
| 24 | hh: "C++", |
| 25 | cs: "C#", |
| 26 | php: "PHP", |
| 27 | scala: "Scala", |
| 28 | clj: "Clojure", |
| 29 | ex: "Elixir", |
| 30 | exs: "Elixir", |
| 31 | erl: "Erlang", |
| 32 | hs: "Haskell", |
| 33 | lua: "Lua", |
| 34 | pl: "Perl", |
| 35 | r: "R", |
| 36 | dart: "Dart", |
| 37 | zig: "Zig", |
| 38 | sql: "SQL", |
| 39 | sh: "Shell", |
| 40 | bash: "Shell", |
| 41 | zsh: "Shell", |
| 42 | fish: "Shell", |
| 43 | ps1: "PowerShell", |
| 44 | html: "HTML", |
| 45 | htm: "HTML", |
| 46 | css: "CSS", |
| 47 | scss: "SCSS", |
| 48 | sass: "SCSS", |
| 49 | less: "Less", |
| 50 | vue: "Vue", |
| 51 | svelte: "Svelte", |
| 52 | astro: "Astro", |
| 53 | md: "Markdown", |
| 54 | mdx: "MDX", |
| 55 | json: "JSON", |
| 56 | yml: "YAML", |
| 57 | yaml: "YAML", |
| 58 | toml: "TOML", |
| 59 | xml: "XML", |
| 60 | proto: "Protocol Buffer", |
| 61 | graphql: "GraphQL", |
| 62 | gql: "GraphQL", |
| 63 | tf: "HCL", |
| 64 | hcl: "HCL", |
| 65 | nix: "Nix", |
| 66 | vim: "Vim Script", |
| 67 | ipynb: "Jupyter Notebook", |
| 68 | }; |
| 69 | |
| 70 | const BY_FILENAME: Record |
| 71 | dockerfile: "Dockerfile", |
| 72 | makefile: "Makefile", |
| 73 | "cmakelists.txt": "CMake", |
| 74 | rakefile: "Ruby", |
| 75 | gemfile: "Ruby", |
| 76 | justfile: "Just", |
| 77 | }; |
| 78 | |
| 79 | export type LanguageType |
| 80 | |
| 81 | /** Linguist's type and aliases for every language above (lib/linguist/languages.yml). */ |
| 82 | const LANGUAGES: Record |
| 83 | TypeScript: { type: " |
| 84 | JavaScript: { type: " |
| 85 | Python: { type: " |
| 86 | Ruby: { |
| 87 | type: "programming", |
| 88 | aliases: ["jruby", |
| 89 | }, |
| 90 | Go: { type: " |
| 91 | Rust: { type: " |
| 92 | Java: { type: " |
| 93 | Kotlin: { type: " |
| 94 | Swift: { type: " |
| 95 | C: { type: " |
| 96 | "C++": { type: |
| 97 | "C#": { type: |
| 98 | PHP: { type: " |
| 99 | Scala: { type: " |
| 100 | Clojure: { type: " |
| 101 | Elixir: { type: " |
| 102 | Erlang: { type: " |
| 103 | Haskell: { type: " |
| 104 | Lua: { type: " |
| 105 | Perl: { type: " |
| 106 | R: { type: " |
| 107 | Dart: { type: " |
| 108 | Zig: { type: " |
| 109 | SQL: { type: " |
| 110 | Shell: { |
| 111 | type: "programming", |
| 112 | aliases: ["sh", |
| 113 | }, |
| 114 | PowerShell: { type: " |
| 115 | HTML: { type: " |
| 116 | CSS: { type: " |
| 117 | SCSS: { type: " |
| 118 | Less: { type: " |
| 119 | Vue: { type: " |
| 120 | Svelte: { type: " |
| 121 | Astro: { type: " |
| 122 | Markdown: { type: " |
| 123 | MDX: { type: " |
| 124 | JSON: { type: " |
| 125 | YAML: { type: " |
| 126 | TOML: { type: " |
| 127 | XML: { type: " |
| 128 | "Protocol Buffer": { |
| 129 | type: "data", |
| 130 | aliases: ["proto", |
| 131 | }, |
| 132 | GraphQL: { type: " |
| 133 | HCL: { |
| 134 | type: "programming", |
| 135 | aliases: ["hashicorp configuration language", |
| 136 | }, |
| 137 | Nix: { type: " |
| 138 | "Vim Script": { |
| 139 | type: "programming", |
| 140 | aliases: ["vim", |
| 141 | }, |
| 142 | "Jupyter Notebook": { type: |
| 143 | Dockerfile: { type: " |
| 144 | Makefile: { type: " |
| 145 | CMake: { type: " |
| 146 | Just: { type: " |
| 147 | }; |
| 148 | |
| 149 | const BY_ALIAS = new |
| 150 | for (const [name |
| 151 | BY_ALIAS.set(name |
| 152 | BY_ALIAS.set(name |
| 153 | for (const alias |
| 154 | } |
| 155 | |
| 156 | export function languageType(language |
| 157 | return LANGUAGES[language |
| 158 | } |
| 159 | |
| 160 | /** A language by its name or one of its aliases, ignoring case, as `linguist-language` names it. */ |
| 161 | export function languageForAlias(alias |
| 162 | return BY_ALIAS.get |
| 163 | } |
| 164 | |
| 165 | export function languageForPath(path |
| 166 | const filename = |
| 167 | |
| 168 | const named = |
| 169 | if (named) return |
| 170 | |
| 171 | const dot = |
| 172 | if (dot <= |
| 173 | |
| 174 | return BY_EXTENSION[filename |
| 175 | } |