UNPKG

compromise

Version:
134 lines (128 loc) 2.32 kB
//turn 'quick' into 'quickly' 'use strict'; const adj_to_adv = function(str) { const irregulars = { 'idle': 'idly', 'public': 'publicly', 'vague': 'vaguely', 'day': 'daily', 'icy': 'icily', 'single': 'singly', 'female': 'womanly', 'male': 'manly', 'simple': 'simply', 'whole': 'wholly', 'special': 'especially', 'straight': 'straight', 'wrong': 'wrong', 'fast': 'fast', 'hard': 'hard', 'late': 'late', 'early': 'early', 'well': 'well', 'good': 'well', 'little': 'little', 'long': 'long', 'low': 'low', 'best': 'best', 'latter': 'latter', 'bad': 'badly' }; const dont = { 'foreign': 1, 'black': 1, 'modern': 1, 'next': 1, 'difficult': 1, 'degenerate': 1, 'young': 1, 'awake': 1, 'back': 1, 'blue': 1, 'brown': 1, 'orange': 1, 'complex': 1, 'cool': 1, 'dirty': 1, 'done': 1, 'empty': 1, 'fat': 1, 'fertile': 1, 'frozen': 1, 'gold': 1, 'grey': 1, 'gray': 1, 'green': 1, 'medium': 1, 'parallel': 1, 'outdoor': 1, 'unknown': 1, 'undersized': 1, 'used': 1, 'welcome': 1, 'yellow': 1, 'white': 1, 'fixed': 1, 'mixed': 1, 'super': 1, 'guilty': 1, 'tiny': 1, 'able': 1, 'unable': 1, 'same': 1, 'adult': 1 }; const transforms = [{ reg: /al$/i, repl: 'ally' }, { reg: /ly$/i, repl: 'ly' }, { reg: /(.{3})y$/i, repl: '$1ily' }, { reg: /que$/i, repl: 'quely' }, { reg: /ue$/i, repl: 'uly' }, { reg: /ic$/i, repl: 'ically' }, { reg: /ble$/i, repl: 'bly' }, { reg: /l$/i, repl: 'ly' }]; const not_matches = [ /airs$/, /ll$/, /ee.$/, /ile$/ ]; if (dont[str]) { return null; } if (irregulars[str]) { return irregulars[str]; } if (str.length <= 3) { return null; } for (let i = 0; i < not_matches.length; i++) { if (str.match(not_matches[i])) { return null; } } for (let i = 0; i < transforms.length; i++) { if (str.match(transforms[i].reg)) { return str.replace(transforms[i].reg, transforms[i].repl); } } return str + 'ly'; }; // console.log(adj_to_adv('direct')) module.exports = adj_to_adv;