diff --git a/docs/usage/templates.md b/docs/usage/templates.md index f76beaa9a228be..ab46b61a3046b9 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 8460d91de65951..e0d7f67304ec3b 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 5eac67473c4f88..4948636a06dca8 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) );