How to use the @hint/utils-string.normalizeString function in @hint/utils-string

To help you get started, we’ve selected a few @hint/utils-string examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github webhintio / hint / packages / hint-sri / src / hint.ts View on Github external
}

        const nodeName = normalizeString(element.nodeName);

        /*
         * The element is not one that we care about (could be an img,
         * video, etc.). No need to report anything, but we can stop
         * processing things right away.
         */

        if (nodeName === 'script') {
            return Promise.resolve(!!element.getAttribute('src'));
        }

        if (nodeName === 'link') {
            const relValues = (normalizeString(element.getAttribute('rel'), ''))!.split(' '); // normalizeString won't return null as a default was passed.

            return Promise.resolve(relValues.includes('stylesheet'));
        }

        return Promise.resolve(false);
    }
github webhintio / hint / packages / hint-sri / src / hint.ts View on Github external
private isScriptOrLink(evt: FetchEnd): Promise {
        debug('Is 
github webhintio / hint / packages / utils-create-server / src / same-thread-server.ts View on Github external
/*
         * Matching is done only based on headers, as for the time
         * beeing there is no need to match based on other things.
         */

        if (!headers) {
            return 0;
        }

        let numberOfMatches = 0;

        for (const [header, value] of Object.entries(headers)) {
            // TODO: handle `string[]` in `req.headers`
            const headerValue = normalizeHeaderValue(req.headers as any, header);

            if ((headerValue !== normalizeString(value as string)) || (!headerValue && (value === null))) {
                return 0;
            }

            numberOfMatches++;
        }

        return numberOfMatches;
    }
github webhintio / hint / packages / hint-meta-viewport / src / hint.ts View on Github external
resource,
                    getMessage('metaElementInBody', context.language),
                    {
                        element: viewportMetaElement,
                        severity: Severity.error
                    }
                );
            }

            // - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

            /*
             * Check if the meta element was specified with the proper value.
             */

            const contentValue = normalizeString(viewportMetaElement.getAttribute('content'));

            checkContentValue(contentValue, resource, viewportMetaElement);

            // - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

            /*
             * All other viewport meta elements should not be included.
             */

            if (viewportMetaElements.length > 1) {
                const metaElements = viewportMetaElements.slice(1);

                for (const metaElement of metaElements) {
                    context.report(
                        resource,
                        getMessage('metaElementDuplicated', context.language),
github webhintio / hint / packages / hint-meta-charset-utf-8 / src / hint.ts View on Github external
*/

            const charsetMetaElement = charsetMetaElements[0];

            // * ``

            if (charsetMetaElement.getAttribute('http-equiv') !== null) {
                context.report(
                    resource,
                    getMessage('metaElementShorter', context.language),
                    {
                        element: charsetMetaElement,
                        severity: Severity.warning
                    });
            } else {
                const metaValue = normalizeString(charsetMetaElement.getAttribute('charset'));

                if (metaValue !== 'utf-8') {

                    const severity = metaValue === 'utf8' ?
                        Severity.warning :
                        Severity.error;

                    context.report(
                        resource,
                        getMessage('metaElementWrongValue', context.language, charsetMetaElement.getAttribute('charset')!),
                        {
                            element: charsetMetaElement,
                            severity
                        });
                }
            }
github webhintio / hint / packages / hint-content-type / src / hint.ts View on Github external
if (contentTypeHeaderValue === '') {
                    throw new TypeError(getMessage('invalidMediaType', context.language));
                }

                contentType = parse(contentTypeHeaderValue);
            } catch (e) {
                context.report(
                    resource,
                    getMessage('contentTypeValueInvalid', context.language, e.message),
                    { codeLanguage, codeSnippet, severity }
                );

                return;
            }

            const originalCharset: string | null = normalizeString(contentType.parameters ? contentType.parameters.charset : '');
            const originalMediaType: string = contentType.type;

            /*
             * Determined values
             *
             * Notes:
             *
             *  * The connectors already did all the heavy lifting here.
             *  * For the charset, recommend `utf-8` for all text based
             *    bases documents.
             */

            const mediaType: string = response.mediaType;
            const charset: string = isTextMediaType(mediaType) ? 'utf-8' : response.charset;

            /*
github webhintio / hint / packages / parser-css / src / parser.ts View on Github external
private isCSSType(element: HTMLElement) {
        const type = normalizeString(element.getAttribute('type'));

        /*
         * From: https://html.spec.whatwg.org/multipage/semantics.html#update-a-style-block
         *
         * If element's type attribute is present and its value is neither
         * the empty string nor an ASCII case-insensitive match for
         * "text/css", then return.
         */
        return !type || type === 'text/css';
    }
github webhintio / hint / packages / hint-apple-touch-icons / src / hint.ts View on Github external
return;
            }

            /*
             * Choose the icon that will most likely
             * pass most of the following tests.
             */

            const appleTouchIcon: HTMLElement = chooseBestIcon(appleTouchIcons);

            /*
             * Check if `rel='apple-touch-icon'`.
             * See `getAppleTouchIcons` function for more details.
             */

            if (normalizeString(appleTouchIcon.getAttribute('rel')) !== 'apple-touch-icon') {
                const message = getMessage('wrongRelAttribute', context.language);

                context.report(
                    resource,
                    message,
                    { element: appleTouchIcon, severity: Severity.warning }
                );
            }

            /*
             * Since we are recommending one icon, the `sizes` attribute
             * is not needed. Also, pre-4.2 versions of iOS ignore the
             * `sizes` attribute.
             *
             * https://mathiasbynens.be/notes/touch-icons
             * https://html.spec.whatwg.org/multipage/semantics.html#attr-link-sizes
github webhintio / hint / packages / parser-sass / src / parser.ts View on Github external
engine.on('element::style', async ({ element, resource }) => {
            const lang = normalizeString(element.getAttribute('lang'));

            if (lang === 'sass') {
                await emitSASS(element.innerHTML, sassParser, resource, element);
            } else if (lang === 'scss') {
                await emitSASS(element.innerHTML, scssParser, resource, element);
            }
        });
    }