Franks Method to turn first Letter upperCase

Benchmark created on


Test runner

Ready to run.

Testing in
TestOps/sec
Handels utf-32 up to 4 bit utf-8 chars (recommend)
const upperCaseFirstLatterUtf8 = (str) => {
	// if (str.codePointAt(1) >> 7)  return str[0].toUpperCase() + str.substr(1)
	const b = str.substr(0,4).normalize();
	return b[0].toUpperCase() + b.substr(1) + str.substr(4);	
}
upperCaseFirstLatterUtf8('me!')
ready
ultra slow Handels some utf-16 cases but never utf-32 (special utf-16 edge case)
const s = '๐Ž๐ฒ๐‘Œ๐ผme!'
s[0].toUpperCase``+s.substr`1`
ready
nice
"๐Ž๐ฒ๐‘Œ๐ผme!".replace(/^[a-z]/, s=>s.toUpperCase());
ready
ultra slow Handels some utf-16 cases but never utf-32 (recommend if no utf-16 edge case and no need for utf 32)
const s = '\u006E\u0303me!'
s[0].toUpperCase()+s.substr(1)
ready
Handels utf-32 up to 4 bit utf-8 chars exponential gets slower with larger strings (recommend when you want to save cleaned data later anyway)
s = '\u006E\u0303me!'.normalize()
s[0].toUpperCase() + s.substr(1) 
ready
slow Handels some utf-16 cases but never utf-32 (recommend if no utf-16 edge case and no need for utf 32)
let str = "hello WORLD"
let newStr = str.replace(str[0], str[0].toUpperCase())
ready
slow Handels some utf-16 cases but never utf-32 (recommend if no utf-16 edge case and no need for utf 32)
let str = "\u006E\u0303ello WORLD"
let newStr = str.replace(str[0], str[0].toUpperCase())
ready
fast Handels some utf-16 cases but never utf-32 (recommend if no utf-16 edge case and no need for utf 32)
let str = "\u006E\u0303ello WORLD"
str[0].toUpperCase() + str.substr(1)
ready
Handels utf-32 up to 4 bit utf-8 chars exponential gets slower with larger strings (recommend)
const upperCaseFirstLatterUtf8 = (str) => {
	const b = str.substr(0,4).normalize();
	return b[0].toUpperCase() + b.substr(1) + str.substr(4);	
}
upperCaseFirstLatterUtf8('\u006E\u0303me!')
ready
Handels utf-32 up to 4 bit utf-8 chars exponential gets slower with larger strings (recommend when you want to save cleaned data later anyway)
s = 'notme!'.normalize()
s[0].toUpperCase() + s.substr(1) 
ready
Handels some utf-16 cases but never utf-32 (recommend if no need for utf 32)
const upperCaseFirstLatterUtf8 = (str) => {
	const b = str.substr(0,2).normalize();
	return b[0].toUpperCase() + b.substr(1) + str.substr(2);	
}
upperCaseFirstLatterUtf8('\u006E\u0303me!')
ready
Most Expensiv but best

const segments = [...new Intl.Segmenter().segment('๐Ÿ…-๐Ÿ‘จโ€๐Ÿ‘ฉโ€๐Ÿ‘ง-เฎจเฎฟ-๊น-่‘›๓ „€')];
segments[0].segment.toUpperCase() + segments.slice(1).map(s=>s.segment).join('');
ready
segmenter parse
const str = '๐Ÿ…-๐Ÿ‘จโ€๐Ÿ‘ฉโ€๐Ÿ‘ง-เฎจเฎฟ-๊น-่‘›๓ „€';
const segs = [...new Intl.Segmenter().segment(str.substr(0,4))]
str.substr(0,segs[1]?.index).toUpperCase()+str.substr(segs[1]?.index)
ready
segmenter reuse segment
const str = '๐Ÿ…-๐Ÿ‘จโ€๐Ÿ‘ฉโ€๐Ÿ‘ง-เฎจเฎฟ-๊น-่‘›๓ „€';
const segs = [...new Intl.Segmenter().segment(str.substr(0,4))]
segs[0].segment.toUpperCase()+str.substr(segs[1]?.index)
ready

Revisions

You can edit these tests or add more tests to this page by appending /edit to the URL.