Skip to content

Commit

Permalink
feat: improve interface (DLC-504) (#569)
Browse files Browse the repository at this point in the history
<!-- You can erase any parts of this template not applicable to your Pull Request. -->

**Fixes or implements VF-XXX**

### Brief description. What is this change?

<!-- Build up some context for your teammates on the changes made here and potential tradeoffs made and/or highlight any topics for discussion -->
  • Loading branch information
pmvrmc committed Dec 17, 2024
1 parent 60ae823 commit 8d4af7b
Showing 1 changed file with 15 additions and 3 deletions.
18 changes: 15 additions & 3 deletions packages/common/src/utils/variables.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,12 +61,24 @@ export const splitVariableName = (inner: string) => {
};
};

export const replaceVariables = (
export function replaceVariables(
phrase: string | undefined | null,
variables: Record<string, unknown>,
modifier?: (variable: unknown) => unknown,
options?: { trim?: boolean; keepTypeIfOnlyVariable?: false }
): string;
export function replaceVariables(
phrase: string | undefined | null,
variables: Record<string, unknown>,
modifier?: (variable: unknown) => unknown,
options?: { trim?: boolean; keepTypeIfOnlyVariable: true }
): unknown;
export function replaceVariables(
phrase: string | undefined | null,
variables: Record<string, unknown>,
modifier: ((variable: unknown) => unknown) | undefined = undefined,
{ trim = true, keepTypeIfOnlyVariable = false }: { trim?: boolean; keepTypeIfOnlyVariable?: boolean } = {}
): string | unknown => {
): string | unknown {
if (!phrase || (trim && !phrase.trim())) {
return '';
}
Expand All @@ -80,7 +92,7 @@ export const replaceVariables = (
return phrase.replace(READABLE_VARIABLE_REGEXP, (match, inner) =>
String(variableReplacer(match, inner, variables, modifier))
);
};
}

// turn float variables to 4 decimal places
export const sanitizeVariables = (variables: Record<string, unknown>): Record<string, unknown> =>
Expand Down

0 comments on commit 8d4af7b

Please sign in to comment.