UNPKG

cspell

Version:

A Spelling Checker for Code!

26 lines 916 B
import assert from 'node:assert'; import Path from 'node:path'; import { pathToFileURL } from 'node:url'; import { STDINProtocol } from './constants.js'; export function isStdinUrl(url) { if (url instanceof URL) { return url.protocol === STDINProtocol; } return url.startsWith(STDINProtocol); } /** * Normalize and resolve a stdin url. * @param url - stdin url to resolve. * @param cwd - file path to resolve relative paths against. * @returns */ export function resolveStdinUrl(url, cwd) { assert(url.startsWith(STDINProtocol), `Expected url to start with ${STDINProtocol}`); const path = url .slice(STDINProtocol.length) .replace(/^\/\//, '') .replace(/^\/([a-z]:)/i, '$1'); const fileUrl = pathToFileURL(Path.resolve(cwd, path)); return fileUrl.toString().replace(/^file:/, STDINProtocol) + (path ? '' : '/'); } //# sourceMappingURL=stdinUrl.js.map