Skip to content

Commit

Permalink
Omit undefined and null attributes (#4)
Browse files Browse the repository at this point in the history
  • Loading branch information
mattlucock authored Mar 30, 2023
1 parent b1d8af0 commit bf53295
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 1 deletion.
2 changes: 1 addition & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ export default function stringifyAttributes(attributes) {
const handledAttributes = [];

for (let [key, value] of Object.entries(attributes)) {
if (value === false) {
if (value === false || value === undefined || value === null) {
continue;
}

Expand Down
2 changes: 2 additions & 0 deletions test.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ test('stringifies attributes', t => {
'b',
],
alt: '',
undef: undefined,
null: null,
}),
' unicorn="🦄" rainbow number="1" multiple="a b" alt=""',
);
Expand Down

0 comments on commit bf53295

Please sign in to comment.