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.
Example with language:
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"]
}
Example with icon:
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:
It leverages GitHub Linguist data to ensure up-to-date and accurate file type detection and uses Material Icon Theme for icons.
Install omni-file using npm:
npm install omni-file
Or if you prefer using pnpm:
pnpm add omni-file
Here's a basic example of how to use omni-file:
import { getFileInfo } from "omni-file";
const fileInfo = getFileInfo("example.js");
console.log(fileInfo);
This will output an object containing comprehensive information about the file, including its language, icon, type, and MIME type.
getFileInfo(filename: string): FileInfo
Returns an object with the following properties:
language
: The programming language associated with the fileicon
: The icon name for the file typetype
: The general type of the file (e.g., 'programming', 'markup', 'data')mime
: The MIME type of the fileTo 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.