Properties
Static AndFraction
And
Fraction: Translator = newRegexTranslator(/^(.*)\s+and\s+(an?|one)\s+(half|third|fourth|fifth|sixth|seventh|eighth|nineth|tenth)\s*(.*)/i,(matches, vars) => {let prefix: string = matches[ 1 ];let units: string = matches[ 4 ];let value: Value = Parse.valueFromString( prefix + units );let fractionName: string = matches[ 3 ].toLowerCase();let fraction: Value = vars[ fractionName ];return value.add( fraction ).output( Core.globalOutput );}, {half: Value.fromFraction(1, 2),third: Value.fromFraction(1, 3),fourth: Value.fromFraction(1, 4),fifth: Value.fromFraction(1, 5),sixth: Value.fromFraction(1, 6),seventh: Value.fromFraction(1, 7),eighth: Value.fromFraction(1, 8),nineth: Value.fromFraction(1, 9),tenth: Value.fromFraction(1, 10)})
Static FractionOfNumber
Fraction
OfNumber: Translator = newRegexTranslator(/^(an?\s+|one|)(half|third|fourth|fifth|sixth|seventh|eighth|nineth|tenth)\s+(a\s+|an\s+|of\s+an?\s+|of\s+)(.*)/i,(matches, vars) => {let remaining: string = matches[ 4 ];let parsed: Value = Parse.valueFromString( remaining );let fractionName: string = matches[ 2 ].toLowerCase();let fraction: Value = vars[ fractionName ];return parsed.mul( fraction ).output( Core.globalOutput );}, {half: Value.fromFraction(1, 2),third: Value.fromFraction(1, 3),fourth: Value.fromFraction(1, 4),fifth: Value.fromFraction(1, 5),sixth: Value.fromFraction(1, 6),seventh: Value.fromFraction(1, 7),eighth: Value.fromFraction(1, 8),nineth: Value.fromFraction(1, 9),tenth: Value.fromFraction(1, 10)})
Static NumberWords
Number
Words: Translator = newRegexTranslator(/^(an?\s+|)(one|two|three|four|five|six|seven|eight|nine|ten|eleven|twelve|dozen|thirteen|fourteen|fifteen|sixteen|seventeen|eighteen|nineteen|twenty|thirty|fourty|fifty|sixty|seventy|eighty|ninety)\s+(.*)/i,(matches, vars) => {let wordName: string = matches[ 2 ];let remaining: string = matches[ 3 ];return vars[ wordName ] + ' ' + remaining;}, {one: '1',two: '2',three: '3',four: '4',five: '5',six: '6',seven: '7',eight: '8',nine: '9',ten: '10',eleven: '11',twelve: '12',dozen: '12',thirteen: '13',fouteen: '14',fifteen: '15',sixteen: '16',seventeen: '17',eighteen: '18',nineteen: '19',twenty: '20',thirty: '30',fourty: '40',fifty: '50',sixty: '60',seventy: '70',eighty: '80',ninety: '90'})
Static Quantity
Quantity
: Translator = newRegexTranslator(/^\((.*)\)(.*)$/,(matches) => {let quantity: string = matches[ 1 ];let unit: string = matches[ 2 ];return quantity + unit;})
Static QuantityValue
Quantity
Value: Translator = newRegexTranslator(/^\s*((-?\d*)(\s+(\d+))?(\s*\/\s*(\d+)|\.(\d+)|))\s*\(\s*((-?\d*)(\s+(\d+))?(\s*\/\s*(\d+)|\.(\d+)|)\s*(.*))\s*\)\s*$/i,(matches) => {let quantityInput: string = matches[ 1 ];let quantity: Value = Parse.valueFromString( quantityInput );let alternativeInput: string = matches[ 8 ];let alternative: Value = Parse.valueFromString( alternativeInput );return alternative.mul( quantity ).output( Core.globalOutput );})
Methods
Static translate
- translate(input: string): string
-
Parameters
Returns string
The translated string.
The class which holds Translators to manipulate user input into something more understandable to the Parse class.