All files / web/src/components/toys/coordinate-plane/wordProblems inflect.ts

100% Statements 71/71
100% Branches 18/18
100% Functions 7/7
100% Lines 71/71

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 721x 1x 1x 1x 179x 179x 1x 1x 1x 77x 77x 1x 1x 1x 128x 128x 1x 1x 1x 714x 714x 1x 1x 1x 1x 1x 1x 1x 2526x 569x 569x 1957x 1957x 1x 1x 1x 1x 1x 11975x 11974x 11974x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 473x 473x 406x 406x 67x 67x  
import type { NounEntry, VerbEntry, SubjectEntry } from './types'
 
/** Pick singular or plural based on count */
export function pluralize(noun: NounEntry, count: number): string {
  return count === 1 ? noun.singular : noun.plural
}
 
/** Get third-person singular form */
export function conjugate3p(verb: VerbEntry): string {
  return verb.thirdPerson
}
 
/** Get base/infinitive form */
export function conjugateBase(verb: VerbEntry): string {
  return verb.base
}
 
/** Conjugate a verb to agree with a subject entry */
export function conjugateFor(verb: VerbEntry, subject: SubjectEntry): string {
  return subject.conjugation === 'thirdPerson' ? verb.thirdPerson : verb.base
}
 
/**
 * Format a number with its unit, respecting prefix/suffix position.
 * Examples: formatWithUnit(3, "$", "prefix") → "$3"
 *           formatWithUnit(5, "inches", "suffix") → "5 inches"
 */
export function formatWithUnit(value: number, unit: string, position: 'prefix' | 'suffix'): string {
  if (position === 'prefix') {
    return `${unit}${value}`
  }
  return `${value} ${unit}`
}
 
/**
 * Capitalize the first letter of a string.
 */
export function capitalize(s: string): string {
  if (s.length === 0) return s
  return s[0].toUpperCase() + s.slice(1)
}
 
/** Words that should be lowercased when a subject appears mid-sentence */
const MID_SENTENCE_LOWERCASE = new Set([
  'the',
  'a',
  'an',
  'each',
  'every',
  'some',
  'this',
  'that',
  'she',
  'he',
  'it',
  'they',
  'we',
])
 
/**
 * Lowercase a subject phrase for mid-sentence use.
 * Lowercases the first letter only if it's an article/pronoun/determiner.
 * Preserves proper nouns like "Sonia".
 */
export function midSentence(phrase: string): string {
  const firstWord = phrase.split(' ')[0]
  if (MID_SENTENCE_LOWERCASE.has(firstWord.toLowerCase())) {
    return phrase[0].toLowerCase() + phrase.slice(1)
  }
  return phrase
}