@rapidrabbit/gitdb
Version:
A powerful, flexible database module for storing data in various formats with local file and GitHub storage options
67 lines (57 loc) • 1.09 kB
JavaScript
/**
* YAMLFormat - Handles YAML data format
*/
class YAMLFormat {
constructor (options = {}) {
this.yaml = null
}
/**
* Initialize YAML format
*/
async initialize () {
try {
this.yaml = require('js-yaml')
} catch (error) {
throw new Error('YAML parsing requires js-yaml package')
}
}
/**
* Parse YAML data
*/
parse (data) {
if (!this.yaml) {
throw new Error('YAML format not initialized')
}
try {
return this.yaml.load(data)
} catch (error) {
throw new Error(`Failed to parse YAML: ${error.message}`)
}
}
/**
* Serialize data to YAML
*/
serialize (data) {
if (!this.yaml) {
throw new Error('YAML format not initialized')
}
try {
return this.yaml.dump(data)
} catch (error) {
throw new Error(`Failed to serialize YAML: ${error.message}`)
}
}
/**
* Get empty data structure
*/
getEmptyStructure () {
return {}
}
/**
* Get format configuration
*/
getConfig () {
return {}
}
}
module.exports = YAMLFormat