util.js 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. /*
  2. * @licstart The following is the entire license notice for the JavaScript
  3. * code in this page.
  4. *
  5. * This file is part of oddjobs-dmg-calc.
  6. *
  7. * oddjobs-dmg-calc is free software: you can redistribute it and/or modify it
  8. * under the terms of the GNU Affero General Public License as published by the
  9. * Free Software Foundation, either version 3 of the License, or (at your
  10. * option) any later version.
  11. *
  12. * oddjobs-dmg-calc is distributed in the hope that it will be useful, but
  13. * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
  14. * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public
  15. * License for more details.
  16. *
  17. * You should have received a copy of the GNU Affero General Public License
  18. * along with oddjobs-dmg-calc. If not, see <https://www.gnu.org/licenses/>.
  19. *
  20. * @licend The above is the entire license notice for the JavaScript code in
  21. * this page.
  22. */
  23. /**
  24. * This is how English works, right? Probably?
  25. */
  26. export function indefinite(s) {
  27. const sLower = s.toLowerCase();
  28. // le sigh...
  29. if (sLower.startsWith("one")) {
  30. return `a ${s}`;
  31. }
  32. switch (sLower.codePointAt(0)) {
  33. case "a".codePointAt(0):
  34. case "e".codePointAt(0):
  35. case "i".codePointAt(0):
  36. case "o".codePointAt(0):
  37. case "u".codePointAt(0):
  38. return `an ${s}`;
  39. default:
  40. return `a ${s}`;
  41. }
  42. }