How to use the @hint/utils.isTextMediaType function in @hint/utils

To help you get started, we’ve selected a few @hint/utils 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 / connector-local / src / connector.ts View on Github external
* target can have one of these forms:
         *   - /path/to/file
         *   - C:/path/to/file
         *   - file:///path/to/file
         *   - file:///C:/path/to/file
         *
         * That's why we need to parse it to an URL
         * and then get the path string.
         */
        const uri = getAsUri(target);
        const filePath: string = uri ? asPathString(uri).replace('%20', ' ') : '';
        const rawContent: Buffer = options && options.content ? Buffer.from(options.content) : await readFileAsBuffer(filePath);
        const contentType = getContentTypeData(null as any, filePath, null, rawContent);
        let content = '';

        if (isTextMediaType(contentType.mediaType || '')) {
            content = rawContent.toString(contentType.charset || undefined);
        }

        // Need to do some magic to create a fetch::end::*
        return {
            request: {} as any,
            response: {
                body: {
                    content,
                    rawContent,
                    rawResponse() {
                        /* istanbul ignore next */
                        return Promise.resolve(rawContent);
                    }
                },
                charset: contentType.charset || /* istanbul ignore next */ '',
github webhintio / hint / packages / hint-http-compression / src / hint.ts View on Github external
'font/otf',
                'font/sfnt',
                'font/ttf',
                'image/bmp',
                'image/x-icon',
                'x-shader/x-fragment',
                'x-shader/x-vertex'
            ];

            /*
             * Check if the media type is one of the common
             * ones for which it is known the response should
             * be compressed.
             */

            if (isTextMediaType(mediaType) ||
                OTHER_COMMON_MEDIA_TYPES_THAT_SHOULD_BE_COMPRESSED.includes(mediaType)) {
                return true;
            }

            return false;
        };