Security News
Weekly Downloads Now Available in npm Package Search Results
Socket's package search now displays weekly downloads for npm packages, helping developers quickly assess popularity and make more informed decisions.
Map file extensions to languages using GitHub Linguist data (Always up to date)
Omni-file is a comprehensive file information extractor that provides language, icon, type, and MIME information for any file based on its name or extension. With over 1000 icons, support for more than 700 programming languages, and only 79.4 kB gzipped, it's both powerful and lightweight!
It leverages GitHub Linguist data and Material Icon Theme for up-to-date and accurate file type detection and icons. The data is regularly updated to ensure the latest language and icon information.
Install omni-file from npm:
npm install omni-file
pnpm add omni-file
yarn add omni-file
Core functions:
getLanguage(filename: string): Language
getIcon(filename: string, options?: IconOptions): string
Utility functions:
getBaseFilenameFromRelativePath(filePath: string): string
getExtensionsFromRelativePath(filePath: string): string[]
Type definitions:
LanguageData
: Detailed information about a programming language
LanguageWithIconsData
: Extends LanguageData
with icon information
IconOptions
: Options for icon retrieval (isFolder, isExpanded, isLight)
LanguagesJSON
: A record of language names to LanguageData
objects
LanguagesWithIconsJSON
: A record of language names to LanguageWithIconsData
objects
ExtensionMapJSON
: Maps file extensions to language names
FileNamesMapJSON
: Maps specific filenames to language names
IconsJSON
: Defines icon associations for files and folders
Raw data:
languages
: A map of all languages with iconsextensionMap
: Maps file extensions to language namesfileNamesMap
: Maps specific filenames to language namesicons
: Default icon set (dark theme)iconsLight
: Light theme icon set (has less icons then dark theme)import { getLanguage } from "omni-file";
console.log(getLanguage("folder/example.ts"));
Output:
{
"type": "programming",
"color": "#3178c6",
"aliases": ["ts"],
"interpreters": ["deno", "ts-node", "tsx"],
"extensions": [".ts", ".cts", ".mts"],
"tm_scope": "source.ts",
"ace_mode": "typescript",
"codemirror_mode": "javascript",
"codemirror_mime_type": "application/typescript",
"language_id": 378,
"name": "TypeScript",
"icons": ["typescript", "javascript"]
}
Note that you can also get icons from
getLanguage
by usinggetLanguage(filename)?.icons
but the answer may be less accurate. (folder icons are not included this way)
import { getIcon } from "omni-file";
console.log(getIcon("example.js")); // Output: 'javascript'
console.log(getIcon("styles.css")); // Output: 'css'
console.log(getIcon("data.json")); // Output: 'json'
console.log(getIcon("package.json")); // Output: 'nodejs'
console.log(getIcon("Dockerfile")); // Output: 'docker'
console.log(getIcon(".gitignore")); // Output: 'git'
console.log(getIcon("src", { isFolder: true })); // Output: 'folder-src'
console.log(getIcon("node_modules", { isFolder: true })); // Output: 'folder-node'
console.log(getIcon("tests", { isFolder: true, isExpanded: true })); // Output: 'folder-test-open'
console.log(getIcon("vercel.json", { isLight: true })); // Output: 'vercel_light'
console.log(getIcon("example.js", { isLight: true })); // Output: 'javascript_light'
console.log(getIcon("example.test.js")); // Output: 'test-js'
console.log(getIcon("component.spec.ts")); // Output: 'test-ts'
console.log(getIcon(path.join("src", "components", "Button.tsx"))); // Output: 'react_ts'
console.log(getIcon(path.join("tests", "unit", "utils.test.js"))); // Output: 'test-js'
console.log(getIcon(".eslintrc.json")); // Output: 'eslint'
console.log(getIcon(".prettierrc")); // Output: 'prettier'
console.log(getIcon("tsconfig.json")); // Output: 'tsconfig'
console.log(getIcon("README.md")); // Output: 'readme'
console.log(getIcon("readme.md")); // Output: 'readme'
console.log(getIcon("DockerFile")); // Output: 'docker'
console.log(getIcon("dockerfile")); // Output: 'docker'
import { getIcon } from "omni-file";
const icon = getIcon("folder/example.ts"); // "typescript"
const svgUrl = `node_modules/omni-file/icons/${icon}.svg`;
<img src={svgUrl} alt={icon} />;
Output:
import { languages, icons } from "omni-file";
console.log(languages["JavaScript"].extensions); // -> [ ".js",".cjs",".es",".jsm", ... ]
console.log(icons.fileExtensions["js"]); // -> "javascript"
Omni-file provides two icon sets:
You can switch between these themes based on your application's needs:
import { getIcon, IconTheme } from "omni-file";
const darkIcon = getIcon("example.ts", { isLight: false });
const lightIcon = getIcon("example.ts", { isLight: true });
To set up the project for development:
pnpm install
pnpm run update-data
pnpm run build
pnpm test
build
: Builds the project using tsupbuild:watch
: Watches for changes and rebuildstest
: Runs the test suitetest:coverage
: Runs tests with coverage reportingupdate-data
: Updates the Linguist datapostinstall
: Automatically updates data after installationContributions are welcome! Please feel free to submit a Pull Request.
git checkout -b feature/AmazingFeature
)git commit -m 'Add some AmazingFeature'
)git push origin feature/AmazingFeature
)This project is licensed under the MIT License - see the LICENSE file for details.
FAQs
You got a filename/foldername we got all its info: icon, category, type, extensions, mime type, color, and more...
The npm package omni-file receives a total of 160 weekly downloads. As such, omni-file popularity was classified as not popular.
We found that omni-file demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 0 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Socket's package search now displays weekly downloads for npm packages, helping developers quickly assess popularity and make more informed decisions.
Security News
A Stanford study reveals 9.5% of engineers contribute almost nothing, costing tech $90B annually, with remote work fueling the rise of "ghost engineers."
Research
Security News
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.