Skip to content

Commit

Permalink
Add 'empty' style option for !!null
Browse files Browse the repository at this point in the history
fix #570
  • Loading branch information
rlidwka committed Dec 10, 2020
1 parent db3f529 commit 421ed22
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 1 deletion.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Expand Up @@ -25,6 +25,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Added `.mjs` (es modules) support.
- Added `quotingType` and `forceQuotes` options for dumper to configure
string literal style, #290, #529.
- Added `styles: { '!!null': 'empty' }` option for dumper
(serializes `{ foo: null }` as "`foo: `"), #570.

### Fixed
- Astral characters are no longer encoded by dump/safeDump, #587.
Expand Down
3 changes: 2 additions & 1 deletion lib/type/null.js
Expand Up @@ -28,7 +28,8 @@ module.exports = new Type('tag:yaml.org,2002:null', {
canonical: function () { return '~'; },
lowercase: function () { return 'null'; },
uppercase: function () { return 'NULL'; },
camelcase: function () { return 'Null'; }
camelcase: function () { return 'Null'; },
empty: function () { return ''; }
},
defaultStyle: 'lowercase'
});
24 changes: 24 additions & 0 deletions test/issues/0570.js
@@ -0,0 +1,24 @@
'use strict';


const assert = require('assert');
const yaml = require('../../');


it('should dump null in different styles', function () {
let dump, src = { foo: null, bar: 1 };

let tests = {
lowercase: 'null',
uppercase: 'NULL',
camelcase: 'Null',
canonical: '~',
empty: ''
};

for (let [ name, value ] of Object.entries(tests)) {
dump = yaml.dump(src, { styles: { '!!null': name } });
assert.strictEqual(dump, 'foo: ' + value + '\nbar: 1\n');
assert.deepStrictEqual(yaml.load(dump), src);
}
});

0 comments on commit 421ed22

Please sign in to comment.