@keymanapp/common-types
Version:
Keyman Developer keyboard file types
151 lines (149 loc) • 5.46 kB
JavaScript
/**
* Registered source file types for Keyman. Some of these file types (e.g. .xml)
* may have multiple uses outside Keyman.
*/
!function(){try{var e="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:{},n=(new Error).stack;n&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[n]="9f5d78b4-3ab9-52a8-9fb8-3471f402a7d2")}catch(e){}}();
export var Source;
(function (Source) {
Source["Model"] = ".model.ts";
Source["Project"] = ".kpj";
Source["KeymanKeyboard"] = ".kmn";
Source["LdmlKeyboard"] = ".xml";
Source["Package"] = ".kps";
Source["VisualKeyboard"] = ".kvks";
Source["TouchLayout"] = ".keyman-touch-layout";
})(Source || (Source = {}));
;
/**
* List of all registered source file types for Keyman. Some of these file types
* (e.g. .xml) may have multiple uses outside Keyman.
*/
export const ALL_SOURCE = [
".model.ts" /* Source.Model */,
".kpj" /* Source.Project */,
".kmn" /* Source.KeymanKeyboard */,
".xml" /* Source.LdmlKeyboard */,
".kps" /* Source.Package */,
".kvks" /* Source.VisualKeyboard */,
".keyman-touch-layout" /* Source.TouchLayout */
];
/**
* Registered binary file types for Keyman. Some of these file types (e.g. .js)
* may have multiple uses outside Keyman.
*/
export var Binary;
(function (Binary) {
Binary["Model"] = ".model.js";
Binary["WebKeyboard"] = ".js";
Binary["Keyboard"] = ".kmx";
Binary["Package"] = ".kmp";
Binary["VisualKeyboard"] = ".kvk";
Binary["KeyboardInfo"] = ".keyboard_info";
Binary["ModelInfo"] = ".model_info";
})(Binary || (Binary = {}));
/**
* List of all registered binary file types for Keyman. Some of these file types
* (e.g. .js) may have multiple uses outside Keyman.
*/
export const ALL_BINARY = [
".model.js" /* Binary.Model */,
".js" /* Binary.WebKeyboard */,
".kmx" /* Binary.Keyboard */,
".kmp" /* Binary.Package */,
".kvk" /* Binary.VisualKeyboard */,
".keyboard_info" /* Binary.KeyboardInfo */,
".model_info" /* Binary.ModelInfo */,
];
export const ALL = [...ALL_SOURCE, ...ALL_BINARY];
/**
* Standard project file name - history of project in Markdown format
*/
export const HISTORY_MD = 'HISTORY.md';
/**
* Standard project file name - README in Markdown format
*/
export const README_MD = 'README.md';
/**
* Standard project file name - LICENSE in Markdown format
*/
export const LICENSE_MD = 'LICENSE.md';
/**
* Gets the file type based on extension, dealing with multi-part file
* extensions. Does not sniff contents of file or assume file existence. Does
* transform upper-cased file extensions to lower-case.
* @param filename
* @returns file extension, or `""` if no extension. Note that this return value
* differs from the other, more-specific fromFilename functions below,
* which return `null` if a supported extension is not found.
*/
export function fromFilename(filename) {
const result = sourceOrBinaryTypeFromFilename(filename) ??
filename.match(/\.[^\.]+$/)?.[0] ??
"";
return result;
}
/**
* Removes the file extension, include known .model.* patterns, from a filename
* @param filename
* @returns
*/
export function removeExtension(filename) {
const ext = fromFilename(filename);
return filename.substring(0, filename.length - ext.length);
}
/**
* Gets the file type based on extension, dealing with multi-part file
* extensions. Does not sniff contents of file or assume file existence.
* Does transform upper-cased file extensions to lower-case.
* @param filename
* @returns file type, or `null` if not found
*/
export function sourceOrBinaryTypeFromFilename(filename) {
filename = filename.toLowerCase();
const result = ALL_SOURCE.find(type => filename.endsWith(type)) ??
ALL_BINARY.find(type => filename.endsWith(type)) ??
null;
return result;
}
/**
* Gets the source file type based on extension, dealing with multi-part file
* extensions. Does not sniff contents of file or assume file existence. Does
* transform upper-cased file extensions to lower-case.
* @param filename
* @returns file type, or `null` if not found
*/
export function sourceTypeFromFilename(filename) {
filename = filename.toLowerCase();
const result = ALL_SOURCE.find(type => filename.endsWith(type)) ??
null;
return result;
}
/**
* Gets the binary file type based on extension, dealing with multi-part file
* extensions. Does not sniff contents of file or assume file existence. Does
* transform upper-cased file extensions to lower-case.
* @param filename
* @returns file type, or `null` if not found
*/
export function binaryTypeFromFilename(filename) {
filename = filename.toLowerCase();
const result = ALL_BINARY.find(type => filename.endsWith(type)) ??
null;
return result;
}
/**
* Returns true if filenmae has a specific file extension. Does transform
* upper-cased file extensions to lower-case.
* @param filename
* @param fileType
* @returns true if file is of type fileType
*/
export function filenameIs(filename, fileType) {
// Special case for .model.js
if (fileType == ".js" /* Binary.WebKeyboard */ && filenameIs(filename, ".model.js" /* Binary.Model */)) {
return false;
}
return filename.toLowerCase().endsWith(fileType);
}
//# sourceMappingURL=file-types.js.map
//# debugId=9f5d78b4-3ab9-52a8-9fb8-3471f402a7d2