Options
All
  • Public
  • Public/Protected
  • All
Menu

The class which holds Translators to manipulate user input into something more understandable to the Parse class.

Hierarchy

  • Translations

Index

Properties

Static AndFraction

AndFraction: 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)})

A translator which takes a word which represents a fraction and multiplies it by the following value.

Examples:

  • 23 and a half eggs
  • one and a half acres
  • 23 and a third
  • 12 and one fourth

Static FractionOfNumber

FractionOfNumber: 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)})

A translator which takes a word which represents a fraction and multiplies it by the following value.

Examples:

  • a third of an acre
  • half a dozen eggs
  • a seventh of a mile

Static NumberWords

NumberWords: 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'})

A translator which takes a word which represents a number and converts it the respective number.

Examples:

  • one [unit]
  • dozen [unit]
  • an eleven [unit]

Static Quantity

Quantity: Translator = newRegexTranslator(/^\((.*)\)(.*)$/,(matches) => {let quantity: string = matches[ 1 ];let unit: string = matches[ 2 ];return quantity + unit;})

A translator which takes the amount in parenthesis and moves it out.

Examples:

  • (one and a half) acre
  • (12) tacos

Static QuantityValue

QuantityValue: 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 );})

A translator which takes the amount in parenthesis and moves it out.

Examples:

  • 1 (6 ounce)
  • 5 (3 liter)

Static registered

registered: Translator[] = []

An array of translators that have been registered.

see

Translations.add

Methods

Static add

  • Adds the given translator to the list of registered translators. This translator will be called last.

    Parameters

    • translator: Translator

      The function which translates user input.

    Returns void

Static addDefaults

  • addDefaults(): void
  • Adds all translators in the library to be available when parsing.

    Returns void

Static translate

  • translate(input: string): string
  • Translates the user input based on the registered translators and returns the final string ready to be parsed.

    Parameters

    • input: string

      The input to translate.

    Returns string

    The translated string.

Legend

  • Module
  • Object literal
  • Variable
  • Function
  • Function with type parameter
  • Index signature
  • Type alias
  • Enumeration
  • Enumeration member
  • Property
  • Method
  • Interface
  • Interface with type parameter
  • Constructor
  • Property
  • Method
  • Index signature
  • Class
  • Class with type parameter
  • Constructor
  • Property
  • Method
  • Accessor
  • Index signature
  • Inherited constructor
  • Inherited property
  • Inherited method
  • Inherited accessor
  • Protected property
  • Protected method
  • Protected accessor
  • Private property
  • Private method
  • Private accessor
  • Static property
  • Static method

Generated using TypeDoc