在使用 js-yaml 包导出 YAML 文件时,如果你想去除 >- 这样的折叠块标记,可以通过设置 lineWidth 选项来解决。lineWidth 选项用于指定输出的每行文本的最大宽度。
```javascript
const yaml = require('js-yaml');
const fs = require('fs');
const data = {
key1: 'value1',
key2: 'value2'
};
// 设置 lineWidth 选项为 -1,表示不限制每行的宽度
const yamlString = yaml.dump(data, { lineWidth: -1 });
// 将 YAML 字符串写入文件
fs.writeFile('output.yaml', yamlString, 'utf8', (err) => {
if (err) {
console.error('Error writing file:', err);
return;
}
console.log('YAML file has been saved successfully.');
});