Skip to content

Commit 3acd779

Browse files
authored
Merge pull request ferdikoomen#448 from mlaps-gafe/allow-spaces-in-enum-names
Add support for enum names with spaces inside them.
2 parents e012d53 + 697551b commit 3acd779

File tree

4 files changed

+25
-0
lines changed

4 files changed

+25
-0
lines changed

rollup.config.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ const handlebarsPlugin = () => ({
3434
knownHelpers: {
3535
equals: true,
3636
notEquals: true,
37+
containsSpaces: true,
3738
},
3839
});
3940
return `export default ${templateSpec};`;

src/templates/partials/exportEnum.hbs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,10 @@ export enum {{{name}}} {
1010
* {{{description}}}
1111
*/
1212
{{/if}}
13+
{{#if (containsSpaces name)}}
14+
"{{{name}}}" = {{{value}}},
15+
{{else}}
1316
{{{name}}} = {{{value}}},
17+
{{/if}}
1418
{{/each}}
1519
}

src/utils/registerHandlebarHelpers.spec.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,5 +8,22 @@ describe('registerHandlebarHelpers', () => {
88
const helpers = Object.keys(Handlebars.helpers);
99
expect(helpers).toContain('equals');
1010
expect(helpers).toContain('notEquals');
11+
expect(helpers).toContain('containsSpaces');
12+
});
13+
14+
describe('containsSpaces', () => {
15+
it('should return true when string with spaces is passed', () => {
16+
registerHandlebarHelpers();
17+
const containsSpaces = Handlebars.helpers['containsSpaces'];
18+
const result = containsSpaces('I have spaces insideme');
19+
expect(result).toBeTruthy();
20+
});
21+
22+
it('should return false when string without spaces is passed', () => {
23+
registerHandlebarHelpers();
24+
const containsSpaces = Handlebars.helpers['containsSpaces'];
25+
const result = containsSpaces('Ihavespacesinsideme');
26+
expect(result).toBeFalsy();
27+
});
1128
});
1229
});

src/utils/registerHandlebarHelpers.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,7 @@ export function registerHandlebarHelpers(): void {
99
Handlebars.registerHelper('notEquals', function (a: string, b: string, options: Handlebars.HelperOptions): string {
1010
return a !== b ? options.fn(this) : options.inverse(this);
1111
});
12+
Handlebars.registerHelper('containsSpaces', function (value: string): boolean {
13+
return /\s+/.test(value);
14+
});
1215
}

0 commit comments

Comments
 (0)