aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorST-DDT <[email protected]>2022-04-04 16:47:03 +0200
committerGitHub <[email protected]>2022-04-04 14:47:03 +0000
commit8b545b4e72e0d00f93d51f8de876103bedebff03 (patch)
treea9488736462c05ca887f9f2432cf7c69396b6c80 /src
parent9e03bcff3aaad13afbfae99fb1df046c2f227c2c (diff)
downloadfaker-8b545b4e72e0d00f93d51f8de876103bedebff03.tar.xz
faker-8b545b4e72e0d00f93d51f8de876103bedebff03.zip
chore: fix mustache type warning and add some tests (#753)
Diffstat (limited to 'src')
-rw-r--r--src/helpers.ts17
1 files changed, 7 insertions, 10 deletions
diff --git a/src/helpers.ts b/src/helpers.ts
index 051de5ea..f302ac46 100644
--- a/src/helpers.ts
+++ b/src/helpers.ts
@@ -477,22 +477,19 @@ export class Helpers {
*/
mustache(
str: string | undefined,
- data: Record<
- string,
- string | ((substring: string, ...args: any[]) => string)
- >
+ data: Record<string, string | Parameters<string['replace']>[1]>
): string {
if (str == null) {
return '';
}
for (const p in data) {
const re = new RegExp('{{' + p + '}}', 'g');
- str = str.replace(
- re,
- // TODO @Shinigami92 2022-01-14: Try to improve the type or maybe use `if`
- // @ts-expect-error
- data[p]
- );
+ const value = data[p];
+ if (typeof value === 'string') {
+ str = str.replace(re, value);
+ } else {
+ str = str.replace(re, value);
+ }
}
return str;
}