All Downloads are FREE. Search and download functionalities are using the official Maven repository.

node_modules.inflected.src.applyInflections.js Maven / Gradle / Ivy

The newest version!
import inflections from "./inflections";

export default function applyInflections(word, rules) {
  var result = "" + word, rule, regex, replacement;

  if (result.length === 0) {
    return result;
  } else {
    var match = result.toLowerCase().match(/\b\w+$/);

    if (match && inflections().uncountables.indexOf(match[0]) > -1) {
      return result;
    } else {
      for (var i = 0, ii = rules.length; i < ii; i++) {
        rule = rules[i];

        regex = rule[0];
        replacement = rule[1];

        if (result.match(regex)) {
          result = result.replace(regex, replacement);
          break;
        }
      }

      return result;
    }
  }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy