Options
All
  • Public
  • Public/Protected
  • All
Menu

A class which contains a parsed number or fraction.

Hierarchy

  • Value

Index

Constructors

constructor

  • new Value(value: number, num: number, den: number, unit: string, group: Group, rate: string, rateGroup: Group): Value

Properties

den

den: number

The denominator parsed or calculated if this is a fraction, otherwise this will be equal to 1.

group

group: Group

The group determined based on the unit.

num

num: number

The numerator parsed or calculated if this is a fraction, otherwise this will be equal to Value.value.

rate

rate: string

The unit parsed or chosen for rate to be output to the user.

rateGroup

rateGroup: Group

The group determined based on the rate.

unit

unit: string

The unit parsed or chosen to be output to the user.

value

value: number

The number parsed or num / den if a fraction was parsed.

Static INVALID

INVALID: Value = new Value(Number.NaN, Number.NaN, 1, '', null, '', null)

A value instance which contains invalid numbers.

Accessors

calculated

calculated:

Returns the number which represents the fraction in the value. There may be a difference between this value and the number when the fraction is calculated from the denominators of the group.

ceil

ceil:

Returns the ceiling of the number in this value.

classScaled

classScaled:

Returns the number of this value relative to the first base unit of it's class.

distance

distance:

Returns the absolute distance the number of this value is from the fraction numerator and denominator determined. If this value is not a fraction then this should return zero.

error

error:

Returns the signed distance the number of this value is from the fraction numerator and denominator determined. If this value is not a fraction then this should return zero.

floor

floor:

Returns the floor of the number in this value.

isDecimal

isDecimal:

Returns true if this value is a number and not a fraction.

isFraction

isFraction:

Returns true if this value is a fraction with a numerator and denoninator.

isRate

isRate:

Returns true if this value is a rate.

isSingular

isSingular:

Returns true if this value is singular.

see

Functions.isSingular

isValid

isValid:

Returns true if this value was successfully parsed from some input.

isZero

isZero:

Returns true if this value is zero.

mixedNum

mixedNum:

Returns the numerator for the mixed fraction of this value. If this value is not a fraction then the numerator is returned.

mixedWhole

mixedWhole:

Returns the whole number for the mixed fraction of this value. If this value is not a fraction 0 is returned.

remainder

remainder:

Returns the fractional part of the number in this value.

scaled

scaled:

Returns the number of this value relative to the base unit.

truncate

truncate:

Returns the truncated number in this value taking into account it's sign.

Methods

add

  • Calculates the sum of this value and the given addend scaled by some factor. This is equivalent to result = this + (addend * scale).

    Parameters

    • addend: Value

      The value to add to this.

    • Default value scale: number = 1

      The factor to scale the addend by before adding it to this.

    Returns Value

    A new instance.

conversions

  • conversions(transform: Transform, reverse: boolean, callback: function): void
  • Determines the available conversions of this value for all groups that are valid for the given transform.

    see

    Group.matches

    Parameters

    • transform: Transform

      Transform which controls the units and values acceptable.

    • reverse: boolean

      Whether to iterate from largest units to smallest units (true), or from smallest to largest (false).

    • callback: function

      The function to invoke for each valid conversion.

        • (transformed: Value, index: number): void
        • Parameters

          • transformed: Value

            The conversion calculated.

          • index: number

            The index of the conversion during iteration.

          Returns void

    Returns void

convertTo

  • Converts this value to the given group and returns the result.

    Parameters

    • to: Group

      The group to convert to.

    • Default value rate: Group = null

      The group for the rate.

    Returns number

    The converted value or the number of this value if there's no group.

convertToValue

  • Converts this value to the given group and returns a new value. The new value will attempted to be converted to a fraction.

    Parameters

    • group: Group

      The group to convert to.

    • Default value rate: Group = null

      The group for the rate.

    Returns Value

    A new value.

copy

fractioned

  • Returns a version of this value as a fraction.

    Returns Value

    A new value or the reference to this instance if it's a fraction.

getRateScale

  • getRateScale(rate: Group): number
  • Calculates the scale necessary to switch this value from the current rate to the provided rate.

    Parameters

    • rate: Group

      The rate group.

    Returns number

    The calculated scale.

isMatch

  • isMatch(other: Value): boolean
  • Determines whether the given value is compatible with this value to perform operations with.

    Parameters

    • other: Value

      The value to test against.

    Returns boolean

    True if the given value has compatible unit and rate groups.

mul

  • Calculates a new value by multiplying this by a given value. This is equivalent to result = this * scale.

    Parameters

    • scale: Value

      The value to scale this instance by.

    Returns Value

    A new instance.

