Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

titleCase fails to transform name #415

Open
viveleroi opened this issue Feb 4, 2024 · 4 comments
Open

titleCase fails to transform name #415

viveleroi opened this issue Feb 4, 2024 · 4 comments

Comments

@viveleroi
Copy link

I have a line of code in an hbs helper:

<WindowHeader onClose={onClose} title='{{titleCase name}}' />

When I run a plop command and name is set to someName, all of the kebab and pascal casing conversions work fine, but the titleCase one does nothing.

The output is:

<WindowHeader onClose={onClose} title='someName' />

Am I missing something or doing something wrong? The handlebars braces are being read just fine as it's replacing the template with the value, it's just not converting the value to title case

@tidemann
Copy link

tidemann commented Feb 6, 2024

I'm also having issues with titleCase.
Did a quick test with variable name set to "test-foo-bar":
{{name}} {{pascalCase name}} {{titleCase name}}
outputs:
test-foo-bar TestFooBar Test-Foo-Bar
I would expect {{titleCase name}} to output: "Test Foo Bar"

@ricardo85x
Copy link

ricardo85x commented Jul 16, 2024

I encountered the same issue with version 0.32.0.

As an alternative, I'm using the sentenceCase function, which produces a similar result.

For example, hello_world becomes Hello world, but the ideal result would be Hello World.

@nkrantz
Copy link

nkrantz commented Oct 14, 2024

I'm using version 3.0.0 of plop and having the same issue with titleCase.

{{titleCase component-name}} is outputting to DisplayHeading when component-name="display heading". Correct behavior would output Display Heading.

@mathias-gr
Copy link

mathias-gr commented Nov 15, 2024

A quick workaround here is to overwrite the titleCase helper in your plop config file :

const capitalizeFirstLetter = (val) => String(val).charAt(0).toUpperCase() + String(val).slice(1);

export default function (plop) {
	const sentenceCase = plop.getHelper('sentenceCase');

	plop.setHelper('titleCase', (text) => {
		const sentence = sentenceCase(text);

		return sentence.split(' ').map(capitalizeFirstLetter).join(' ');
	});

	plop.setGenerator(name, config);
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants