UNPKG

compromise

Version:
72 lines (66 loc) 1.17 kB
'use strict'; //convert 'cute' to 'cuteness' const to_noun = function(w) { const irregulars = { 'clean': 'cleanliness', 'naivety': 'naivety', hurt: 'hurt' }; if (!w) { return ''; } if (irregulars.hasOwnProperty(w)) { return irregulars[w]; } if (w.match(' ')) { return w; } if (w.match(/w$/)) { return w; } const transforms = [{ 'reg': /y$/, 'repl': 'iness' }, { 'reg': /le$/, 'repl': 'ility' }, { 'reg': /ial$/, 'repl': 'y' }, { 'reg': /al$/, 'repl': 'ality' }, { 'reg': /ting$/, 'repl': 'ting' }, { 'reg': /ring$/, 'repl': 'ring' }, { 'reg': /bing$/, 'repl': 'bingness' }, { 'reg': /sing$/, 'repl': 'se' }, { 'reg': /ing$/, 'repl': 'ment' }, { 'reg': /ess$/, 'repl': 'essness' }, { 'reg': /ous$/, 'repl': 'ousness' }]; for (let i = 0; i < transforms.length; i++) { if (w.match(transforms[i].reg)) { return w.replace(transforms[i].reg, transforms[i].repl); } } if (w.match(/s$/)) { return w; } return w + 'ness'; }; // console.log(to_noun("great")) module.exports = to_noun;