'use strict';
const to_noun = function(w) {
const irregulars = {
'clean': 'cleanliness',
'naivety': 'naivety'
};
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';
};