isWord

Benchmark created on


Setup

const str = "wordy-word";

Test runner

Ready to run.

Testing in
TestOps/sec
regex
return str.match(/^[a-zA-Z\-]+$/);
ready
negated regex
return str.match(/[^a-zA-Z\-]/);
ready
charcodeat

for(let i = 0; i < str.length; i++) {
	const code = str.charCodeAt(i);
	if( 
	!(code >= 65 && code <= 90)
	&& !(code >= 97 && code <= 122)
	&& !(code == 45))
	    return false;
}
return true;
ready
lowercase charcodeat
const s = str.toLowerCase();
for(let i = 0; i < s.length; i++) {
	const code = s.charCodeAt(i);
	if( !(code >= 97 && code <= 122)
	&& !(code >= 48 && code <= 57)
	&& !(code == 45))
	    return false;
}
return true;
ready
insensitive regex
return str.match(/^[a-z\-]+$/i);
ready
insensitive negated regext
return str.match(/[^a-z\-]/i);
ready
lowercase regex
return str.toLowerCase().match(/^[a-z\-]+$/);
ready
lowercase negated regex
return str.toLowerCase().match(/[^a-z\-]/);
ready

Revisions

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