Skip to content

Commit

Permalink
feat(template): add lowercase Handlebars helper (#15212)
Browse files Browse the repository at this point in the history
  • Loading branch information
ikesyo committed Apr 21, 2022
1 parent 65b6697 commit 2c087e8
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 0 deletions.
6 changes: 6 additions & 0 deletions docs/usage/templates.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
6 changes: 6 additions & 0 deletions lib/util/template/index.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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');
});
});
2 changes: 2 additions & 0 deletions lib/util/template/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
);
Expand Down

0 comments on commit 2c087e8

Please sign in to comment.