Skip to content

Commit

Permalink
Filter undefined, null, and false results from dataset object
Browse files Browse the repository at this point in the history
  • Loading branch information
Ricky Miller committed Jul 27, 2021
1 parent f3e3599 commit ad7034e
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 4 deletions.
8 changes: 7 additions & 1 deletion cjs/utils.js
Expand Up @@ -77,7 +77,13 @@ const parse = (template, expectedLength, svg) => {
case name[0] === '.':
const lower = name.slice(1).toLowerCase();
updates.push(lower === 'dataset' ?
(value => (pre + keys(value).map(data, value).join(''))) :
(value => (
pre
+ keys(value)
.filter(key => value[key] != null)
.map(data, value)
.join('')
)) :
(value => {
let result = pre;
// null, undefined, and false are not shown at all
Expand Down
2 changes: 1 addition & 1 deletion es.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 7 additions & 1 deletion esm/utils.js
Expand Up @@ -75,7 +75,13 @@ export const parse = (template, expectedLength, svg) => {
case name[0] === '.':
const lower = name.slice(1).toLowerCase();
updates.push(lower === 'dataset' ?
(value => (pre + keys(value).map(data, value).join(''))) :
(value => (
pre
+ keys(value)
.filter(key => value[key] != null)
.map(data, value)
.join('')
)) :
(value => {
let result = pre;
// null, undefined, and false are not shown at all
Expand Down
8 changes: 7 additions & 1 deletion index.js
Expand Up @@ -178,7 +178,13 @@ self.uhtml = (function (exports) {
case name[0] === '.':
const lower = name.slice(1).toLowerCase();
updates.push(lower === 'dataset' ?
(value => (pre + keys(value).map(data, value).join(''))) :
(value => (
pre
+ keys(value)
.filter(key => value[key] != null)
.map(data, value)
.join('')
)) :
(value => {
let result = pre;
// null, undefined, and false are not shown at all
Expand Down
5 changes: 5 additions & 0 deletions test/index.js
Expand Up @@ -94,6 +94,11 @@ assert(
`<this data-any="value">is a html test</this>`
);

assert(
render(String, html`<this .dataset=${{any: 'value', other: undefined}}>is a html test</this>`),
`<this data-any="value">is a html test</this>`
);

assert(
render(String, html`<this ?hidden=${1}>is a html test</this>`),
`<this hidden>is a html test</this>`
Expand Down

0 comments on commit ad7034e

Please sign in to comment.