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 | 1x 1x 1x 1x 1x 80x 80x 7x 7x 80x 9x 9x 64x 80x 80x 1x 306x 306x 306x 306x 306x 226x 226x 80x 80x 80x 80x 80x 80x 80x 80x 80x 80x 80x 80x 80x 80x 80x 80x | import { type DeconstructedNumber } from './@types/deconstructed-number.ts'; import { deriveFraction } from './derive-fraction.ts'; import { fabricateAlphabeticInteger } from './fabricate-alphabetic-integer.ts'; import { type Numbering } from './numbering.ts'; import { ordinal } from './ordinal.ts'; import { plural } from './plural.ts'; import { empty, hyphen, space } from './unicode.ts'; /** * Returns the English word representation of a fractional denominator. * * Special cases: * - Returns "half" for denominator 2. * - Returns "quarter" for denominator 4. * - For other denominators, returns the alphabetic ordinal form, removing a leading "one " if present. * @param denominator - The denominator of the fraction. * @returns The word representation of the fractional denominator. * @internal */ function fractionWord(denominator: number): string { if (denominator === 2) { return 'half'; } if (denominator === 4) { return 'quarter'; } const words = ordinal(denominator, { output: 'alphabetic' }); return words.startsWith('one ') ? words.slice(4) : words; } /** * Converts a given number, represented as a `DeconstructedNumber`, into its alphabetic fraction form. * The output is a string representing the number as an alphabetic integer and fraction (e.g., "three-fourths"), * or `null` if the numerator is zero. * @param input - The deconstructed number to be converted into an alphabetic fraction. * @param options - Numbering options that influence the formatting and construction of the output. * @returns The alphabetic fraction as a string, or `null` if the numerator is zero. * @internal */ export function fabricateAlphabeticFraction( input: DeconstructedNumber, options: Numbering, ): string | null { const { numerator, denominator } = deriveFraction(input, options); if (numerator === 0) { return null; } const fractionPart = plural(fractionWord(denominator), numerator); const integerPart = fabricateAlphabeticInteger(numerator, { output: { integer: 'alphabetic', fraction: 'alphabetic', }, and: empty, hyphen: space, tolerance: 0.01, denominators: 'common', precision: 9, ordinal: false, shift: false, }); return `${integerPart}${hyphen}${fractionPart}`; } |