Skip to content

Commit

Permalink
feat: add custom color settings to VSCode configuration and improve c…
Browse files Browse the repository at this point in the history
…omments in fetchBlock and parser files
  • Loading branch information
jupegarnica committed Nov 7, 2024
1 parent a4caf6d commit 568d664
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 29 deletions.
25 changes: 24 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,27 @@
{
"deno.enable": true,
"deno.unstable": true
"deno.unstable": true,
"workbench.colorCustomizations": {
"activityBar.activeBackground": "#a98bf1",
"activityBar.background": "#a98bf1",
"activityBar.foreground": "#15202b",
"activityBar.inactiveForeground": "#15202b99",
"activityBarBadge.background": "#f8d5c6",
"activityBarBadge.foreground": "#15202b",
"commandCenter.border": "#e7e7e799",
"editorGroup.border": "#a98bf1",
"sash.hoverBorder": "#a98bf1",
"statusBar.background": "#875dec",
"statusBar.debuggingBackground": "#c2ec5d",
"statusBar.debuggingForeground": "#15202b",
"statusBar.foreground": "#e7e7e7",
"statusBarItem.hoverBackground": "#a98bf1",
"statusBarItem.remoteBackground": "#875dec",
"statusBarItem.remoteForeground": "#e7e7e7",
"titleBar.activeBackground": "#875dec",
"titleBar.activeForeground": "#e7e7e7",
"titleBar.inactiveBackground": "#875dec99",
"titleBar.inactiveForeground": "#e7e7e799"
},
"peacock.color": "#875dec"
}
2 changes: 1 addition & 1 deletion src/fetchBlock.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ export async function fetchBlock(block: Block): Promise<Block> {
} catch (_error) {
const error = _error as Error;
if (error.name === "AbortError") {
// @ts-expect-error
// @ts-ignore - it works
throw new error.constructor(
`Timeout of ${block.meta.timeout}ms exceeded`
);
Expand Down
48 changes: 21 additions & 27 deletions src/parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,15 @@ import { _Request, _Response, httpMethods } from "./types.ts";
import * as eta from "npm:eta@1.14.2";
import { extract } from "jsr:@std/front-matter@0.224.0/yaml";



async function renderTemplate(template: string, data: Record<string, unknown>) {
const result = await eta.render(
template,
data,
{
async: true,
useWith: true,
rmWhitespace: false,
autoTrim: false,
// TODO: add custom tags??
// tags: ["{{", "}}"]
},
);
const result = await eta.render(template, data, {
async: true,
useWith: true,
rmWhitespace: false,
autoTrim: false,
// TODO: add custom tags??
// tags: ["{{", "}}"]
});
return result;
}

Expand All @@ -40,12 +34,12 @@ export async function parseBlockText(block: Block): Promise<Block> {
const findFrontMatterTextRegex = /^---\s*([\s\S]*?)\s*---\s*/gm;
export async function parseMetaFromText(
textRaw = "",
dataToInterpolate = {},
dataToInterpolate = {}
): Promise<Meta> {
const meta: Meta = {};
const frontMatterTextRaw = textRaw.match(findFrontMatterTextRegex)?.[0] || "";
const text = await renderTemplate(frontMatterTextRaw, dataToInterpolate) ||
"";
const text =
(await renderTemplate(frontMatterTextRaw, dataToInterpolate)) || "";
const frontMatterText = text.match(findFrontMatterTextRegex)?.[0] || "";

if (frontMatterText) {
Expand All @@ -61,7 +55,7 @@ function splitLines(text: string): string[] {

export async function parseRequestFromText(
block: Block,
dataToInterpolate = {},
dataToInterpolate = {}
): Promise<_Request | undefined> {
const textRaw = block.text.replace(findFrontMatterTextRegex, "");

Expand All @@ -71,16 +65,16 @@ export async function parseRequestFromText(
const requestStartLine = 0;
let requestEndLine = linesRaw.findIndex(
isResponseStartLine,
requestStartLine,
requestStartLine
);

if (requestEndLine === -1) requestEndLine = linesRaw.length;

const requestText = linesRaw.slice(requestStartLine, requestEndLine).join(
"\n",
);
const requestText = linesRaw
.slice(requestStartLine, requestEndLine)
.join("\n");

const text = await renderTemplate(requestText, dataToInterpolate) || "";
const text = (await renderTemplate(requestText, dataToInterpolate)) || "";

const requestStartLineIndex = linesRaw.findIndex(isRequestStartLine);
if (requestStartLineIndex === -1) {
Expand Down Expand Up @@ -141,7 +135,7 @@ export async function parseRequestFromText(
requestInit.body = (requestInit.body || "") + "\n" + line;
}
}
requestInit.body = (requestInit.body as string || "").trim();
requestInit.body = ((requestInit.body as string) || "").trim();
if (requestInit.body === "") {
requestInit.body = null;
}
Expand All @@ -164,7 +158,7 @@ export async function parseRequestFromText(
try {
url = new URL(url).toString();
} catch (error) {
// @ts-expect-error
// @ts-ignore - it works
throw new error.constructor(`Invalid URL: ${url} -> ${error.message}`);
}

Expand All @@ -175,7 +169,7 @@ export async function parseRequestFromText(

export async function parseResponseFromText(
textRaw = "",
dataToInterpolate = {},
dataToInterpolate = {}
): Promise<_Response | undefined> {
const linesRaw: string[] = splitLines(textRaw);
const responseInit: ResponseInit = {};
Expand All @@ -186,7 +180,7 @@ export async function parseResponseFromText(
if (statusLine === -1) return;

const responseText = linesRaw.slice(statusLine).join("\n");
const text = await renderTemplate(responseText, dataToInterpolate) || "";
const text = (await renderTemplate(responseText, dataToInterpolate)) || "";
const lines = splitLines(text);

let lookingFor = "status";
Expand Down

0 comments on commit 568d664

Please sign in to comment.