Merge codeday/jason => codeday/isai

This commit is contained in:
Jason Casareno
2022-08-01 14:46:06 -07:00
6 changed files with 28 additions and 24 deletions

View File

@@ -12,11 +12,10 @@ export type Environment = {
export type Variables = {
key: string
value: string
}[]
}[]
const REGEX_ENV_VAR = /<<([^>]*)>>/g // "<<myVariable>>"
const REGEX_PATHVAR = /{{([^>]*)}}/g // "{{myVariable}}"
const REGEX_PATH_VAR = /{{([^>]*)}}/g // "{{myVariable}}"
/**
* How much times can we expand environment variables

View File

@@ -16,7 +16,7 @@ export type Variables = {
}[]
const REGEX_ENV_VAR = /<<([^>]*)>>/g // "<<myVariable>>"
const REGEX_PATHVAR = /{{([^>]*)}}/g // "{{myVariable}}"
const REGEX_MY_VAR = /{{([^}]*)}}/g // "{{myVariable}}"
/**
* How much times can we expand environment variables
@@ -32,9 +32,9 @@ const ENV_EXPAND_LOOP = "ENV_EXPAND_LOOP" as const
export function parseTemplateStringEV(
str: string,
variables: Environment["variables"],
pathVariables: Variables
myVariables: Variables
) {
if (!variables || !str || !pathVariables) {
if (!variables || !str || !myVariables) {
return E.right(str)
}
@@ -49,10 +49,13 @@ export function parseTemplateStringEV(
depth++
}
while (result.match(REGEX_PATHVAR) != null && depth <= ENV_MAX_EXPAND_LIMIT) {
/**
* TODO: Create an error state when there is a suspected loop while recursively expanding these variables
*/
while (result.match(REGEX_MY_VAR) != null && depth <= ENV_MAX_EXPAND_LIMIT) {
result = decodeURI(encodeURI(result)).replace(
REGEX_PATHVAR,
(_, p1) => pathVariables.find((x) => x.key === p1)?.value || ""
REGEX_MY_VAR,
(_, p1) => myVariables.find((x) => x.key === p1)?.value || ""
)
}
@@ -62,15 +65,14 @@ export function parseTemplateStringEV(
}
/**
* @deprecated Use `parseTemplateStringE` instead
* @deprecated Use `parseTemplateStringEV` instead
*/
export const parseTemplateStringV = (
str: string,
variables: Environment["variables"],
pathVariables: Variables
myVariables: Variables
) =>
pipe(
parseTemplateStringEV(str, variables, pathVariables),
parseTemplateStringEV(str, variables, myVariables),
E.getOrElse(() => str)
)