2016-09-20 15:56:49 +00:00
|
|
|
import 'typings-global'
|
2016-03-20 16:36:38 +00:00
|
|
|
|
2016-09-20 15:56:49 +00:00
|
|
|
import plugins = require('./smartfile.plugins')
|
2016-03-20 16:36:38 +00:00
|
|
|
|
2016-09-20 15:56:49 +00:00
|
|
|
export let filetype = (pathArg: string): string => {
|
|
|
|
let extName = plugins.path.extname(pathArg)
|
|
|
|
let 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) => {
|
2016-03-20 16:36:38 +00:00
|
|
|
switch (fileTypeArg) {
|
2016-09-20 15:56:49 +00:00
|
|
|
case 'yml' :
|
|
|
|
case 'yaml':
|
|
|
|
return plugins.yaml.safeLoad(fileStringArg)
|
|
|
|
case 'json':
|
|
|
|
return JSON.parse(fileStringArg)
|
2016-03-20 16:36:38 +00:00
|
|
|
default:
|
2017-01-21 11:11:22 +00:00
|
|
|
console.error('file type ' + fileTypeArg.blue + ' not supported')
|
2016-09-20 15:56:49 +00:00
|
|
|
break
|
2016-03-20 16:36:38 +00:00
|
|
|
}
|
2016-09-20 15:56:49 +00:00
|
|
|
}
|