What's each method call in this function doing?
export const capitalize = (string: string): string =>
	string
		.replace(/([A-Z]+)/g, " $1")
		.replace(/([A-Z][a-z])/g, " $1")
		.split(/([\s-])/g)
		.map((str) => (str?.[0]?.toUpperCase() || "") + (str.slice(1)?.toLowerCase() || ""))
		.join(" ");
system
What's each method call in this function doing?
export const capitalize = (string: string): string =>
	string
		.replace(/([A-Z]+)/g, " $1")
		.replace(/([A-Z][a-z])/g, " $1")
		.split(/([\s-])/g)
		.map((str) => (str?.[0]?.toUpperCase() || "") + (str.slice(1)?.toLowerCase() || ""))
		.join(" ");
user
The first method call in this function uses String#replace to insert a space before any sequences of capital letters. It then calls String#replace again to insert a space before any capital letter followed by a lowercase letter. Next, it uses String#split to split the produced string into an array at each instance of either a whitespace character or the - character. The produced array is mapped over, with each string in the array having its first letter capitalized and the rest converted to lowercase. This array is then joined back into a string with a space between each element.
assistant
<|system|>
</s>
<|user|>
What's each method call in this function doing?
export const capitalize = (string: string): string =>
	string
		.replace(/([A-Z]+)/g, " $1")
		.replace(/([A-Z][a-z])/g, " $1")
		.split(/([\s-])/g)
		.map((str) => (str?.[0]?.toUpperCase() || "") + (str.slice(1)?.toLowerCase() || ""))
		.join(" ");</s>
<|assistant|>
The first method call in this function uses String#replace to insert a space before any sequences of capital letters. It then calls String#replace again to insert a space before any capital letter followed by a lowercase letter. Next, it uses String#split to split the produced string into an array at each instance of either a whitespace character or the - character. The produced array is mapped over, with each string in the array having its first letter capitalized and the rest converted to lowercase. This array is then joined back into a string with a space between each element.</s>
