Sha256: face0fc7bc6f71bc76cdeafb76be025fab3d723ade12f83d6cfc4b6552138141

Contents?: true

Size: 1.33 KB

Versions: 115

Compression:

Stored size: 1.33 KB

Contents

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

/**
 * Check if a node matches some definition
 *
 * Note: matches.fromDefinition(node, definition) can be indirectly used through
 * matches(node, definition)
 *
 * Example:
 * ```js
 * matches.fromDefinition(node, {
 *   nodeName: ['div', 'span']
 *   attributes: {
 *     'aria-live': 'assertive'
 *   }
 * })
 * ```
 *
 * @private
 * @param {HTMLElement|VirtualNode} node
 * @param {Object|Array<Object>} definition
 * @returns {Boolean}
 */
matches.fromDefinition = function matchFromDefinition(node, definition) {
	node = node.actualNode || node;
	if (Array.isArray(definition)) {
		return definition.some(definitionItem => matches(node, definitionItem));
	}
	if (typeof definition === 'string') {
		return axe.utils.matchesSelector(node, 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(node, matcher);
	});
};

Version data entries

115 entries across 115 versions & 1 rubygems

Version Path
govuk_publishing_components-21.22.1 node_modules/axe-core/lib/commons/matches/from-definition.js
govuk_publishing_components-21.22.0 node_modules/axe-core/lib/commons/matches/from-definition.js
govuk_publishing_components-21.21.3 node_modules/axe-core/lib/commons/matches/from-definition.js
govuk_publishing_components-21.21.2 node_modules/axe-core/lib/commons/matches/from-definition.js
govuk_publishing_components-21.21.1 node_modules/axe-core/lib/commons/matches/from-definition.js
govuk_publishing_components-21.21.0 node_modules/axe-core/lib/commons/matches/from-definition.js
govuk_publishing_components-21.20.0 node_modules/axe-core/lib/commons/matches/from-definition.js
govuk_publishing_components-21.19.1 node_modules/axe-core/lib/commons/matches/from-definition.js
govuk_publishing_components-21.19.0 node_modules/axe-core/lib/commons/matches/from-definition.js
govuk_publishing_components-21.18.0 node_modules/axe-core/lib/commons/matches/from-definition.js
govuk_publishing_components-21.17.0 node_modules/axe-core/lib/commons/matches/from-definition.js
govuk_publishing_components-21.16.3 node_modules/axe-core/lib/commons/matches/from-definition.js
govuk_publishing_components-21.16.2 node_modules/axe-core/lib/commons/matches/from-definition.js
govuk_publishing_components-21.16.1 node_modules/axe-core/lib/commons/matches/from-definition.js
govuk_publishing_components-21.16.0 node_modules/axe-core/lib/commons/matches/from-definition.js
govuk_publishing_components-21.15.2 node_modules/axe-core/lib/commons/matches/from-definition.js
govuk_publishing_components-21.15.1 node_modules/axe-core/lib/commons/matches/from-definition.js
govuk_publishing_components-21.15.0 node_modules/axe-core/lib/commons/matches/from-definition.js
govuk_publishing_components-21.14.0 node_modules/axe-core/lib/commons/matches/from-definition.js
govuk_publishing_components-21.13.5 node_modules/axe-core/lib/commons/matches/from-definition.js