Sha256: 800f43fc2f95d90e56541591e4929a3b48b1d107d58a154d9c28620ff1dbf686

Contents?: true

Size: 1.52 KB

Versions: 271

Compression:

Stored size: 1.52 KB

Contents

const { text } = axe.commons;
const { pixelThreshold, occuranceThreshold } = options || {};

const accText = text.accessibleText(node).toLowerCase();
if (text.isHumanInterpretable(accText) < 1) {
	return undefined;
}

const textVNodes = text.visibleTextNodes(virtualNode);
const nonLigatureText = textVNodes
	.filter(
		textVNode =>
			!text.isIconLigature(textVNode, pixelThreshold, occuranceThreshold)
	)
	.map(textVNode => textVNode.actualNode.nodeValue)
	.join('');
const visibleText = text.sanitize(nonLigatureText).toLowerCase();
if (!visibleText) {
	return true;
}
if (text.isHumanInterpretable(visibleText) < 1) {
	if (isStringContained(visibleText, accText)) {
		return true;
	}
	return undefined;
}

return isStringContained(visibleText, accText);

/**
 * Check if a given text exists in another
 *
 * @param {String} compare given text to check
 * @param {String} compareWith text against which to be compared
 * @returns {Boolean}
 */
function isStringContained(compare, compareWith) {
	const curatedCompareWith = curateString(compareWith);
	const curatedCompare = curateString(compare);
	if (!curatedCompareWith || !curatedCompare) {
		return false;
	}
	return curatedCompareWith.includes(curatedCompare);
}

/**
 * Curate given text, by removing emoji's, punctuations, unicode and trim whitespace.
 *
 * @param {String} str given text to curate
 * @returns {String}
 */
function curateString(str) {
	const noUnicodeStr = text.removeUnicode(str, {
		emoji: true,
		nonBmp: true,
		punctuations: true
	});
	return text.sanitize(noUnicodeStr);
}

Version data entries

271 entries across 271 versions & 1 rubygems

Version Path
govuk_publishing_components-27.9.1 node_modules/axe-core/lib/checks/label/label-content-name-mismatch.js
govuk_publishing_components-27.9.0 node_modules/axe-core/lib/checks/label/label-content-name-mismatch.js
govuk_publishing_components-27.8.2 node_modules/axe-core/lib/checks/label/label-content-name-mismatch.js
govuk_publishing_components-27.8.1 node_modules/axe-core/lib/checks/label/label-content-name-mismatch.js
govuk_publishing_components-27.8.0 node_modules/axe-core/lib/checks/label/label-content-name-mismatch.js
govuk_publishing_components-27.7.0 node_modules/axe-core/lib/checks/label/label-content-name-mismatch.js
govuk_publishing_components-27.6.0 node_modules/axe-core/lib/checks/label/label-content-name-mismatch.js
govuk_publishing_components-27.5.0 node_modules/axe-core/lib/checks/label/label-content-name-mismatch.js
govuk_publishing_components-27.4.0 node_modules/axe-core/lib/checks/label/label-content-name-mismatch.js
govuk_publishing_components-27.3.1 node_modules/axe-core/lib/checks/label/label-content-name-mismatch.js
govuk_publishing_components-27.3.0 node_modules/axe-core/lib/checks/label/label-content-name-mismatch.js
govuk_publishing_components-27.2.0 node_modules/axe-core/lib/checks/label/label-content-name-mismatch.js
govuk_publishing_components-27.1.0 node_modules/axe-core/lib/checks/label/label-content-name-mismatch.js
govuk_publishing_components-27.0.0 node_modules/axe-core/lib/checks/label/label-content-name-mismatch.js
govuk_publishing_components-26.0.0 node_modules/axe-core/lib/checks/label/label-content-name-mismatch.js
govuk_publishing_components-25.7.0 node_modules/axe-core/lib/checks/label/label-content-name-mismatch.js
govuk_publishing_components-25.6.0 node_modules/axe-core/lib/checks/label/label-content-name-mismatch.js
govuk_publishing_components-25.5.0 node_modules/axe-core/lib/checks/label/label-content-name-mismatch.js
govuk_publishing_components-25.4.0 node_modules/axe-core/lib/checks/label/label-content-name-mismatch.js
govuk_publishing_components-25.3.1 node_modules/axe-core/lib/checks/label/label-content-name-mismatch.js