Sha256: 49d56ba8d06da0c27a7c2f22a8672593d8654ce7bba7dbf043034e91e5b9b64e

Contents?: true

Size: 1.2 KB

Versions: 104

Compression:

Stored size: 1.2 KB

Contents

const { text } = axe.commons;

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

const visibleText = text
	.sanitize(text.visibleVirtual(virtualNode))
	.toLowerCase();
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

104 entries across 104 versions & 1 rubygems

Version Path
govuk_publishing_components-21.16.3 node_modules/axe-core/lib/checks/label/label-content-name-mismatch.js
govuk_publishing_components-21.16.2 node_modules/axe-core/lib/checks/label/label-content-name-mismatch.js
govuk_publishing_components-21.16.1 node_modules/axe-core/lib/checks/label/label-content-name-mismatch.js
govuk_publishing_components-21.16.0 node_modules/axe-core/lib/checks/label/label-content-name-mismatch.js
govuk_publishing_components-21.15.2 node_modules/axe-core/lib/checks/label/label-content-name-mismatch.js
govuk_publishing_components-21.15.1 node_modules/axe-core/lib/checks/label/label-content-name-mismatch.js
govuk_publishing_components-21.15.0 node_modules/axe-core/lib/checks/label/label-content-name-mismatch.js
govuk_publishing_components-21.14.0 node_modules/axe-core/lib/checks/label/label-content-name-mismatch.js
govuk_publishing_components-21.13.5 node_modules/axe-core/lib/checks/label/label-content-name-mismatch.js
govuk_publishing_components-21.13.4 node_modules/axe-core/lib/checks/label/label-content-name-mismatch.js
govuk_publishing_components-21.13.3 node_modules/axe-core/lib/checks/label/label-content-name-mismatch.js
govuk_publishing_components-21.13.2 node_modules/axe-core/lib/checks/label/label-content-name-mismatch.js
govuk_publishing_components-21.13.1 node_modules/axe-core/lib/checks/label/label-content-name-mismatch.js
govuk_publishing_components-21.13.0 node_modules/axe-core/lib/checks/label/label-content-name-mismatch.js
govuk_publishing_components-21.12.0 node_modules/axe-core/lib/checks/label/label-content-name-mismatch.js
govuk_publishing_components-21.11.0 node_modules/axe-core/lib/checks/label/label-content-name-mismatch.js
govuk_publishing_components-21.10.0 node_modules/axe-core/lib/checks/label/label-content-name-mismatch.js
govuk_publishing_components-21.9.0 node_modules/axe-core/lib/checks/label/label-content-name-mismatch.js
govuk_publishing_components-21.8.1 node_modules/axe-core/lib/checks/label/label-content-name-mismatch.js
govuk_publishing_components-21.8.0 node_modules/axe-core/lib/checks/label/label-content-name-mismatch.js