How to use the @hint/utils-fs.pathExists 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-network / src / as-uri.ts View on Github external
if (isFile(source) || isDirectory(source)) {
        target = new URL(fileUrl(source));
        debug(`Adding valid target: ${url.format(target)}`);

        return target;
    }

    target = new URL(`http://${source}`);

    /*
     * And it doesn't exist locally, and is a valid URL:
     * Except for the case of the well known and used `localhost`,
     * for all other cases the `hostname` needs to contain at least
     * a `.`. Private domains should have `http(s)://` in front.
     */
    if (!pathExists(source) && (target.hostname === 'localhost' || target.hostname.includes('.'))) {
        debug(`Adding modified target: ${url.format(target)}`);

        return target;
    }

    // If it's not a regular file or looks like a URL, ignore it.
    logger.error(`Ignoring '${source}' as it's not an existing file nor a valid URL`);

    return null;
};