Source: selector/methods/NoNumbersIdSelector.js

(function() {
    /** @augments Help4.selector.methods.BaseSelector */
    Help4.selector.methods.NoNumbersIdSelector = class extends Help4.selector.methods.BaseSelector {
        /** @type {Object} */
        static CONFIG = {
            block: [
                /\d/,
                /^u[0-9A-F]{3}.*/   // uAFE, uBCF-itms, etc.
            ],
            except: [
                /^help4ui5$/
            ],
            idAttributes: [
                'id',
                'aria-controls'
            ]
        }

        /**
         * @param {HTMLElement} element
         * @return {?Help4.selector.methods.Selector}
         */
        static getSelector(element) {
            const {CONFIG: {idAttributes}} = this;
            const nodeName = element.nodeName.toUpperCase();
            const attributes = [...idAttributes];
            if (nodeName === 'LABEL') attributes.push('for');

            for (const attributeName of attributes) {
                const attributeValue = element.getAttribute(attributeName);
                const selector = _attributeToSelector.call(this, nodeName, attributeName, attributeValue);
                if (selector) return selector;
            }
            return null;
        }
    }

    /**
     * @memberof Help4.selector.methods.NoNumbersIdSelector
     * @private
     * @param {string} nodeName
     * @param {string} attributeName
     * @param {string} attributeValue
     * @returns {?Help4.selector.methods.Selector}
     */
    function _attributeToSelector(nodeName, attributeName, attributeValue) {
        if (!attributeValue || typeof attributeValue !== 'string') return null;

        const {methods, SELECTOR_QUALITY: {good: quality}} = Help4.selector;
        const {CONFIG: {block, except}} = this;

        const rxVal = rx => rx.test(attributeValue);
        if (!except.some(rxVal) && block.some(rxVal)) return null;

        attributeValue = methods.$E(attributeValue);
        const value = attributeName === 'id'
            ? `${nodeName}#${attributeValue}`
            : `${nodeName}[${attributeName}="${attributeValue}"]`;

        return methods.$(value).length === 1
            ? {value, quality}
            : null;
    }
})();