url#fileURLToPath TypeScript Examples
The following examples show how to use
url#fileURLToPath.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: util.ts From yarn-audit-fix with MIT License | 6 votes |
__dirname = dirname(fileURLToPath(import.meta.url))
Example #2
Source File: loader.ts From tsm with MIT License | 6 votes |
load: Load = async function (uri, context, fallback) {
// note: inline `getFormat`
let options = await toOptions(uri);
if (options == null) return fallback(uri, context, fallback);
let format: Format = options.format === 'cjs' ? 'commonjs' : 'module';
// TODO: decode SAB/U8 correctly
let path = fileURLToPath(uri);
let source = await fs.readFile(path);
// note: inline `transformSource`
esbuild = esbuild || await import('esbuild');
let result = await esbuild.transform(source.toString(), {
...options,
sourcefile: path,
format: format === 'module' ? 'esm' : 'cjs',
});
return { format, source: result.code };
}
Example #3
Source File: InputPanel.ts From discord-qt with GNU General Public License v3.0 | 6 votes |
private handleDrag(e?: any) {
const ev = new QDragMoveEvent(e as NativeElement);
try {
const mimeData = ev.mimeData();
if (mimeData.hasUrls()) {
const url = new URL(mimeData.text());
if (url.protocol !== 'file:') {
return;
}
this.attachments.addFiles([fileURLToPath(url.href)]);
}
ev.accept();
} catch (ex) {}
}
Example #4
Source File: index.ts From discord-qt with GNU General Public License v3.0 | 6 votes |
async function handleRequest(url: string) {
const uri = new URL(url);
const roundify = uri.searchParams.get('roundify') === 'true';
const path = join(paths.cache, `.${uri.pathname}${roundify ? '.round' : ''}`);
if (uri.hostname === 'cdn.discordapp.com') {
if (existsSync(path)) {
return path;
}
}
await mkdir(dirname(path), { recursive: true });
let buffer = await (uri.protocol === 'file:' ? readFile(fileURLToPath(url)) : httpsGet(url));
if (buffer && buffer.length) {
buffer = await processPng(buffer, roundify);
await writeFile(path, buffer as Buffer);
return path;
}
return null;
}
Example #5
Source File: index.ts From graphene with MIT License | 6 votes |
server = polka({ onError: errorHandler, onNoMatch: notFoundHandler })
.use(
helmet() as Middleware,
sirv(resolve(dirname(fileURLToPath(import.meta.url)), "./views"), {
dev: process.env.NODE_ENV !== "production",
etag: true,
maxAge: 60 * 60 * 24
})
)
.get("/")
.options("/api", cors)
.post("/api", cors, rateLimiter, bodyParser, coreHandler)
Example #6
Source File: params.ts From bls with Apache License 2.0 | 5 votes |
__dirname = path.dirname(fileURLToPath(import.meta.url))
Example #7
Source File: index.ts From bls with Apache License 2.0 | 5 votes |
__dirname = path.dirname(fileURLToPath(import.meta.url))
Example #8
Source File: index.ts From Nukecord with MIT License | 5 votes |
__filename = fileURLToPath(import.meta.url)
Example #9
Source File: docs.ts From WebCord with MIT License | 5 votes |
function handleUrls(container:HTMLElement, article:HTMLElement, header:HTMLElement, mdPrevious: string):void {
for(const link of container.getElementsByTagName('a')){
link.onclick = () => {
window.history.replaceState("", "", pathToFileURL(mdPrevious))
// Handle links with the whitelisted protocols
if(new URL(link.href).protocol.match(trustedProtocolRegExp)) {
open(link.href)
// Handle in-document links
} else if (link.href.startsWith(document.URL.replace(/#.*/, '')+'#')) {
const id = getId(link.href);
if (id) {
const element = document.getElementById(id)
if(element) element.scrollIntoView({behavior: "smooth"});
}
// Handle markdown links and 'LICENSE' files.
} else if(link.href.match(/^file:\/\/.+(\.md|LICENSE)(#[a-z0-9-]+)?$/)) {
const mdFile = fileURLToPath(link.href);
const id = getId(link.href);
const oldHeader = menuHeader.innerHTML
menuHeader.innerText = basename(mdFile);
document.body.removeChild(article);
if(existsSync(mdFile)){
loadMarkdown(container,mdFile);
mdPrevious = mdFile;
} else {
// Fix for HTML links ('<a>' elements) that are unhandled by marked.
const relFile = relative(document.URL, link.href);
const mdFile = resolve(mdPrevious, relFile);
if(!existsSync(mdFile)) {
// Failsafe: revert all changes done so far...
console.error("File '"+mdFile+"' does not exists!");
document.body.appendChild(article);
window.history.pushState("", "", htmlFileUrl);
menuHeader.innerHTML = oldHeader;
return false;
}
loadMarkdown(container,mdFile);
mdPrevious = mdFile;
console.log(relFile);
}
window.scroll(0,0);
handleUrls(container, article, header, mdPrevious);
fixImages(container);
document.body.appendChild(article);
if (id) {
const element = document.getElementById(id);
if (element) element.scrollIntoView();
}
}
window.history.pushState("", "", htmlFileUrl)
return false;
}
}
}
Example #10
Source File: bin.ts From spork with MIT License | 5 votes |
PACKAGE_JSON_PATH = path.join(path.dirname(fileURLToPath(import.meta.url)), '..', 'package.json')
Example #11
Source File: internal.ts From reskript with MIT License | 5 votes |
resolveSync = (id: string) => {
const callerUrl = caller();
const callerPath = callerUrl.startsWith('file://') ? fileURLToPath(callerUrl) : callerUrl;
return resolveCore.sync(id, {basedir: callerPath});
}
Example #12
Source File: index.ts From icepkg with MIT License | 5 votes |
__dirname = path.dirname(fileURLToPath(import.meta.url))
Example #13
Source File: cli.ts From icepkg with MIT License | 5 votes |
__dirname = dirname(fileURLToPath(import.meta.url))
Example #14
Source File: loader.ts From tsm with MIT License | 5 votes |
function check(fileurl: string): string | void {
let tmp = fileURLToPath(fileurl);
if (existsSync(tmp)) return fileurl;
}
Example #15
Source File: cli.ts From baidupcs-batch-upload with MIT License | 5 votes |
__filename = fileURLToPath(import.meta.url)
Example #16
Source File: index.ts From nota with MIT License | 5 votes |
__filename = fileURLToPath(import.meta.url)