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