smartfile/ts/smartfile.interpreter.ts

21 lines
593 B
TypeScript
Raw Normal View History

2022-06-07 13:43:28 +00:00
import * as plugins from './smartfile.plugins.js';
2016-09-20 15:56:49 +00:00
export let filetype = (pathArg: string): string => {
2019-09-27 09:00:17 +00:00
const extName = plugins.path.extname(pathArg);
const fileType = extName.replace(/\.([a-z]*)/, '$1'); // remove . form fileType
return fileType;
};
2016-06-23 16:31:55 +00:00
2016-09-20 15:56:49 +00:00
export let objectFile = (fileStringArg: string, fileTypeArg) => {
switch (fileTypeArg) {
case 'yml':
case 'yaml':
2021-04-07 09:48:54 +00:00
return plugins.yaml.load(fileStringArg);
case 'json':
return JSON.parse(fileStringArg);
default:
console.error('file type ' + fileTypeArg.blue + ' not supported');
break;
}
};