Skip to content

Commit

Permalink
Parser: Clarify toBooleanAttributeMatcher documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
aduth committed Jun 28, 2018
1 parent 9114974 commit de1c2ea
Showing 1 changed file with 15 additions and 2 deletions.
17 changes: 15 additions & 2 deletions blocks/api/parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,27 @@ import { attr, prop, html, text, query, node, children } from './matchers';
* or false depending on whether the original matcher returns undefined. This
* is useful for boolean attributes (e.g. disabled) whose attribute values may
* be technically falsey (empty string), though their mere presence should be
* enough to infer as a truthy value.
* enough to infer as true.
*
* @param {Function} matcher Original hpq matcher.
*
* @return {Function} Enhanced hpq matcher.``
* @return {Function} Enhanced hpq matcher.
*/
export const toBooleanAttributeMatcher = ( matcher ) => flow( [
matcher,
// Expected values from `attr( 'disabled' )`:
//
// <input>
// - Value: `undefined`
// - Transformed: `false`
//
// <input disabled>
// - Value: `''`
// - Transformed: `true`
//
// <input disabled="disabled">
// - Value: `'disabled'`
// - Transformed: `true`
( value ) => value !== undefined,
] );

Expand Down

0 comments on commit de1c2ea

Please sign in to comment.