Skip to content
This repository was archived by the owner on Aug 9, 2023. It is now read-only.

Add support for false, falsey boolean props #16

Merged
merged 1 commit into from
Apr 23, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -140,17 +140,19 @@ function toH(h, node, ctx) {
}

function addAttribute(props, prop, value, ctx) {
var hyperlike = ctx.hyperscript || ctx.vdom
var schema = ctx.schema
var info = find(schema, prop)
var subprop

// Ignore nully, `false`, `NaN`, and falsey known booleans.
// Ignore nully and `NaN` values.
// Ignore `false` and falsey known booleans for hyperlike DSLs.
if (
value === null ||
value === undefined ||
value === false ||
value !== value ||
(info.boolean && !value)
(hyperlike && value === false) ||
(hyperlike && info.boolean && !value)
) {
return
}
Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,8 @@
"rules": {
"unicorn/prefer-type-error": "off",
"guard-for-in": "off",
"no-self-compare": "off"
"no-self-compare": "off",
"complexity": "off"
}
},
"remarkConfig": {
Expand Down
4 changes: 4 additions & 0 deletions test.js
Original file line number Diff line number Diff line change
Expand Up @@ -275,6 +275,8 @@ test('hast-to-hyperscript', function(t) {
{
key: 'h-3',
style: {color: 'red'},
ignored: false,
disabled: 0,
foo: 'bar',
camelCase: 'on off',
'data-123': '456',
Expand Down Expand Up @@ -341,6 +343,8 @@ test('hast-to-hyperscript', function(t) {
{
key: 'h-3',
style: {color: 'red'},
ignored: false,
disabled: 0,
foo: 'bar',
camelCase: 'on off',
'data-123': '456',
Expand Down