From 2c087e86f78503c7f22d93bc88f97a86e3b33a3f Mon Sep 17 00:00:00 2001
From: IKEDA Sho <suicaicoca@gmail.com>
Date: Thu, 21 Apr 2022 18:26:24 +0900
Subject: [PATCH] feat(template): add `lowercase` Handlebars helper (#15212)

---
 docs/usage/templates.md         | 6 ++++++
 lib/util/template/index.spec.ts | 6 ++++++
 lib/util/template/index.ts      | 2 ++
 3 files changed, 14 insertions(+)

diff --git a/docs/usage/templates.md b/docs/usage/templates.md
index f76beaa9a2..ab46b61a30 100644
--- a/docs/usage/templates.md
+++ b/docs/usage/templates.md
@@ -58,6 +58,12 @@ In the example above all matches of `github.com` will be replaced by `ghc` in `d
 
 Read the [MDN Web Docs, String.prototype.replace()](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/replace) to learn more.
 
+### lowercase
+
+The `lowercase` helper converts a given string to lower case.
+
+`{{{ lowercase depName }}}`
+
 ### containsString
 
 Returns `true` if a given string is a substring.
diff --git a/lib/util/template/index.spec.ts b/lib/util/template/index.spec.ts
index 8460d91de6..e0d7f67304 100644
--- a/lib/util/template/index.spec.ts
+++ b/lib/util/template/index.spec.ts
@@ -74,4 +74,10 @@ describe('util/template/index', () => {
     const output = template.compile(userTemplate, undefined);
     expect(output).toMatchSnapshot();
   });
+
+  it('lowercase', () => {
+    const userTemplate = "{{{ lowercase 'FOO'}}}";
+    const output = template.compile(userTemplate, undefined);
+    expect(output).toBe('foo');
+  });
 });
diff --git a/lib/util/template/index.ts b/lib/util/template/index.ts
index 5eac67473c..4948636a06 100644
--- a/lib/util/template/index.ts
+++ b/lib/util/template/index.ts
@@ -17,6 +17,8 @@ handlebars.registerHelper(
     (context || '').replace(new RegExp(find, 'g'), replace) // TODO #12873
 );
 
+handlebars.registerHelper('lowercase', (str: string) => str.toLowerCase());
+
 handlebars.registerHelper('containsString', (str, subStr, options) =>
   str.includes(subStr)
 );
-- 
GitLab