Sha256: 1a904cadf40e007f204e8901dbba633cd78364bff259653abad309400e3507d9

Contents?: true

Size: 1.48 KB

Versions: 260

Compression:

Stored size: 1.48 KB

Contents

/* global matches */
const matchers = ['nodeName', 'attributes', 'properties', 'condition'];

/**
 * Check if a virtual node matches some definition
 *
 * Note: matches.fromDefinition(vNode, definition) can be indirectly used through
 * matches(vNode, definition)
 *
 * Example:
 * ```js
 * matches.fromDefinition(vNode, {
 *   nodeName: ['div', 'span']
 *   attributes: {
 *     'aria-live': 'assertive'
 *   }
 * })
 * ```
 *
 * @deprecated HTMLElement is deprecated, use VirtualNode instead
 *
 * @private
 * @param {HTMLElement|VirtualNode} vNode
 * @param {Object|Array<Object>} definition
 * @returns {Boolean}
 */
matches.fromDefinition = function matchFromDefinition(vNode, definition) {
	if (!(vNode instanceof axe.AbstractVirtualNode)) {
		vNode = axe.utils.getNodeFromTree(vNode);
	}

	if (Array.isArray(definition)) {
		return definition.some(definitionItem => matches(vNode, definitionItem));
	}
	if (typeof definition === 'string') {
		return axe.utils.matches(vNode, definition);
	}

	return Object.keys(definition).every(matcherName => {
		if (!matchers.includes(matcherName)) {
			throw new Error(`Unknown matcher type "${matcherName}"`);
		}
		// Find the specific matches method to.
		// matches.attributes, matches.nodeName, matches.properties, etc.
		const matchMethod = matches[matcherName];

		// Find the matcher that goes into the matches method.
		// 'div', /^div$/, (str) => str === 'div', etc.
		const matcher = definition[matcherName];
		return matchMethod(vNode, matcher);
	});
};

Version data entries

260 entries across 260 versions & 1 rubygems

Version Path
govuk_publishing_components-30.4.1 node_modules/axe-core/lib/commons/matches/from-definition.js
govuk_publishing_components-30.4.0 node_modules/axe-core/lib/commons/matches/from-definition.js
govuk_publishing_components-30.3.0 node_modules/axe-core/lib/commons/matches/from-definition.js
govuk_publishing_components-30.2.1 node_modules/axe-core/lib/commons/matches/from-definition.js
govuk_publishing_components-30.2.0 node_modules/axe-core/lib/commons/matches/from-definition.js
govuk_publishing_components-30.1.0 node_modules/axe-core/lib/commons/matches/from-definition.js
govuk_publishing_components-30.0.0 node_modules/axe-core/lib/commons/matches/from-definition.js
govuk_publishing_components-29.15.3 node_modules/axe-core/lib/commons/matches/from-definition.js
govuk_publishing_components-29.15.2 node_modules/axe-core/lib/commons/matches/from-definition.js
govuk_publishing_components-29.15.1 node_modules/axe-core/lib/commons/matches/from-definition.js
govuk_publishing_components-29.15.0 node_modules/axe-core/lib/commons/matches/from-definition.js
govuk_publishing_components-29.14.0 node_modules/axe-core/lib/commons/matches/from-definition.js
govuk_publishing_components-29.13.0 node_modules/axe-core/lib/commons/matches/from-definition.js
govuk_publishing_components-29.12.1 node_modules/axe-core/lib/commons/matches/from-definition.js
govuk_publishing_components-29.12.0 node_modules/axe-core/lib/commons/matches/from-definition.js
govuk_publishing_components-29.11.0 node_modules/axe-core/lib/commons/matches/from-definition.js
govuk_publishing_components-29.10.0 node_modules/axe-core/lib/commons/matches/from-definition.js
govuk_publishing_components-29.9.0 node_modules/axe-core/lib/commons/matches/from-definition.js
govuk_publishing_components-29.8.0 node_modules/axe-core/lib/commons/matches/from-definition.js
govuk_publishing_components-29.7.0 node_modules/axe-core/lib/commons/matches/from-definition.js