omni-file
Version:
You got a filename/foldername we got all its info: icon, category, type, extensions, mime type, color, and more...
220 lines (215 loc) • 8.39 kB
TypeScript
/**
* Represents a collection of language data, where each key is the LanguageData["name"] property
* (e.g., "JavaScript", "Python", "HTML") and the value is the corresponding LanguageData object.
*
* This structure allows for easy lookup and access to language-specific information
* based on the language name. The key is case-sensitive and matches the "name" field
* in the LanguageData object.
*
* @example
* const languagesJSON: LanguagesJSON = {
* "JavaScript": {
* language_id: 183,
* name: "JavaScript",
* type: "programming",
* tm_scope: "source.js",
* ace_mode: "javascript",
* color: "#f1e05a",
* extensions: [".js", ".mjs"],
* // ... other properties
* },
* "Python": {
* language_id: 303,
* name: "Python",
* type: "programming",
* tm_scope: "source.python",
* ace_mode: "python",
* color: "#3572A5",
* extensions: [".py", ".pyi"],
* // ... other properties
* },
* // ... other languages
* };
*/
type LanguagesJSON = Record<string, LanguageData>;
type LanguageData = {
/** A unique identifier for the language */
language_id: number;
/** The name of the language (e.g. "JavaScript", "Python", "HTML") */
name: string;
/** The classification of the language (e.g., "programming", "markup", "data") */
type: string;
/** The TextMate scope used for syntax highlighting */
tm_scope: string;
/** The mode used by the Ace editor for syntax highlighting (e.g. "text", "html", "javascript") */
ace_mode: string;
/** The color associated with the language (usually a hex code example: '#000000') */
color?: string;
/** File extensions associated with the language (always starts with a dot, e.g. ".js") */
extensions?: string[];
/** Specific filenames associated with the language */
filenames?: string[];
/** Interpreters used for the language */
interpreters?: string[];
/** Alternative names for the language */
aliases?: string[];
/** The mode used by CodeMirror for syntax highlighting */
codemirror_mode?: string;
/** The MIME type used by CodeMirror */
codemirror_mime_type?: string;
/** The group the language belongs to (if any) */
group?: string;
/** Whether the language should be wrapped (usually for prose languages) */
wrap?: boolean;
/** Whether the language is searchable */
searchable?: boolean;
};
type LanguageWithIconsData = LanguageData & {
icons?: string[];
};
type LanguagesWithIconsJSON = Record<string, LanguageWithIconsData>;
/**
* Represents a mapping of file extensions to language names (LanguageData["name"])
* The key has no leading dot.
*
* @example
* { "js": "JavaScript", "py": "Python" }
*/
type ExtensionMapJSON = Record<string, string>;
/**
* Represents a mapping of specific filenames to language names (LanguageData["name"])
*
* @example
* { "makefile": "Makefile", "Dockerfile": "Dockerfile" }
*/
type FileNamesMapJSON = Record<string, string>;
type IconsJSON = {
/** Default icon name for files */
file: string;
/** Default icon name for folders */
folder: string;
/** Default icon name for expanded folders */
folderExpanded: string;
/**
* Mapping of file extensions to icon names (no leading dot)
* @example { "js": "javascript", "py": "python" }
*/
fileExtensions: Record<string, string>;
/**
* Mapping of specific file names to icon names
* @example { "package.json": "nodejs", "dockerfile": "docker" }
*/
fileNames: Record<string, string>;
/**
* Mapping of folder names to icon names
* @example { "src": "folder-src", "test": "folder-test" }
*/
folderNames: Record<string, string>;
/**
* Mapping of expanded folder names to icon names
* @example { "node_modules": "folder-node-open", "dist": "folder-dist-open" }
*/
folderNamesExpanded: Record<string, string>;
/**
* Mapping of language IDs to icon names
* @example { "sql": "database", "plaintext": "document" }
*/
languageIds: Record<string, string>;
};
/**
* Represents a list of icon names
* @example ["nodejs", "python", "docker"]
*/
type IconListJSON = string[];
/**
* The default icon set for dark themes.
* This constant contains all the icon definitions for files, folders, and languages.
*/
declare const icons: IconsJSON;
/**
* The icon set for light themes.
* This constant contains all the icon definitions for files, folders, and languages optimized for light backgrounds.
*/
declare const iconsLight: IconsJSON;
/**
* Retrieves a list of all icon names based on the provided options.
*
* @param opts - Optional configuration object
* @param opts.isLight - If true, use light theme icons
* @param opts.isExpanded - If true, include expanded folder icons
* @param opts.isFolder - If true, include folder-related icons
* @returns An array of unique icon names
*/
declare function getIconList(opts?: {
isLight?: boolean;
isExpanded?: boolean;
isFolder?: boolean;
}): string[];
/**
* Retrieves the icon name associated with a given file path.
*
* This function takes a file path as input and returns a string
* representing the icon name for that file or folder.
*
* @param filePath - The path of the file or folder for which to retrieve the icon.
* @param isFolder - A boolean indicating whether the path represents a folder.
* @returns A string representing the icon name for the given file path or folder.
*/
declare function getIcon(filePath: string, opts?: {
isFolder?: boolean;
isLight?: boolean;
isExpanded?: boolean;
}): string;
/**
* A collection of language data, including icons, indexed by language name.
* This constant contains detailed information about various programming languages.
*/
declare const languages: LanguagesWithIconsJSON;
/**
* A mapping of file extensions to language names.
* This constant is used to determine the language of a file based on its extension.
*/
declare const extensionMap: ExtensionMapJSON;
/**
* A mapping of specific filenames to language names.
* This constant is used to determine the language of a file based on its exact filename.
*/
declare const fileNamesMap: FileNamesMapJSON;
/**
* Retrieves the language data associated with a given filename.
*
* This function first attempts to match the filename directly against known filenames
* in the language data. If no match is found, it falls back to matching by file extension,
* trying longer extensions before shorter ones.
*
* @param filename - The name of the file to look up (can be a relative path).
* @returns The LanguageWithIconsData object if a match is found, undefined otherwise.
*/
declare function getLanguage(filePath: string): LanguageWithIconsData | undefined;
/**
* Extracts the base filename from a relative path.
*
* This function takes a relative file path and returns only the filename
* without any preceding directory structure. It handles various edge cases
* such as empty strings, paths with no separators, and paths with trailing separators.
*
* @param filePath - The relative file path to process.
* @returns The base filename extracted from the path, or an empty string if the input is invalid.
*/
declare function getBaseFilenameFromRelativePath(filePath: string): string;
/**
* Extracts all possible extensions from a relative file path.
*
* This function takes a relative file path and returns an array of all possible
* extensions, starting from the longest to the shortest. It considers everything
* after the first dot in the filename as part of the extension.
*
* @param filePath - The relative file path to process.
* @returns An array of strings representing all possible extensions, or an empty array if there are no extensions.
*
* @example
* getExtensionsFromRelativePath("folder/file.conf.d.ts")
* // returns ["conf.d.ts", "d.ts", "ts"]
*/
declare function getExtensionsFromRelativePath(filePath: string): string[];
export { type ExtensionMapJSON, type FileNamesMapJSON, type IconListJSON, type IconsJSON, type LanguageData, type LanguageWithIconsData, type LanguagesJSON, type LanguagesWithIconsJSON, extensionMap, fileNamesMap, getBaseFilenameFromRelativePath, getExtensionsFromRelativePath, getIcon, getIconList, getLanguage, icons, iconsLight, languages };