How to use the @hint/utils-fs.fileName function in @hint/utils-fs

To help you get started, we’ve selected a few @hint/utils-fs 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 / utils / src / content-type.ts View on Github external
const determineMediaTypeBasedOnFileName = (resource: string, rawContent: Buffer): string | null => {
    const fileName = getFileName(resource);

    if (!fileName) {
        return null;
    }

    const configFileNameRegex = /^\.[a-z0-9]+rc$/i;

    if (!configFileNameRegex.test(fileName)) {
        return null;
    }

    try {
        // Determine if this is a json file.
        JSON.parse(rawContent.toString());
    } catch (err) {
        return 'text/plain';