| // |
| // Copyright 2014-26 Volker Sorge |
| // |
| // Licensed under the Apache License, Version 2.0 (the "License"); |
| // you may not use this file except in compliance with the License. |
| // You may obtain a copy of the License at |
| // |
| // http://www.apache.org/licenses/LICENSE-2.0 |
| // |
| // Unless required by applicable law or agreed to in writing, software |
| // distributed under the License is distributed on an "AS IS" BASIS, |
| // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| // See the License for the specific language governing permissions and |
| // limitations under the License. |
| |
| /** |
| * @file Miscellaneous and experimental API functions. |
| * @author volker.sorge@gmail.com (Volker Sorge) |
| */ |
| |
| import { KeyCode } from '../common/event_util.js'; |
| import { processString, output, keypress } from '../common/processor_factory.js'; |
| |
| /** |
| * Translates a number into its word form for the current locale. |
| * |
| * @param expr The number |
| * @returns The word form of the number. |
| */ |
| export function number(expr: string): string { |
| return processString('number', expr); |
| } |
| |
| /** |
| * Translates a number into its word ordinal for the current locale. |
| * |
| * @param expr The number |
| * @returns The word ordinal of the number. |
| */ |
| export function ordinal(expr: string): string { |
| return processString('ordinal', expr); |
| } |
| |
| /** |
| * Translates a number into a numeric ordinal for the current locale. |
| * |
| * @param expr The number |
| * @returns The numeric ordinal of the number. |
| */ |
| export function numericOrdinal(expr: string): string { |
| return processString('numericOrdinal', expr); |
| } |
| |
| /** |
| * Translates a vulgar fraction into its word representation for the current |
| * locale. |
| * |
| * @param expr The number with divisor slash. |
| * @returns The vulgar fraction in words. |
| */ |
| export function vulgar(expr: string): string { |
| return processString('vulgar', expr); |
| } |
| |
| // These are still considered experimental. |
| /** |
| * Walk a math expression provided by an external system. |
| * |
| * @param expr The string containing a MathML representation. |
| * @returns The initial speech string for that expression. |
| */ |
| export function walk(expr: string): string { |
| return output('walker', expr); |
| } |
| |
| /** |
| * Moves in the math expression that is currently being walked. |
| * |
| * @param direction The direction of the move |
| * given either as string or keycode. |
| * @returns The speech string generated by the walk. Null if a boundary |
| * is hit. |
| */ |
| export function move(direction: KeyCode | string): string | null { |
| return keypress('move', direction); |
| } |