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

Commit

Permalink
Add support for false, falsey boolean props
Browse files Browse the repository at this point in the history
Closes GH-14.
Closes GH-16.

Reviewed-by: Christian Murphy <christian.murphy.42@gmail.com>
  • Loading branch information
wooorm authored Apr 23, 2019
1 parent 75849d1 commit b5daafe
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 4 deletions.
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

0 comments on commit b5daafe

Please sign in to comment.