Allow for `jsyaml.dump` options in `dumpBlock`

Introduce the capability to customize `jsyaml.dump` options in the `dumpBlock` function, allowing developers to supply all of the dump options specified by `jsyaml.dump()`.

Signed-off-by: Phillip Rak <rak.phillip@gmail.com>
This commit is contained in:
Phillip Rak 2023-12-12 10:42:21 -07:00
parent 209a471473
commit 01c043099e
2 changed files with 11 additions and 9 deletions

View File

@ -40,7 +40,8 @@ export default {
return {
data: Object.keys(this.data).reduce((acc, key) => ({
...acc,
[key]: { chomping: '+' },
lineWidth: -1,
[key]: { chomping: '+' },
}), {}),
};
},

View File

@ -443,20 +443,21 @@ export function saferDump(obj) {
*
* this is required since jsyaml.dump doesn't support chomping and scalar style at the moment.
* see: https://github.com/nodeca/js-yaml/issues/171
* @typedef {Object} DumpBlockOptions
* @property {('>' | '|')} [scalarStyle] - The scalar style.
* @property {('-' | '+' | '' | null)} [chomping] - The chomping style.
*
* @param {*} data the multiline block
* @param {*} options blocks indicators, see: https://yaml-multiline.info
* @param {Object} options - Serialization options for jsyaml.dump.
* @param {number} options.lineWidth - Set max line width. Set -1 for unlimited width.
* @param {DumpBlockOptions} [options.dynamicProperties] - Options for dynamic properties.
* Developers can provide their own property names under `options`.
*
* - scalarStyle:
* one of '|', '>'
* default '|'
* - chomping:
* one of: null, '', '-', '+'
* default: null
* @returns the result of jsyaml.dump with the addition of multiline indicators
*/
export function dumpBlock(data, options = {}) {
const parsed = jsyaml.dump(data);
const parsed = jsyaml.dump(data, options);
let out = parsed;