• Jump To … +
    abbreviations.js adjectives.js convertables.js dates.js demonyms.js firstnames.js honourifics.js irregular_nouns.js irregular_verbs.js misc.js multiples.js numbers.js organisations.js phrasal_verbs.js places.js uncountables.js verbs.js fns.js index.js lexicon.js negate.js passive_voice.js contractions.js fancy_lumping.js grammar_rules.js parts_of_speech.js phrasal_verbs.js tagger.js word_rules.js question.js sentence.js statement.js tense.js adjective.js to_adverb.js to_comparative.js to_noun.js to_superlative.js adverb.js to_adjective.js is_acronym.js article.js date.js date_rules.js is_date.js parse_date.js is_plural.js is_uncountable.js noun.js is_organisation.js organisation.js gender.js is_person.js parse_name.js person.js is_place.js place.js pluralize.js pronoun.js singularize.js is_value.js numbers.js to_number.js units.js value.js term.js conjugate.js from_infinitive.js predict_form.js suffix_rules.js to_actor.js to_infinitive.js negate.js verb.js sentence_parser.js text.js
  • to_adverb.js

  • ¶

    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',
        '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;