From bdfdb44743af2f120f4e6622562068932a076230 Mon Sep 17 00:00:00 2001 From: isaiM6 <98564922+isaiM6@users.noreply.github.com> Date: Mon, 1 Aug 2022 14:42:48 -0700 Subject: [PATCH] forced commit --- packages/hoppscotch-data/src/pathVariables.ts | 76 ------------------- 1 file changed, 76 deletions(-) delete mode 100644 packages/hoppscotch-data/src/pathVariables.ts diff --git a/packages/hoppscotch-data/src/pathVariables.ts b/packages/hoppscotch-data/src/pathVariables.ts deleted file mode 100644 index 44892680d..000000000 --- a/packages/hoppscotch-data/src/pathVariables.ts +++ /dev/null @@ -1,76 +0,0 @@ -import { pipe } from "fp-ts/function" -import * as E from "fp-ts/Either" -import {parseTemplateStringE} from "./environment"; - -export type Environment = { - name: string - variables: { - key: string - value: string - }[] -} - -export type Variables = { - key: string - value: string -}[] - -const REGEX_ENV_VAR = /<<([^>]*)>>/g // "<>" -const REGEX_PATHVAR = /{{([^>]*)}}/g // "{{myVariable}}" - -/** - * How much times can we expand environment variables - */ -const ENV_MAX_EXPAND_LIMIT = 10 - -/** - * Error state when there is a suspected loop while - * recursively expanding variables - */ -const ENV_EXPAND_LOOP = "ENV_EXPAND_LOOP" as const - -export function parseTemplateStringEV( - str: string, - variables: Environment["variables"], - pathVariables: Variables -) { - if (!variables || !str || !pathVariables) { - return E.right(str) - } - - let result = str - let depth = 0 - - while (result.match(REGEX_ENV_VAR) != null && depth <= ENV_MAX_EXPAND_LIMIT) { - result = decodeURI(encodeURI(result)).replace( - REGEX_ENV_VAR, - (_, p1) => variables.find((x) => x.key === p1)?.value || "" - ) - depth++ - } - - while (result.match(REGEX_PATHVAR) != null && depth <= ENV_MAX_EXPAND_LIMIT) { - result = decodeURI(encodeURI(result)).replace( - REGEX_PATHVAR, - (_, p1) => pathVariables.find((x) => x.key === p1)?.value || "" - ) - } - - return depth > ENV_MAX_EXPAND_LIMIT - ? E.left(ENV_EXPAND_LOOP) - : E.right(result) -} - -/** - * @deprecated Use `parseTemplateStringE` instead - */ -export const parseTemplateStringV = ( - str: string, - variables: Environment["variables"], - pathVariables: Variables -) => - pipe( - parseTemplateStringEV(str, variables, pathVariables), - E.getOrElse(() => str) - ) -