• 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
  • fns.js

  • ¶
    'use strict';
    exports.pluck = function(arr, str) {
      arr = arr || [];
      return arr.map(function(o) {
        return o[str];
      });
    };
    
    exports.flatten = function(arr) {
      let all = [];
      arr.forEach(function(a) {
        all = all.concat(a);
      });
      return all;
    };
    
    exports.sameArr = function(arr, arrB) {
      if (typeof arr !== typeof arrB || arr.length !== arrB.length) {
        return null;
      }
      for(let i = 0; i < arr.length; i++) {
        if (arr[i] !== arrB[i]) {
          return false;
        }
      }
      return true;
    };
    
    exports.compact = function(arr) {
      return arr.filter(function(a) {
        if (a === undefined || a === null) {
          return false;
        }
        return true;
      });
    };
  • ¶

    shallow-combine two objects

    exports.extend = function (objA, objB) {
      Object.keys(objB).forEach(function (k) {
        objA[k] = objB[k];
      });
      return objA;
    };
  • ¶

    string utilities

    exports.endsWith = function(str, suffix) {
      return str.indexOf(suffix, str.length - suffix.length) !== -1;
    };
    
    exports.titlecase = function(str) {
      if (!str) {
        return '';
      }
      return str.charAt(0).toUpperCase() + str.slice(1);
    };
  • ¶

    typeof obj == “function” also works but not in older browsers. :-/

    exports.isFunction = function(obj) {
      return Object.prototype.toString.call(obj) === '[object Function]';
    };