Pre-release
AdventureJS Docs Downloads Devlog
Score: 0 Moves: 0
// getCase.js

/* global AdventureJS A */

/**
 * Get the case of a string.
 * @method AdventureJS.Game#getCase
 * @memberOf AdventureJS
 * @param {String} text
 * @returns {String}
 */
AdventureJS.FX.getCase = function AdventureJS_getCase(text) {
  if (text === "I") {
    return "title";
  }

  if (text === text.toLowerCase()) {
    return "lower";
  }

  if (text === text.toUpperCase()) {
    return "upper";
  }

  if (
    text[0] === text[0].toUpperCase() &&
    text.slice(1) === text.slice(1).toLowerCase()
  ) {
    return "title";
  }

  return "mixed";
};