Skip to content

Commit 4c9871c

Browse files
Support touppercamelcase in iterator for split templates (#1566)
* Support touppercamelcase and unit tests * Documentation update * Undo some formatting * Undo some formatting --------- Co-authored-by: Andrei Litvin <[email protected]>
1 parent 3375934 commit 4c9871c

File tree

3 files changed

+7
-3
lines changed

3 files changed

+7
-3
lines changed

docs/sdk-integration.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ The `templates` key contained in the `gen-templates.json` file above, is an arra
8282

8383
The _replacement pattern_ inside the output key, comes handy when iterator key is used and defines how each generated file will be named. Replacement patterns are in a format of `{key}` or `{key:modifier}`. The `key` can be any usual key that the iterated object provides. For example, if you iterate over cluster, these can be `code`, `name`, `description`, `define` and all the usual keys that a cluster supports. So if your output contains `{code}` then this pattern will be replaced by the actual cluster code.
8484

85-
The modifier can be one of the following: `hexuppercase`, `hexlowercase`, `tolowercase`, `touppercase`, `tocamelcase`, `tosnakecase` or `tosnakecaseallcaps`.
85+
The modifier can be one of the following: `hexuppercase`, `hexlowercase`, `tolowercase`, `touppercase`, `tocamelcase`, `touppercamelcase`, `tosnakecase` or `tosnakecaseallcaps`.
8686

8787
## Templates key: options
8888

src-electron/util/util.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -930,6 +930,10 @@ function patternFormat(pattern, data) {
930930
`{${key}:tocamelcase}`,
931931
string.toCamelCase(value.toString())
932932
)
933+
out = out.replace(
934+
`{${key}:touppercamelcase}`,
935+
string.toCamelCase(value.toString(), /* firstLower = */ false)
936+
)
933937
out = out.replace(
934938
`{${key}:tosnakecase}`,
935939
string.toSnakeCase(value.toString())

test/util.test.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,13 +47,13 @@ test(
4747
)
4848
expect(
4949
util2.patternFormat(
50-
'{a:tocamelcase} {b:tosnakecase} {b:tosnakecaseallcaps}',
50+
'{a:tocamelcase} {b:tosnakecase} {b:tosnakecaseallcaps} {a:touppercamelcase} {b:touppercamelcase}',
5151
{
5252
a: 'some string',
5353
b: 'another string'
5454
}
5555
)
56-
).toEqual('someString another_string ANOTHER_STRING')
56+
).toEqual('someString another_string ANOTHER_STRING SomeString AnotherString')
5757
},
5858
timeout.short()
5959
)

0 commit comments

Comments
 (0)