UNPKG

luhn-generator

Version:

A generator of numbers that passes the validation of Luhn algorithm or Luhn formula, also known as the 'modulus 10' or 'mod 10' algorithm

40 lines (34 loc) 1.15 kB
import getRole from './get-role'; import standards from '../../standards'; import { getNodeFromTree } from '../../core/utils'; import AbstractVirtuaNode from '../../core/base/virtual-node/abstract-virtual-node'; /** * Check if an element is named from contents * * @param {Node|VirtualNode} element * @param {Object} options * @property {Bool} strict Whether or not to follow the spects strictly * @return {Bool} */ function namedFromContents(vNode, { strict } = {}) { vNode = vNode instanceof AbstractVirtuaNode ? vNode : getNodeFromTree(vNode); if (vNode.props.nodeType !== 1) { return false; } const role = getRole(vNode); const roleDef = standards.ariaRoles[role]; if (roleDef && roleDef.nameFromContent) { return true; } /** * Note: Strictly speaking if the role is null, presentation, or none, the element * isn't named from contents. Axe-core often needs to know if an element * has content anyway, so we're allowing it here. * Use { strict: true } to disable this behavior. */ if (strict) { return false; } return !roleDef || ['presentation', 'none'].includes(role); } export default namedFromContents;