normalize

  • Returns a value based on this value with the unit that best represents the value. What is best is typically related to the magnitude of the value. Really small and really large values are harder for people to comprehend so the unit which results in the most normal looking value is determined.

    see

    Value.conversions

    see

    Core.isMoreNormal

    Parameters

    • transform: Transform

      Transform which controls the units and values acceptable.

    • forOutput: Output

      The output that may be used so the most normal looking value can be determined.

    Returns Value

    The most normal value found.

numbered

  • Returns a version of this value as a number.

    Returns Value

    A new value or the reference to this instance if it's a number.

output

  • Converts this value to a string with the given output options taking into account the global options.

    see

    Output

    Parameters

    • Optional options: OutputInput

      The options to override the global output options.

    Returns string

    The string representation of this instance.

preferred

  • Returns a version of this value with the preferred unit.

    see

    Group.preferredUnit

    Returns Value

    A new value or the reference to this instance if it's groupless.

scale

  • scale(scale: number): Value
  • Calculates a new value by multiplying this by a given factor. This is equivalent to result = this * scale.

    Parameters

    • scale: number

      The factor to scale this instance by.

    Returns Value

    A new instance.

sub

  • Calculates the difference between this value and the subtrahend scaled by some factor. This is equivalent to result = this - (subtrahend * scale).

    Parameters

    • subtrahend: Value

      The value to subtract from this.

    • Default value scale: number = 1

      The factor to scale the subtrahend by before subtraction.

    Returns Value

    A new instance.

truncated

  • Returns the truncated version of this value. That's a value where the number is a whole number.

    Returns Value

    A new value.

units

  • Returns the units of this value as a string based on the global output options.

    see

    Output

    Parameters

    • Optional options: OutputInput

      The options to override the global output options.

    Returns string

    The string representation of the units of this value.

zero

  • Returns a value equivalent to zero with the unt and group of this instance.

    Returns Value

    A new value.

Static fromFraction

  • fromFraction(num: number, den: number, unit?: string, group?: Group, rate?: string, rateGroup?: Group): Value
  • Returns a Value instance for a given fraction specified by a numerator and denominator.

    Parameters

    • num: number

      The numerator of the fraction.

    • den: number

      The denominator of the fraction.

    • Default value unit: string = ""

      The unit, if any, of the fraction.

    • Default value group: Group = null

      The group which matches the unit.

    • Default value rate: string = ""
    • Default value rateGroup: Group = null

    Returns Value

    A new instance.

Static fromNumber

  • fromNumber(value: number, unit?: string, group?: Group, rate?: string, rateGroup?: Group): Value
  • Returns a Value instance which is a number with the optional unit and group.

    Parameters

    • value: number

      The number.

    • Default value unit: string = ""

      The unit, if any, of the number.

    • Default value group: Group = null

      The group which matches the unit.

    • Default value rate: string = ""
    • Default value rateGroup: Group = null

    Returns Value

    A new instance.

Static fromNumberForGroup

  • Returns a Value instance which tries to be a fraction based on the denominators of the group. If a valid fraction could not be found then the instance returned will be a number value. Since a unit is not passed here, the preferred unit of the group is used as the unit of the value.

    Parameters

    • value: number

      The number to try to find a fraction for.

    • group: Group

      The group for the unit and also the denominators to try.

    • rateGroup: Group

      The group for the rate.

    Returns Value

    A new instance.

Static fromNumberWithDenominators

  • fromNumberWithDenominators(value: number, denominators: number[], unit?: string, group?: Group, rate?: string, rateGroup?: Group): Value
  • Returns a Value instance which tries to be a fraction based on the denominators of the group. If a valid fraction could not be found then the instance returned will be a number value.

    Parameters

    • value: number

      The number to try to find a fraction for.

    • denominators: number[]

      The array of denominators to try.

    • Default value unit: string = ""

      The unit, if any, of the number.

    • Default value group: Group = null

      The group which matches the unit.

    • Default value rate: string = ""
    • Default value rateGroup: Group = null

    Returns Value

    A new instance.

Static fromNumberWithRange

  • fromNumberWithRange(value: number, unit?: string, group?: Group, minDen?: number, maxDen?: number, rate?: string, rateGroup?: Group): Value
  • Returns a Value instance which tries to be a fraction given a range of denominators. If the number is already whole or a fraction close enough to the number cannot be found a value which is a number is returned.

    Parameters

    • value: number

      The number to try to find a fraction for.

    • Default value unit: string = ""

      The unit, if any, of the number.

    • Default value group: Group = null

      The group which matches the unit.

    • Default value minDen: number = 1

      The starting denominator to inclusively try.

    • Default value maxDen: number = 100

      The last denominator to inclusively try.

    • Default value rate: string = ""
    • Default value rateGroup: Group = null

    Returns Value

    A new instance.

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