25 lines
691 B
JavaScript
25 lines
691 B
JavaScript
import { promisify } from 'util'
|
|
import { readFile as readF, writeFile as writeF } from 'fs'
|
|
const readFile = promisify(readF)
|
|
const writeFile = promisify(writeF)
|
|
import { stringify as toToml } from '@iarna/toml'
|
|
import parse from 'xdg-parse'
|
|
|
|
async function read (file) {
|
|
return readFile(file).then( buf => {
|
|
try { return parse(buf.toString()) }
|
|
catch(error) { return error }
|
|
})}
|
|
|
|
function stringify(obj) {
|
|
try { return toToml(obj).replace(/["]/gi,'').replace(/\ = /gi,'=') }
|
|
catch(error) { return error }
|
|
}
|
|
|
|
async function write(file,obj) {
|
|
return writeFile(file,stringify(obj))
|
|
}
|
|
|
|
export default { read, write, stringify, parse }
|
|
export {read, write, stringify, parse }
|