Javascript Gerundization

Ever needed to "gerudize" a word? No? I needed to today to convert links and button labels like "Save" and "Submit" into their gerund equivalents: "Saving" and "Submitting". I found a set of rules on how to convert a verb into a noun here, and put together a simple Javascript implementation. I might do a ColdFusion one later to match my Pluralize() and Singularize() utility functions.

function gerundize (word) {
    if ( word.match( /[^aeiou]e$/i ) ) {
        word = word.slice(0, word.length-1);
    } else if ( word.match( /[^aeiou][aeiou][^aeiou]$/i ) ) {
        word = word + word.slice(word.length-1, word.length);
    }

    return word + 'ing';
}

And the test code:

document.write(gerundize('Think'));
document.write('<br />');
document.write(gerundize('Submit'));
document.write('<br />');
document.write(gerundize('Hit'));
document.write('<br />');
document.write(gerundize('Take'));
document.write('<br />');
document.write(gerundize('Create'));
document.write('<br />');
document.write(gerundize('Save'));
document.write('<br />');

 

Comments

Jon Hartmann, July 2011

I'm Jon Hartmann and I'm a Javascript fanatic, UX/UI evangelist and former ColdFusion master. I blog about mysterious error messages, user interface design questions, and all things baffling and irksome about programming for the web.

Learn more about me.

Post a job. Find one. authenticjobs.com

Interested in becoming a sponsor? Contact me.