Options
All
  • Public
  • Public/Protected
  • All
Menu

Retirement Simulator - v0.2.0

Retirement Simulator

Retirement-simulator library. It is intended to be used in an exploratory manner in an ObservableHQ notebook.

Key Modelling Concepts

Balance Sheet

These concepts are what you have; together, they determine your net worth.

let net_worth = assets - liabilities
  • Asset: What you own
  • Liability: What you owe. Loans, mortages, debts.

Cash Flow

Cash flow is money in or out. Together, they determine your net income, which can be positive or negative.

let net_income = income - expense

While technically, asset growth is reinvested investment income, we do not need to model it that way, as it would complicate the picture with details. With investments in a protected tax-deferred retirement account, with dividends and interest automatically reinvested, it is simpler to model as compound growth. However, nothing prevents you from modeling it as an income stream adding to the asset.

Other

Interfaces

The key modeling classes have corresponding interface types, to facilitate working with the raw data without instantiation as a class instance.

Other Facilities

  • color Provides a stable set of colors for graphing.
  • Interpolated actuary data SS_2017.
  • [[calendar]] provides utilities for working with time in relevant ways.

Index

Namespaces

Enumerations

Classes

Interfaces

Type aliases

Variables

Functions

Type aliases

ActionData

ActionData<A>: A extends "begin" | "end" ? {} : A extends "receive" | "deposit" | "withdraw" | "interest" | "pay" ? TransferAction : A extends "age" ? AgeAction : never

Type parameters

ActionItem

ActionItem<A>: A extends "begin" | "end" ? IItem : A extends "receive" ? IItem<"income"> : A extends "deposit" ? IItem<"asset"> : A extends "interest" ? IItem<"asset" | "liability"> : A extends "withdraw" | "deposit" ? IItem<"asset" | "income" | "liability"> : A extends "pay" ? IItem<"expense" | "liability" | "incomeTax"> : A extends "age" ? IItem<"person"> : never

Type parameters

ActuaryAnnualData

ActuaryAnnualData: { age: number; female: ActuaryDatum; male: ActuaryDatum }

Actuary data for one age, for both sexes.

Type declaration

ActuaryDatum

ActuaryDatum: { n: number; p: Probability; years: number }

Type declaration

  • Readonly n: number

    Number of people surviving to this age.

  • Readonly p: Probability

    Probability of surviving one year (birthday to next birthday).

  • Readonly years: number

    Life expectency from this birthday.

Age

Age: Tagged<"Age">

Age (usually of people)

AgeGroup

AgeGroup: Exclude<keyof AgeGroups, "age">

AllItems

AllItems: { [ K in Type]: ItemTableType<K> }

AnyRow

AnyRow: Partial<Omit<IAsset, OmitKeys>> & Partial<Omit<ILiability, OmitKeys>> & Partial<Omit<IExpense, OmitKeys>> & Partial<Omit<IIncome, OmitKeys>> & Partial<Omit<IIncomeStream, OmitKeys>> & Partial<Omit<IIncomeTax, OmitKeys>> & Partial<Omit<IText, OmitKeys>> & Partial<Omit<IPerson, OmitKeys>> & Omit<IItem, OmitKeys> & { name: Name; type: Type }

AssetName

AssetName: Name

BalanceType

BalanceType: "asset" | "liability"

Byte

Byte: Tagged<"Byte"> | Tagged<"Integer">

An integer between 0 and 255, inclusive.

CalendarInterval

CalendarInterval: { [ k in keyof typeof CalendarUnit]?: Integer }

A specification of a length of time in units specified as CalendarUnit. e.g.:

const interval = {month: 3}; // 3 months

CalendarLength

CalendarLength: CalendarInterval & { totalDays: Integer }

Measured length of time. This incorporates a {@link CalenderInterval} and adds a measured {@link CalendarLength.totalDays} that measures the exact number of days.

CashFlowType

CashFlowType: "income" | "expense" | "incomeStream" | "incomeTax"

Category

Category: Tagged<"Category", string>

{link @Tagged} type for category names.

ChangeFn

ChangeFn<T>: (value: T) => void | DisposeFn<void>

Type parameters

  • T

Type declaration

Channel

Channel: string | Scale | ((a: any) => any)

Color

Color: Tagged<"Color", `#${string}`>

Colors are strings in the form #rrggbb.

Column

Column: string | [name: string] | [name: string, type: ColumnType] | [name: string, align: Align] | [name: string, format: Formatter] | [name: string, fixed: boolean] | [name: string, format: Formatter, align: Align] | [name: string, format: Formatter, fixed: boolean] | ColumnSpec

Description of a table column

ComputeTaxParams

ComputeTaxParams: { state: StateCode; year: Year } & TaxData

Parameters to pass to computeTax.

Constructor

Constructor<T, P>: abstract new (...args: P) => T

Type parameters

  • T: {}

  • P: any[] = any[]

Type declaration

    • abstract new (...args: P): T
    • Parameters

      • Rest ...args: P

      Returns T

Converters

Converters: { [ T in RowLabel]: (a: any) => AnyRow[T] } & { src: any; temporal: any }

Degrees

Degrees: Tagged<"Degrees">

A number between 0 and 360, inclusive of 0, exclusive of 360.

Other values are mathematically valid, but are constrained here for implementation convenience and reliability. Use mod360 to coerce to this range.

DisposeFn

DisposeFn<T>: (value: T) => void

Type parameters

  • T

Type declaration

    • (value: T): void
    • Parameters

      • value: T

      Returns void

ExpenseName

ExpenseName: Name

ExtractorFn

ExtractorFn<T, K>: (item: T) => K

Type parameters

  • T

  • K

Type declaration

    • (item: T): K
    • Parameters

      • item: T

      Returns K

Formatter

Formatter: (arg: any) => string

Type declaration

    • (arg: any): string
    • Parameters

      • arg: any

      Returns string

HSV

HSV: { h: Degrees; s: Unit; v: Unit } & Tag<"HSV">

HSVSpec

HSVSpec: { h: number; s: number; v: number }

Type declaration

  • h: number
  • s: number
  • v: number

IAge

IAge: Tagged<"IAge">

Integer age (usually of people)

IFAsset

IFAsset: ItemImpl<"asset">

IFExpense

IFExpense: ItemImpl<"expense">

IFIncome

IFIncome: ItemImpl<"income">

IFIncomeStream

IFIncomeStream: ItemImpl<"incomeStream">

IFIncomeTax

IFIncomeTax: ItemImpl<"incomeTax">

IFLiability

IFLiability: ItemImpl<"liability">

IFPerson

IFPerson: ItemImpl<"person">

IFScenario

IFScenario: ItemImpl<"scenario">

IFText

IFText: ItemImpl<"text">

IItemState

IItemState<T>: { date: Date; id: Id<T>; item: ItemImpl<T>; step: CalendarStep; type: T }

Common fields for item states.

Type parameters

Type declaration

Id

Id<T>: `${T}/${Name}`

Type parameters

IncomeName

IncomeName: Name

IncomeSourceType

IncomeSourceType: BalanceType | "income"

IncomeStreamBoundSpec

IncomeStreamBoundSpec: IncomeStreamId | IncomeStreamBoundSpec[] | { [ K in IncomeStreamId]: Constraint }

IncomeStreamId

IncomeStreamId: `income/${IncomeName}` | `asset/${AssetName}` | `liability/${LiabilityName}` | `incomeStream/${IncomeStreamName}`

IncomeStreamName

IncomeStreamName: Name

IncomeStreamSpec

Specs are prrovided as JSON. This describes the input form. See IncomeStreamBoundSpec for the bound form.

Initable

Initable<T>: { -readonly [ P in keyof T]?: T[P] }

Type parameters

  • T

InputColumn

InputColumn: Capitalize<RowLabel>

InputRow

InputRow: { [ k in Capitalize<RowLabel>]: AnyRow[Uncapitalize<k>] }

Integer

Integer: Tagged<"Integer">

An integer.

ItemImpl

ItemImpl<T>: RowType<T> & ItemMethods<T> & ItemImplFields<T> & ItemImplMethods<T> & TemporalItemImpl<T> & { id: Id<T>; prettyName: string; scenario: ItemImpl<"scenario"> }

The model implementation for each Type.

Type parameters

ItemImplFields

ItemImplFields<T>: T extends keyof ItemImplFieldDefs ? ItemImplFieldDefs[T] : {}

Additional fields found in specific implementation types.

Type parameters

ItemImplMethods

ItemImplMethods<T>: T extends keyof ItemImplMethodDefs ? ItemImplMethodDefs[T] : {}

Type parameters

ItemKey

ItemKey<I>: I extends IItem<infer T> ? T : never

Extract the Type keyword from an IITem-based type.

Type parameters

ItemState

ItemState<T>: IItemState<T> & StepperState<T>

An item's full state.

Type parameters

ItemTable

ItemTable: { [ K in Type]: ItemTableType<K> }

ItemType

ItemType<T>: ItemTypes[T] & { type: T }

Type parameters

ItemTypeOf

ItemTypeOf<I>: I extends Named<infer T> ? T : never

Type parameters

KeyFn

KeyFn<T, K>: ExtractorFn<T, K>

Alias denoting ExtractorFns used to obtain keys

Type parameters

  • T

  • K

LiabilityName

LiabilityName: Name

MergeFn

MergeFn<K, I, R>: (key: K) => Merge<K, I, R>

Type parameters

  • K

  • I: Record<keyof any, any>

  • R

Type declaration

    • For aggregation, k

      Parameters

      • key: K

      Returns Merge<K, I, R>

MergeObjectSpec

MergeObjectSpec<K, V, I, R>: { [ F in keyof V]: MergeFn<K, I[F], R[F]> | [F, MergeFn<K, I[F], R[F]>] }

Type parameters

  • K

  • V: Record<keyof any, any>

  • I: Record<keyof V, any>

  • R: Record<keyof V, any>

MonetaryType

MonetaryType: BalanceType | CashFlowType

Money

Money: Tagged<"Money">

An amount of money.

Name

Name: string

Offset

Offset: "expand" | "normalize" | "center" | "silhouette" | "whiggle" | null

PayableType

PayableType: "expense" | "liability" | "incomeTax"

Probability

Probability: Tagged<"Probability">

The unit interval: a number between 0 and 1, inclusive.

RGB

RGB: { b: Byte; g: Byte; r: Byte } & Tag<"RGB">

RGBSpec

RGBSpec: { b: number; g: number; r: number }

Type declaration

  • b: number
  • g: number
  • r: number

RampifyKeys

RampifyKeys<SEQ>: { cmp?: SortFn<SEQ>; post?: SEQ; pre?: SEQ }

Type parameters

  • SEQ

Type declaration

  • Optional cmp?: SortFn<SEQ>
  • Optional post?: SEQ
  • Optional pre?: SEQ

Rate

Rate: Tagged<"Rate">

Interest/growth rate as a fraction (not percent).

Reference

Reference<Str>: `@${Str}`

A reference to an asset, income, or loan.

Because names are not costrained, the compiler won't actually enforce this; it only serves to document it for humans.

Type parameters

  • Str: string

Relaxed

Relaxed<T, Tag>: T extends Tagged<Tag, infer Base> ? Base : T extends Tagged<Tag, infer Base> ? Base | undefined : T extends {} ? { [ k in keyof T]: Relaxed<T[k], Tag> } : T

Relax the type checking on tagged types. You can use typeguards and validators to convert back to the unrelaxed version by checking.

Type parameters

  • T

    the type being relaxed.

  • Tag: string = TagOf<T>

    the tag being removed. Defaults for simple types, must be supplied for recursive.

RowLabel

RowLabel: keyof AnyRow

RowType

RowType<T>: RowTypes[T]

Type parameters

ScenarioName

ScenarioName: Name

SeriesName

SeriesName: Name

Sex

Sex: "male" | "female"

Sex for actuarial purposes.

Side

Side: "top" | "bottom" | "left" | "right"

SortFn

SortFn<T>: (a: T, b: T) => -1 | 0 | 1

Type parameters

  • T

Type declaration

    • (a: T, b: T): -1 | 0 | 1
    • Parameters

      • a: T
      • b: T

      Returns -1 | 0 | 1

Sources

Sources: { [ k in Id<IncomeSourceType>]?: Money }

State

State<T>: ItemImpl<T> & IState<T>

Type parameters

StateCode

StateCode: keyof typeof STATES

StateMixinConstructor

StateMixinConstructor<T, Base, P>: Constructor<InstanceType<Base> & IState<T> & { [toStringTag]: string }, P>

Type parameters

StateName

StateName: typeof STATES[StateCode]

Stepper

Stepper<T>: Generator<StepperState<T>, void, ItemState<T>>

A generator that produces updated item states,

Type parameters

StepperState

StepperState<T>: { asset: { interest: Money; rate: Rate; used?: Money; value: Money }; expense: { payment: Money; value: Money }; income: { payment: Money; used?: Money; value: Money }; incomeStream: {}; incomeTax: {}; liability: { interest: Money; payment: Money; principal: Money; rate: Rate; used?: Money; value: Money }; person: { age: Age; expected: number; mortality: Probability; n: number; survival: Probability }; scenario: {}; text: { text: string } }[T]

The type returned by a stepper function. This includes just the state provided by the stepper function; the full state is StateItem.

Type parameters

Tag

Tag<T>: { [typetag]: T }

Create a tag for a tagged type. A tagged type is a compile-time-only thing that limits the intensional use of a type, and traces type validations.

Type parameters

  • T: string

Type declaration

  • [typetag]: T

TagOf

TagOf<T>: T extends Tag<infer Tag> ? Tag : never

The tag (as a string literal type) of a tagged type.

Type parameters

  • T

Tagged

Tagged<TagType, Base>: Base & Tag<TagType>

Create a taggged type. A tagged type is is a compile-time-only thing that limits the intensional use of a type, and traces type validations.

Type parameters

  • TagType: string

  • Base = number

TaxCalculation

TaxCalculation: (data: TaxData) => TaxResult

Type declaration

TaxIncomeCategory

TaxIncomeCategory: keyof TaxIncome

TaxRate

TaxRate: Tagged<"TaxRate">

A tax rate (as a fraction, not percentage).

TaxStatus

TaxStatus: "single" | "married" | "separately" | "head"

TaxTableItem

TaxTableItem: { [ k in TaxStatus]?: Money } & { rate: TaxRate }

TimeLineAction

TimeLineAction: "begin" | "end" | "receive" | "deposit" | "withdraw" | "interest" | "pay" | "age"

TimeLineItem

TimeLineItem<A>: TimeLineItemBase<A> & ActionData<A>

Type parameters

Type

Type: `${Types}`

TypeAssertion

TypeAssertion<T, B>: (n: B) => Tagged<T, B>

Type parameters

  • T: string

  • B

Type declaration

    • Assert that the argument n is of the type Tagged<T,B>. The compiler's type inferencing is informed that the return value has been validated to be of that type.

      Parameters

      • n: B

      Returns Tagged<T, B>

TypeCoercion

TypeCoercion<T>: (n: any) => T

Type parameters

  • T

Type declaration

    • (n: any): T
    • A function that coerces to a specified type.

      Parameters

      • n: any

      Returns T

TypeGuard

TypeGuard<T>: (n: any) => n is T

Type parameters

  • T

Type declaration

    • (n: any): n is T
    • A type guard. Returns true if the argument n satisfies the conditions to be of type T, and informs the compiler's type inferencing engine.

      Parameters

      • n: any

      Returns n is T

Unit

Unit: Tagged<"Unit">

The unit interval: a number between 0 and 1, inclusive.

Untag

Untag<T>: Omit<T, typeof typetag>

The base type of T without the Tag.

Type parameters

ValidationSpec

ValidationSpec<T>: { [ k in keyof T & string]: TypeCoercion<T[k]> }

Type parameters

  • T: any

ValueFn

ValueFn<T, K>: ExtractorFn<T, K>

Alias denoting ExtractorFns used to obtain values.

Type parameters

  • T

  • K

Weight

Weight: number

Writeable

Writeable<T>: { -readonly [ P in keyof T]: T[P] }

Type parameters

  • T

Year

Year: Tagged<"Year">

Year as an integer.

Variables

$0

$0: Money = ...

Zero Money.

ANNUAL_PAYMENT_PERIODS

ANNUAL_PAYMENT_PERIODS: { [ k in CalendarUnit]: number } = ...

For each CalendarUnit, the number of occurrances of that unit per year.

ColTypes

ColTypes: { [ K in keyof typeof coltypes]: ColumnType } = coltypes

END

END: Date = ...

The default end date is 50 years from the start.

END_OF_TIME

END_OF_TIME: Date = ...

Date a century in the future.

END_OF_YEARS

END_OF_YEARS: Tagged<"Year", number> = ...

Year number a century in the future.

END_YEAR

END_YEAR: Tagged<"Year", number> = ...

Default to 50 years.

Fmt

Fmt: { [ K in keyof typeof fmt]: Formatter } = fmt

Prepackaged formatters.

Heap

Heap: typeof Heap = HeapIn

MONTH_LEMGTH

MONTH_LEMGTH: number[][] = ...

The length of each month, 0-origin, for non-leap and leap years.

MONTH_START

MONTH_START: number[][] = ...

The starting day of each month, 0-origin, for non-leap and leap years.

O

O: O

Our interface to the Observable world. This must be set before

SS_2017

SS_2017: ActuaryAnnualData[] = ...

Actuary data from the Social Security Administration based on mortality in calendar year 2017.

START

START: Date = ...

The default start date is the start of the next month.

STATES

STATES: { AK: "Alaska"; AL: "Alabama"; AR: "Arkansas"; AS: "American Samoa"; AZ: "Arizona"; CA: "California"; CO: "Colorado"; CT: "Connecticut"; DC: "District of Columbia"; DE: "Delaware"; FL: "Florida"; FM: "Federated States of Micronesia"; GA: "Georgia"; GU: "Guam"; HI: "Hawaii"; IA: "Iowa"; ID: "Idaho"; IL: "Illinois"; IN: "Indiana"; KS: "Kansas"; KY: "Kentucky"; LA: "Louisiana"; MA: "Massachusetts"; MD: "Maryland"; ME: "Maine"; MH: "Marshall Islands"; MI: "Michigan"; MN: "Minnesota"; MO: "Missouri"; MP: "Northern Mariana Islands"; MS: "Mississippi"; MT: "Montana"; NC: "North Carolina"; ND: "North Dakota"; NE: "Nebraska"; NH: "New Hampshire"; NJ: "New Jersey"; NM: "New Mexico"; NV: "Nevada"; NY: "New York"; OH: "Ohio"; OK: "Oklahoma"; OR: "Oregon"; PA: "Pennsylvania"; PR: "Puerto Rico"; PW: "Palau"; RI: "Rhode Island"; SC: "South Carolina"; SD: "South Dakota"; TN: "Tennessee"; TX: "Texas"; US: "Federal"; UT: "Utah"; VA: "Virginia"; VI: "Virgin Islands"; VT: "Vermont"; WA: "Washington"; WI: "Wisconsin"; WV: "West Virginia"; WY: "Wyoming" } = ...

US State postal codes, plus US = Federal

Type declaration

  • AK: "Alaska"
  • AL: "Alabama"
  • AR: "Arkansas"
  • AS: "American Samoa"
  • AZ: "Arizona"
  • CA: "California"
  • CO: "Colorado"
  • CT: "Connecticut"
  • DC: "District of Columbia"
  • DE: "Delaware"
  • FL: "Florida"
  • FM: "Federated States of Micronesia"
  • GA: "Georgia"
  • GU: "Guam"
  • HI: "Hawaii"
  • IA: "Iowa"
  • ID: "Idaho"
  • IL: "Illinois"
  • IN: "Indiana"
  • KS: "Kansas"
  • KY: "Kentucky"
  • LA: "Louisiana"
  • MA: "Massachusetts"
  • MD: "Maryland"
  • ME: "Maine"
  • MH: "Marshall Islands"
  • MI: "Michigan"
  • MN: "Minnesota"
  • MO: "Missouri"
  • MP: "Northern Mariana Islands"
  • MS: "Mississippi"
  • MT: "Montana"
  • NC: "North Carolina"
  • ND: "North Dakota"
  • NE: "Nebraska"
  • NH: "New Hampshire"
  • NJ: "New Jersey"
  • NM: "New Mexico"
  • NV: "Nevada"
  • NY: "New York"
  • OH: "Ohio"
  • OK: "Oklahoma"
  • OR: "Oregon"
  • PA: "Pennsylvania"
  • PR: "Puerto Rico"
  • PW: "Palau"
  • RI: "Rhode Island"
  • SC: "South Carolina"
  • SD: "South Dakota"
  • TN: "Tennessee"
  • TX: "Texas"
  • US: "Federal"
  • UT: "Utah"
  • VA: "Virginia"
  • VI: "Virgin Islands"
  • VT: "Vermont"
  • WA: "Washington"
  • WI: "Wisconsin"
  • WV: "West Virginia"
  • WY: "Wyoming"

Sort

Sort: { byName: SortFn<Named<"asset" | "liability" | "income" | "expense" | "incomeStream" | "incomeTax" | "person" | "text" | "scenario">>; byRate: SortFn<any>; byStart: SortFn<any>; byType: SortFn<Named<"asset" | "liability" | "income" | "expense" | "incomeStream" | "incomeTax" | "person" | "text" | "scenario">>; byValue: SortFn<any>; natural: <T>(a: T, b: T) => 0 | 1 | -1; null: <T>(a: T, b: T) => 0 | 1 | -1 } = ...

Collection of sort comparator functions.

Type declaration

  • byName: SortFn<Named<"asset" | "liability" | "income" | "expense" | "incomeStream" | "incomeTax" | "person" | "text" | "scenario">>
  • byRate: SortFn<any>
  • byStart: SortFn<any>
  • byType: SortFn<Named<"asset" | "liability" | "income" | "expense" | "incomeStream" | "incomeTax" | "person" | "text" | "scenario">>
  • byValue: SortFn<any>
  • natural: <T>(a: T, b: T) => 0 | 1 | -1
      • <T>(a: T, b: T): 0 | 1 | -1
      • A comparator that sorts according to the "natural" order. First by type, then by string or numerical ordering if a string, number, boolean, or symbol.

        Type parameters

        • T

        Parameters

        • a: T
        • b: T

        Returns 0 | 1 | -1

  • null: <T>(a: T, b: T) => 0 | 1 | -1
      • <T>(a: T, b: T): 0 | 1 | -1
      • A comparator that does not alter the sort order. It regards everything as equal, and thus Javascript's stable sort leaves the ordering unchanged.

        Type parameters

        • T

        Parameters

        • a: T
        • b: T

        Returns 0 | 1 | -1

        0

TAX_TABLES

TAX_TABLES: Partial<{ [ k in StateCode]: TaxYearTables }> = ...

Tax tables by state.

THIS_YEAR

THIS_YEAR: Date = ...

This year as a Date referring to January 1.

TODAY

TODAY: Date = ...

Today as a Date, starting at midnite (UTC).

VERSION

VERSION: Readonly<{ mode: string; version: string }> = ...

Information about this version.

YEAR

YEAR: Tagged<"Year", number> = ...

This year as a 4-digit number.

color_scheme

color_scheme: Color[] = ...

The supplied color scheme.

comparator

comparator: typeof comparator = ...

converters

converters: Converters = ...

Map of fields to converters to convert to the proper type (e.g. number, date, etc.)

Functions

Const $$

  • Cast (and check) a numerical value as Money.

    Parameters

    • n: number

      A number to be interpreted as a monetary value

    Returns Money

    the number, typed as Money

Const $max

  • $max(...n: number[]): Money

Const $min

  • $min(...n: number[]): Money

Const HSVtoRGB

Const RGBtoHSV

StateMixin

Const Throw

  • Throw(s: string | Error): never
  • Function that throws its argument.

    Parameters

    • s: string | Error

      a string or an Error.

    Returns never

UTC

  • UTC(date: string): Date
  • UTC(year: string | number, month?: number, day?: number): Date
  • Parse a UTC date.

    see

    parseDate

    Parameters

    • date: string

      a string.

    Returns Date

    a Date, constrained to 00:00:00.000 UTC.

  • Construct a UTC Date

    Parameters

    • year: string | number
    • Optional month: number

      (0-11), default = 0 (January)

    • Optional day: number

      (1-31), default = 1

    Returns Date

    a Date, constrained to 00:00:00.000 UTC.

actuary

  • Obtain actuarial data for a person on a particular date.

    Interpolates from the actuarial tables. (Linear interpolation for now, although that is not strictly correct),

    Parameters

    • spouse: IPerson
    • date: Date

      The date on which the age is desired.

    Returns ActuaryDatum

  • Obtain actuarial data for a specified age and sex.

    Interpolates from the actuarial tables. (Linear interpolation for now, although that is not strictly correct),

    Parameters

    • age: number
    • sex: Sex

    Returns ActuaryDatum

Const addSubSources

Const aggregate

applyRateSimpleMonthly

Const as

  • A type-inferred cast to a Tagged type. This is primarily intended for use with constants, where supplying the correct type can be determined by inspection

    Generally the type parameters will be inferred.

    let foo: Integer = as(1);
    

    Type parameters

    • T: string

      the tag type

    • B

      the base (untagged) type.

    Parameters

    • n: B

      a value in the base type

    Returns Tagged<T, B>

    n cast to be of the expected Tagged<T,B> type.

asAge

  • asAge(n: number): Tagged<"Age", number>
  • Assert that the argument n is of the type Tagged<T,B>. The compiler's type inferencing is informed that the return value has been validated to be of that type.

    Parameters

    • n: number

    Returns Tagged<"Age", number>

asAlign

asAsset

asBoolean

  • asBoolean(a: any): boolean

asByte

  • asByte(n: number): Tagged<"Byte", number>
  • Assert that the argument n is of the type Tagged<T,B>. The compiler's type inferencing is informed that the return value has been validated to be of that type.

    Parameters

    • n: number

    Returns Tagged<"Byte", number>

asCalendarInterval

asCalendarLength

asCalendarPeriod

asCalendarStep

asCalendarUnit

Const asColor

  • asColor(c: string): Color

asColumn

asColumnSpec

  • asColumnSpec(a: any): { align: Align; fixed?: boolean; format: Formatter; name: any }

asColumnType

asDate

  • asDate(a: any): Date

asDegrees

  • asDegrees(n: number): Tagged<"Degrees", number>
  • Assert that the argument n is of the type Tagged<T,B>. The compiler's type inferencing is informed that the return value has been validated to be of that type.

    Parameters

    • n: number

    Returns Tagged<"Degrees", number>

asExpense

asFormatter

Const asHSV

asIAge

  • asIAge(n: number): Tagged<"IAge", number>
  • Assert that the argument n is of the type Tagged<T,B>. The compiler's type inferencing is informed that the return value has been validated to be of that type.

    Parameters

    • n: number

    Returns Tagged<"IAge", number>

asIncome

asIncomeStream

asIncomeTax

asInteger

  • asInteger(n: number): Tagged<"Integer", number>
  • Assert that the argument n is of the type Tagged<T,B>. The compiler's type inferencing is informed that the return value has been validated to be of that type.

    Parameters

    • n: number

    Returns Tagged<"Integer", number>

asLiability

asMonetary

asMoney

  • asMoney(n: number): Tagged<"Money", number>
  • Assert that the argument n is of the type Tagged<T,B>. The compiler's type inferencing is informed that the return value has been validated to be of that type.

    Parameters

    • n: number

    Returns Tagged<"Money", number>

Const asNumber

  • asNumber(n: any): number
  • Coerce an unknown value to a number. Strings and other things coercible to numbers will be converted. An error will be thrown if the result does not satisfy isNumber.

    Parameters

    • n: any

      a number, or something coerced to a number

    Returns number

asObject

  • asObject(a: any): {}

asPerson

asProbability

  • asProbability(n: number): Tagged<"Probability", number>
  • Assert that the argument n is of the type Tagged<T,B>. The compiler's type inferencing is informed that the return value has been validated to be of that type.

    Parameters

    • n: number

    Returns Tagged<"Probability", number>

Const asRGB

asRate

  • asRate(n: number): Tagged<"Rate", number>
  • Assert that the argument n is of the type Tagged<T,B>. The compiler's type inferencing is informed that the return value has been validated to be of that type.

    Parameters

    • n: number

    Returns Tagged<"Rate", number>

asScenario

asSnapshot

Const asString

  • asString(n: any): string
  • Coerce an unknown value to a string. Numbers will be converted.

    Parameters

    • n: any

      a number, or something coerced to a number

    Returns string

asTaxRate

  • asTaxRate(n: number): Tagged<"TaxRate", number>
  • Assert that the argument n is of the type Tagged<T,B>. The compiler's type inferencing is informed that the return value has been validated to be of that type.

    Parameters

    • n: number

    Returns Tagged<"TaxRate", number>

asTextItem

asUnit

  • asUnit(n: number): Tagged<"Unit", number>
  • Assert that the argument n is of the type Tagged<T,B>. The compiler's type inferencing is informed that the return value has been validated to be of that type.

    Parameters

    • n: number

    Returns Tagged<"Unit", number>

asYear

  • asYear(n: number): Tagged<"Year", number>
  • Assert that the argument n is of the type Tagged<T,B>. The compiler's type inferencing is informed that the return value has been validated to be of that type.

    Parameters

    • n: number

    Returns Tagged<"Year", number>

Const assertNever

  • assertNever(x: never, msg?: string): never
  • Assert that the call in the argument cannot return.

    Parameters

    • x: never
    • msg: string = ...

    Returns never

Const assertRow

  • assertRow<T>(row: RowType<"asset" | "liability" | "income" | "expense" | "incomeStream" | "incomeTax" | "person" | "text" | "scenario">, type: T): RowType<T>
  • Check that the supplied {@link Row} is of the desired Type, returning it as that type, or throwing an exception if it is not.

    Type parameters

    • T: "asset" | "liability" | "income" | "expense" | "incomeStream" | "incomeTax" | "person" | "text" | "scenario"

    Parameters

    • row: RowType<"asset" | "liability" | "income" | "expense" | "incomeStream" | "incomeTax" | "person" | "text" | "scenario">

      The {@link Row} to check

    • type: T

    Returns RowType<T>

Const box

  • box(content: string | Element): Element
  • NOP for the moment. Replaces:

    html`<div style='border: 1px solid blue; padding: 5px; margin-right: 1px;'> ${content} </div>`
    

    Parameters

    • content: string | Element

    Returns Element

Const calculate_age

  • calculate_age(birth: Date, thisDate: Date): Age

calendarRange

  • calendarRange(start: string | Date, end: string | Date, unit: CalendarUnit, n?: number): CalendarRange
  • calendarRange(start: string | Date, end: string | Date, interval: { biweekly: undefined | number; day: undefined | number; month: undefined | number; quarter: undefined | number; semiannually: undefined | number; semimonthly: undefined | number; week: undefined | number; year: undefined | number }): CalendarRange
  • Construct a CalendarRange.

    A CalendarRange is a CalendarPeriod that is divided up by increments of time into a series of CalendarStep segments. These segments can be iterated over in a for loop:

    for (const step in calendarRange) {
    console.log(step.start, step.end, JSON.stringify(step.length));
    }

    Parameters

    • start: string | Date

      The start Date.

    • end: string | Date

      The end Date.

    • unit: CalendarUnit

      The units of increment.

    • Optional n: number

      The number of units.

    Returns CalendarRange

  • Parameters

    • start: string | Date
    • end: string | Date
    • interval: { biweekly: undefined | number; day: undefined | number; month: undefined | number; quarter: undefined | number; semiannually: undefined | number; semimonthly: undefined | number; week: undefined | number; year: undefined | number }
      • biweekly: undefined | number
      • day: undefined | number
      • month: undefined | number
      • quarter: undefined | number
      • semiannually: undefined | number
      • semimonthly: undefined | number
      • week: undefined | number
      • year: undefined | number

    Returns CalendarRange

Const ceil

  • ceil<T>(n: T): number & Tag<"Integer"> & T
  • Integer version of Math.ciel

    Type parameters

    • T: number

    Parameters

    • n: T

    Returns number & Tag<"Integer"> & T

Const checkRow

  • checkRow<T>(row: RowType<"asset" | "liability" | "income" | "expense" | "incomeStream" | "incomeTax" | "person" | "text" | "scenario">, type: T): row is RowType<T>
  • Check that the supplied {@link Row} is of the specified Type

    Type parameters

    • T: "asset" | "liability" | "income" | "expense" | "incomeStream" | "incomeTax" | "person" | "text" | "scenario"

    Parameters

    • row: RowType<"asset" | "liability" | "income" | "expense" | "incomeStream" | "incomeTax" | "person" | "text" | "scenario">

      The {@link Row} to check

    • type: T

      the Type the row should be.

    Returns row is RowType<T>

Const classChecks

  • classChecks<T>(cls: new (...args: any[]) => T, coerce?: (a: any) => T): [(a: any) => a is T, (a: any) => T, (a: any) => T]
  • Construct a family of type functions: a type guard, a coersion, and a checked cast.

    • The type guard ("is") tests membership and lets the compiler know the type. Same as an instanceof check, but can be passed as a function.
    • The coercion ("to") checks to see if it is already of the type. If not, and a coercion function was supplied, the suplied coercion function will be applied, and the test retried with a checked cast.
    • The checked cast ("as") checks the object, returning it as being the right type, or throwing an exception if not.

    Type parameters

    • T

    Parameters

    • cls: new (...args: any[]) => T

      A class constructor

        • new (...args: any[]): T
        • Parameters

          • Rest ...args: any[]

          Returns T

    • Optional coerce: (a: any) => T

      an optional coercion function to be tried in the to* (coercion) variant

        • (a: any): T
        • Parameters

          • a: any

          Returns T

    Returns [(a: any) => a is T, (a: any) => T, (a: any) => T]

Const colorsFor

  • colorsFor(color_scheme: Color[], unknown?: Color): (keys: Iterable<string>) => ScaleOrdinal<string, Color, Color>
  • Compute a set of color mappings for items in a given set of keys. A higher-order function. Supply color_scheme (and optionally unknown), and it will return a a function that accepts a list of keys

    Parameters

    • color_scheme: Color[]

      a list of colors in '#rrggbb' format.

    • unknown: Color = ...

      the color to use for unknown keys

    Returns (keys: Iterable<string>) => ScaleOrdinal<string, Color, Color>

    an object equivalent to a d3 ordinal interpolator.

      • (keys: Iterable<string>): ScaleOrdinal<string, Color, Color>
      • Parameters

        • keys: Iterable<string>

        Returns ScaleOrdinal<string, Color, Color>

Const composeSorts

  • Compose multiple sort functions into one.

    Type parameters

    • T

    Parameters

    • fn: SortFn<T>

      The first sort function

    • Rest ...fns: SortFn<T>[]

      Additional sort functions to compose, if the previous return 0 for equality.

    Returns SortFn<T>

Const computeTax

Const compute_colors

  • Compute a set of color mappings for items in a given set of scenarios. A higher-order function. Supply color_scheme (and optionally unknown), and it will return a a function that accepts a list of scenarios

    Parameters

    • color_scheme: Color[]

      a list of colors in '#rrggbb' format.

    • unknown: Color = ...

      the color to use for unknown keys

    Returns (scenario_list: Scenario[]) => ScaleOrdinal<string, Color, Color>

    a d3 ordinal interpolator.

compute_probabilities

  • compute_probabilities(spouse: IFPerson, date: Date): Probability[]
  • compute_probabilities(spouse: undefined, date: Date): undefined

Const construct

  • construct<T>(items: RowType<T>[], type: T, dataset: RowType<"asset" | "liability" | "income" | "expense" | "incomeStream" | "incomeTax" | "person" | "text" | "scenario">[] | Scenario, end_year: Year): ItemType<T>
  • Construct an item from a row object

    Type parameters

    • T: "asset" | "liability" | "income" | "expense" | "incomeStream" | "incomeTax" | "person" | "text" | "scenario"

    Parameters

    • items: RowType<T>[]
    • type: T

      The type of item (defaulted from the item)

    • dataset: RowType<"asset" | "liability" | "income" | "expense" | "incomeStream" | "incomeTax" | "person" | "text" | "scenario">[] | Scenario
    • end_year: Year

    Returns ItemType<T>

    the constructed instance.

Const convert

  • Conveert an InputRow to an AnyRow, that is, parse and validate fields for each type of object.

    InputRow objects differ from AnyRow objects, in that the field names are capitalized. This is convenient for column headings in editing the CSV files, and also helps to distinguish between unprocessed InputRow and processed AnyRow objects.

    Type parameters

    • T: "asset" | "liability" | "income" | "expense" | "incomeStream" | "incomeTax" | "person" | "text" | "scenario"

    Parameters

    Returns AnyRow

Const convertInterest

  • Convert interest rates between different compounding periods.

    Parameters

    • rate: Rate

      The rate per year in the original compounding period.

    • fromPeriod: number | CalendarUnit

      The number of periods per year for the original compounding period, or the corresponding CalendarUnit.

    • newPeriod: number | CalendarUnit

      The number of periods per year for the new compounding period, or the corresponding CalendarUnit.

    Returns Rate

    The effective rate per year at the new compounding period.

Const convertInterestPerPeriod

  • Convert interest rates between different compounding periods.

    Parameters

    • rate: Rate

      The rate per year in the original compounding period.

    • fromPeriod: number | CalendarUnit

      The number of periods per year for the original compounding period, or the corresponding CalendarUnit.

    • newPeriod: number | CalendarUnit

      The number of periods per year for the new compounding period, or the corresponding CalendarUnit.

    Returns Rate

    The effective rate per period at the new compounding period.

Const convertPeriods

Const day

  • day(date: Date): Date

Const dayOfYear

  • dayOfYear(date: Date): number

Const day_of_year

  • day_of_year(d: Date): number
  • Obtain the day number of a given Date

    Parameters

    • d: Date

      The given Date.

    Returns number

    number of days since January 1

Const decodeCalendarInterval

Const decr

Const default_colors

Const entries

  • entries<K, V>(o: Record<K, V>): [K, V][]
  • Type parameters

    • K: string | number | symbol

    • V: unknown

    Parameters

    • o: Record<K, V>

    Returns [K, V][]

Const extractor

Const floor

  • floor<T>(n: T): number & Tag<"Integer"> & T
  • Integer version of Math.floor

    Type parameters

    • T: number

    Parameters

    • n: T

    Returns number & Tag<"Integer"> & T

Const fmt_date

  • fmt_date(date: string | Date): string

Const fmt_datetime

  • fmt_datetime(date: Date): string

Const fmt_month

  • fmt_month(date: string | Date): string

Const fmt_pct

  • fmt_pct(d: number, frac?: 0 | 1 | 2 | 3 | 4): string
  • Format a number as a percentage.

    Parameters

    • d: number

      Format a number as

    • frac: 0 | 1 | 2 | 3 | 4 = 3

      0 or 2 (default = 2) positions for cents

    Returns string

Const fmt_time

  • fmt_time(date: string | Date): string

Const fmt_usd

  • fmt_usd(d: number, frac?: number): string
  • Format a number as US currency.

    Parameters

    • d: number

      a number as US currency

    • frac: number = ...

      0 or 2 (default = 2) positions for cents

    Returns string

Const fmt_year

  • fmt_year(date: string | Date): string

Const fmt_year_abbrev

  • fmt_year_abbrev(date: string | Date): string

Const fmt_year_short

  • fmt_year_short(date: string | Date): string

Const formatCell

Const heapgen

  • Given a Heap, give a generator to the (sorted) values in the heap.

    Type parameters

    • T

    Parameters

    • heap: Heap<T>

    Returns EnhancedGenerator<T, void, unknown>

Const hsv

id

  • id<T>(type: T): (name: Name) => Id<T>
  • id<T>(type: T, name: string): Id<T>
  • Type parameters

    • T: "asset" | "liability" | "income" | "expense" | "incomeStream" | "incomeTax" | "person" | "text" | "scenario"

    Parameters

    • type: T

    Returns (name: Name) => Id<T>

  • Type parameters

    • T: "asset" | "liability" | "income" | "expense" | "incomeStream" | "incomeTax" | "person" | "text" | "scenario"

    Parameters

    • type: T
    • name: string

    Returns Id<T>

Const identity

  • identity<T>(a: T): T
  • Simple type-aware identity function.

    Type parameters

    • T

    Parameters

    • a: T

    Returns T

    a

Const idiv

Const imod

Const incr

incrementDate

  • incrementDate(date: string | Date, interval: { biweekly: undefined | number; day: undefined | number; month: undefined | number; quarter: undefined | number; semiannually: undefined | number; semimonthly: undefined | number; week: undefined | number; year: undefined | number }): Date
  • incrementDate(date: string | Date, unitOrInterval: CalendarUnit, n?: number): Date
  • Increment a time by a specified period of time.

    The returned value is truncated to the beginning of the UTC day.

    Parameters

    • date: string | Date

      The date to be incremented

    • interval: { biweekly: undefined | number; day: undefined | number; month: undefined | number; quarter: undefined | number; semiannually: undefined | number; semimonthly: undefined | number; week: undefined | number; year: undefined | number }

      A CalendarInterval denoting how much to increment by.

      • biweekly: undefined | number
      • day: undefined | number
      • month: undefined | number
      • quarter: undefined | number
      • semiannually: undefined | number
      • semimonthly: undefined | number
      • week: undefined | number
      • year: undefined | number

    Returns Date

  • Increment a time by a specified period of time.

    The returned value is truncated to the beginning of the UTC day.

    Parameters

    • date: string | Date

      The date to be incremented

    • unitOrInterval: CalendarUnit
    • Optional n: number

      The number of units to increment by

    Returns Date

Const indexByName

  • Produce an index to a list of {@link Named objects.

    Type parameters

    Parameters

    • list: T[]

      A list of Named objects

    Returns NamedIndex<T>

    An index of the objects by name.

Const interestCalculator

  • interestCalculator(): undefined

Const invertSort

  • Invert the direction of sorting of a sort comparator function.

    Type parameters

    • T

    Parameters

    • fn: SortFn<T>

      A sort comparator function

    Returns SortFn<T>

    A sort comparator function that sorts in the opposite direction

isAge

  • isAge(n: any): n is Tagged<"Age", number>
  • A type guard. Returns true if the argument n satisfies the conditions to be of type T, and informs the compiler's type inferencing engine.

    Parameters

    • n: any

    Returns n is Tagged<"Age", number>

Const isAlign

  • isAlign(a: any): a is Align

isAsset

  • isAsset(a: any): a is Asset

Const isBoolean

  • isBoolean(a: any): a is boolean

isByte

  • isByte(n: any): n is Tagged<"Byte", number>
  • A type guard. Returns true if the argument n satisfies the conditions to be of type T, and informs the compiler's type inferencing engine.

    Parameters

    • n: any

    Returns n is Tagged<"Byte", number>

Const isCalendarInterval

Const isCalendarLength

isCalendarPeriod

isCalendarStep

Const isCalendarUnit

Const isColumn

Const isColumnSpec

Const isColumnType

Const isDate

  • isDate(d: any): d is Date

isDegrees

  • isDegrees(n: any): n is Tagged<"Degrees", number>
  • A type guard. Returns true if the argument n satisfies the conditions to be of type T, and informs the compiler's type inferencing engine.

    Parameters

    • n: any

    Returns n is Tagged<"Degrees", number>

isExpense

Const isFormatter

Const isFunction

  • isFunction(f: any): f is Function

Const isHSV

isIAge

  • isIAge(n: any): n is Tagged<"IAge", number>
  • A type guard. Returns true if the argument n satisfies the conditions to be of type T, and informs the compiler's type inferencing engine.

    Parameters

    • n: any

    Returns n is Tagged<"IAge", number>

isIncome

Const isIncomeSource

isIncomeStream

isIncomeTax

isInteger

  • isInteger(n: any): n is Tagged<"Integer", number>
  • A type guard. Returns true if the argument n satisfies the conditions to be of type T, and informs the compiler's type inferencing engine.

    Parameters

    • n: any

    Returns n is Tagged<"Integer", number>

isLeapYear

  • isLeapYear(year: number): boolean
  • isLeapYear(year: Date): boolean

isLiability

Const isMonetary

isMoney

  • isMoney(n: any): n is Tagged<"Money", number>
  • A type guard. Returns true if the argument n satisfies the conditions to be of type T, and informs the compiler's type inferencing engine.

    Parameters

    • n: any

    Returns n is Tagged<"Money", number>

Const isNumber

  • isNumber(n: any): n is number
  • Type guard for numbers.

    Parameters

    • n: any

    Returns n is number

    true if the argument n is a number, not a NaN, and finite.

Const isObject

  • isObject(o: any): o is {}

isPerson

isProbability

  • isProbability(n: any): n is Tagged<"Probability", number>
  • A type guard. Returns true if the argument n satisfies the conditions to be of type T, and informs the compiler's type inferencing engine.

    Parameters

    • n: any

    Returns n is Tagged<"Probability", number>

Const isRGB

isRate

  • isRate(n: any): n is Tagged<"Rate", number>
  • A type guard. Returns true if the argument n satisfies the conditions to be of type T, and informs the compiler's type inferencing engine.

    Parameters

    • n: any

    Returns n is Tagged<"Rate", number>

isScenario

isSnapshot

Const isString

  • isString(n: any): n is string
  • Type guard for strings.

    Parameters

    • n: any

    Returns n is string

    true if the argument n is a string.

isTaxRate

  • isTaxRate(n: any): n is Tagged<"TaxRate", number>
  • A type guard. Returns true if the argument n satisfies the conditions to be of type T, and informs the compiler's type inferencing engine.

    Parameters

    • n: any

    Returns n is Tagged<"TaxRate", number>

isTextItem

isUnit

  • isUnit(n: any): n is Tagged<"Unit", number>
  • A type guard. Returns true if the argument n satisfies the conditions to be of type T, and informs the compiler's type inferencing engine.

    Parameters

    • n: any

    Returns n is Tagged<"Unit", number>

isYear

  • isYear(n: any): n is Tagged<"Year", number>
  • A type guard. Returns true if the argument n satisfies the conditions to be of type T, and informs the compiler's type inferencing engine.

    Parameters

    • n: any

    Returns n is Tagged<"Year", number>

Const isum

Const keys

  • keys<K>(o: Record<K, any>): K[]
  • Type parameters

    • K: string | number | symbol

    Parameters

    • o: Record<K, any>

    Returns K[]

Const linePlot

Const loadData

  • loadData(url: string): Promise<ItemType<"scenario">[]>

loadFrom

  • loadFrom(url: string | Promise<string>, src: string, type: "asset" | "liability" | "income" | "expense" | "incomeStream" | "incomeTax" | "person" | "text" | "scenario" | "index"): Promise<DSVRowArray>
  • loadFrom(request: Requested | Promise<Requested>, src: string, type: "asset" | "liability" | "income" | "expense" | "incomeStream" | "incomeTax" | "person" | "text" | "scenario" | "index"): Promise<DSVRowArray>
  • Load data from the specified URL.

    Parameters

    • url: string | Promise<string>

      URL to load the data from

    • src: string
    • type: "asset" | "liability" | "income" | "expense" | "incomeStream" | "incomeTax" | "person" | "text" | "scenario" | "index"

    Returns Promise<DSVRowArray>

  • Parameters

    • request: Requested | Promise<Requested>
    • src: string
    • type: "asset" | "liability" | "income" | "expense" | "incomeStream" | "incomeTax" | "person" | "text" | "scenario" | "index"

    Returns Promise<DSVRowArray>

Const lookupTax

Const makeSort

  • makeSort<T>(cmp?: SortFn<T>): <I>(l: Iterable<I>) => I[]
  • A higher-order function that returs a sort function.

    Type parameters

    • T

    Parameters

    • cmp: SortFn<T> = naturalCMP

      a comparator

    Returns <I>(l: Iterable<I>) => I[]

    a sort function that sorts a list according to cmp

      • <I>(l: Iterable<I>): I[]
      • Type parameters

        • I

        Parameters

        • l: Iterable<I>

        Returns I[]

Const makeSummer

  • makeSummer<T, V>(f: (item: T) => V, v?: (n: V) => V): (l: T[]) => V
  • Higher-order function, that creates summing functions.

    Type parameters

    • T

    • V: number

    Parameters

    • f: (item: T) => V

      a function that takes an item and returns a number.

        • (item: T): V
        • Parameters

          • item: T

          Returns V

    • Optional v: (n: V) => V

      a function that validates that the result is of type V.

        • (n: V): V
        • Parameters

          • n: V

          Returns V

    Returns (l: T[]) => V

    a function that takes a list of items and returns the sum of the values returned by applying f.

      • (l: T[]): V
      • Parameters

        • l: T[]

        Returns V

Const max

  • max<T>(...n: T[]): T
  • Type parameters

    • T: number

    Parameters

    • Rest ...n: T[]

    Returns T

Const mergeKey

  • mergeKey<K>(key: K): MergeKey<K>

Const mergeList

  • mergeList<K, V, R>(key: K): MergeList<K, V, R>
  • Merge operator to merge to a list of values.

    Type parameters

    • K

    • V

    • R: V[]

    Parameters

    • key: K

      Key for the merged items. Ignored.

    Returns MergeList<K, V, R>

    Merge object that merges to a list of values.

Const mergeObject

  • Higher order Merge operator. This takes a specification object and an optional onUnequal action.

    The result is a Merge operator that performs each supplied merge in parallel, and producing a result object with the results of the sub-merges indicated by the specification object.

    The specification object is an object with a field for each field of the result.

    Each field value of the specification object is either a MergeFn, or a tuple of [extractor, MergeFn].

    If an extractor is supplied, it is either a field to be extracted, or a function that takes the value supplied to the parent merge and produces the value to be merged by the sub-merge.

    If the specification is an array, the result of the merge will be an array of the same size.

    Type parameters

    • K

    • V: Record<string | number | symbol, any>

    • I: Record<keyof V, any>

    • R: Record<keyof V, any>

    Parameters

    Returns (key: K) => MergeObject<K, V, R, MergeObjectSpec<K, V, I, R>>

Const mergeRamp

  • mergeRamp<T, KT, KV>(keyFn: KeyFn<T, KT>, valueField: KV, valueFn: ValueFn<T, T[KV]>): (key: string | number | symbol) => MergeRamp<string | number | symbol, T, KT, KV>
  • Type parameters

    • T: unknown

    • KT: string | number | symbol

    • KV: string | number | symbol

    Parameters

    Returns (key: string | number | symbol) => MergeRamp<string | number | symbol, T, KT, KV>

      • (key: string | number | symbol): MergeRamp<string | number | symbol, T, KT, KV>
      • Parameters

        • key: string | number | symbol

        Returns MergeRamp<string | number | symbol, T, KT, KV>

Const mergeSum

  • mergeSum<K, V, R>(key: K): MergeSum<K, V, R>
  • Merge operator to sum a set of numbers.

    Type parameters

    • K

    • V: number

    • R: number

    Parameters

    • key: K

      The merge key. Ignored

    Returns MergeSum<K, V, R>

    the sum of the numbers supplied

Const min

  • min<T>(...n: T[]): T
  • Type parameters

    • T: number

    Parameters

    • Rest ...n: T[]

    Returns T

Const mod360

  • Coerce a number to the range between 0 and 360, inclusive of 0, exclusive of 360.

    Parameters

    • n: number

    Returns Degrees

    the number, coerced to the range (0,360], typed as Degrees

Const monetaryValue

Const naturalCMP

  • naturalCMP<T>(a: T, b: T): 0 | 1 | -1
  • A comparator that sorts according to the "natural" order. First by type, then by string or numerical ordering if a string, number, boolean, or symbol.

    Type parameters

    • T

    Parameters

    • a: T
    • b: T

    Returns 0 | 1 | -1

Const naturalSort

  • naturalSort<I>(l: Iterable<I>): I[]
  • A function that sorts according to natural order. See naturalCMP.

    Type parameters

    • I: unknown

    Parameters

    • l: Iterable<I>

    Returns I[]

    a copy of list in sorted order.

Const nullCMP

  • nullCMP<T>(a: T, b: T): 0 | 1 | -1
  • A comparator that does not alter the sort order. It regards everything as equal, and thus Javascript's stable sort leaves the ordering unchanged.

    Type parameters

    • T

    Parameters

    • a: T
    • b: T

    Returns 0 | 1 | -1

    0

Const numberRange

  • Create functions to test and assert membership in a tagged numerical range.

    Type parameters

    • T: string

    Parameters

    • tag: T

      the type tag

    • range: NumberDomain

      the specification of the range to be enforced.

    Returns DomainFns<T, number>

    a DomainFns with the test and assert functions.

Const optional

  • optional<T>(fn: (a: any) => T): <D>(dflt: D) => (a: any) => T | D
  • A higher-order function that takes a converter function and gives a higher-order function that takes a default, which returns a converter that uses the default when no value is supplied, instead of invoking the converter.

    Type parameters

    • T

    Parameters

    • fn: (a: any) => T

      a converter function

        • (a: any): T
        • Parameters

          • a: any

          Returns T

    Returns <D>(dflt: D) => (a: any) => T | D

      • <D>(dflt: D): (a: any) => T | D
      • Type parameters

        • D

        Parameters

        • dflt: D

        Returns (a: any) => T | D

          • (a: any): T | D
          • Parameters

            • a: any

            Returns T | D

Const optionalDate

  • optionalDate<D>(dflt: D): (a: any) => Date | D
  • Type parameters

    • D

    Parameters

    • dflt: D

    Returns (a: any) => Date | D

      • (a: any): Date | D
      • Parameters

        • a: any

        Returns Date | D

Const optionalMoney

  • optionalMoney<D>(dflt: D): (a: any) => Tagged<"Money", number> | D
  • Type parameters

    • D

    Parameters

    • dflt: D

    Returns (a: any) => Tagged<"Money", number> | D

      • (a: any): Tagged<"Money", number> | D
      • Parameters

        • a: any

        Returns Tagged<"Money", number> | D

Const optionalNumber

  • optionalNumber<D>(dflt: D): (a: any) => number | D
  • Type parameters

    • D

    Parameters

    • dflt: D

    Returns (a: any) => number | D

      • (a: any): number | D
      • Parameters

        • a: any

        Returns number | D

Const optionalRate

  • optionalRate<D>(dflt: D): (a: any) => Tagged<"Rate", number> | D
  • Type parameters

    • D

    Parameters

    • dflt: D

    Returns (a: any) => Tagged<"Rate", number> | D

      • (a: any): Tagged<"Rate", number> | D
      • Parameters

        • a: any

        Returns Tagged<"Rate", number> | D

Const or

  • or<T>(dflt: T): (a: any) => T
  • A higher-order function that returns a @{link Converters} provides a default in cases where a value is not supplied in the input.

    Type parameters

    • T

    Parameters

    • dflt: T

      Default value

    Returns (a: any) => T

      • (a: any): T
      • Parameters

        • a: any

        Returns T

Const parse

  • parse(text: string): DSVRowArray<string>

Const parseDate

  • parseDate(date: string): Date
  • Parse a UTC date, in one of the following forms:

    • 2021-08-13
    • 2021-08 // Same as 2021-08-01
    • 2021 // Same as 2021-01-01

    Leading zeros on month and day are optional. Two-year year abbreviations are not allowed.

    Parameters

    • date: string

      A string in the form YYYY-MMM-dd

    Returns Date

    a Date at 00:00:00.000 UTC.

Const rampify

  • rampify<T, TK, VK, SK, KEY, SEQ>(keyField: TK | KeyFn<T, KEY>, seqField: SK, valueField: VK): (__namedParameters?: RampifyKeys<SEQ>) => (list: Iterable<T>) => EnhancedGenerator<T, void, T>
  • Type parameters

    • T: object

    • TK: string | number | symbol = keyof T

    • VK: string | number | symbol = keyof T

    • SK: string | number | symbol = keyof T

    • KEY: string | number | symbol = (T[TK] & string) & (T[TK] & number) & (T[TK] & symbol)

    • SEQ = T[SK]

    Parameters

    • keyField: TK | KeyFn<T, KEY>
    • seqField: SK
    • valueField: VK

    Returns (__namedParameters?: RampifyKeys<SEQ>) => (list: Iterable<T>) => EnhancedGenerator<T, void, T>

Const rgb

Const round

  • round<T>(n: T): number & Tag<"Integer"> & T
  • Integer version of Math.round

    Type parameters

    • T: number

    Parameters

    • n: T

    Returns number & Tag<"Integer"> & T

Const roundTo

  • roundTo(n: number): <T>(arg: T) => T
  • A higher-order-function that produces a rounding function that rounds to the nearest n.

    Parameters

    • n: number

      scale of rounding

    Returns <T>(arg: T) => T

      • <T>(arg: T): T
      • Type parameters

        • T: number

        Parameters

        • arg: T

        Returns T

Const row

  • row(...args: any[]): string
  • Format a row of values in a Markdown table.

    Parameters

    • Rest ...args: any[]

      Array of values for the cells in the row

    Returns string

    a markdown-formatted string

Const runSim

  • runSim(scenario: Scenario, start?: Date, end?: Date): Sim

Const setup

  • setup(o: O): { loadData: (url: string) => Promise<ItemType<"scenario">[]> }
  • Initialize our world and connect it to the ObservableHQ world.

    Parameters

    • o: O

      the O interface to our ObservableHQ environment

    Returns { loadData: (url: string) => Promise<ItemType<"scenario">[]> }

    the loadData function, ready for use.

    • loadData: (url: string) => Promise<ItemType<"scenario">[]>
        • (url: string): Promise<ItemType<"scenario">[]>
        • Load the model data.

          Parameters

          • url: string

            URL to an index file

          Returns Promise<ItemType<"scenario">[]>

          a list of Scenario objects

Const sortBy

  • sortBy<T, V>(field: T): SortFn<V>
  • Type parameters

    • T: string | number | symbol

    • V: { [ K in string | number | symbol]: any }

    Parameters

    • field: T

    Returns SortFn<V>

Const split

  • split<T>(dflt: T[]): (c: any) => T[]
  • Split a comma-separated field.

    Type parameters

    • T

    Parameters

    • dflt: T[]

    Returns (c: any) => T[]

      • (c: any): T[]
      • Parameters

        • c: any

        Returns T[]

Const stackPlot

Const subcolors

  • subcolors(colors: ScaleOrdinal<string, Color, Color>, subdomain: string[]): ScaleOrdinal<string, Color, Color>
  • Subset a color interpolator to a subdomain. This is used to allow genenrating a swatch for just the relevant items.

    Parameters

    • colors: ScaleOrdinal<string, Color, Color>
    • subdomain: string[]

    Returns ScaleOrdinal<string, Color, Color>

    a d3 ordinal interpolator.

Const table

  • table(columns: ColMap | Column[], ...rows: any): string

Const temporalCmp

Const temporalSort

  • temporalSort<I>(l: Iterable<I>): I[]
  • Type parameters

    • I: TemporalItem<"asset" | "liability" | "income" | "expense" | "incomeStream" | "incomeTax" | "person" | "text" | "scenario", I>

    Parameters

    • l: Iterable<I>

    Returns I[]

Const timelineCmp

toAge

  • toAge(n: any): Tagged<"Age", number>
  • A function that coerces to a specified type.

    Parameters

    • n: any

    Returns Tagged<"Age", number>

toAlign

toAsset

toBoolean

  • toBoolean(a: any): boolean

toByte

  • toByte(n: any): Tagged<"Byte", number>
  • A function that coerces to a specified type.

    Parameters

    • n: any

    Returns Tagged<"Byte", number>

toCalendarInterval

toCalendarLength

toCalendarPeriod

toCalendarStep

toCalendarUnit

toColumn

toColumnSpec

  • toColumnSpec(a: any): { align: Align; fixed?: boolean; format: Formatter; name: any }

toColumnType

toDate

  • toDate(a: any): Date

toDegrees

  • toDegrees(n: any): Tagged<"Degrees", number>
  • A function that coerces to a specified type.

    Parameters

    • n: any

    Returns Tagged<"Degrees", number>

toExpense

toFormatter

toIAge

  • toIAge(n: any): Tagged<"IAge", number>
  • A function that coerces to a specified type.

    Parameters

    • n: any

    Returns Tagged<"IAge", number>

toIncome

toIncomeStream

toIncomeTax

toInteger

  • toInteger(n: any): Tagged<"Integer", number>
  • A function that coerces to a specified type.

    Parameters

    • n: any

    Returns Tagged<"Integer", number>

toLiability

toMonetary

toMoney

  • toMoney(n: any): Tagged<"Money", number>
  • A function that coerces to a specified type.

    Parameters

    • n: any

    Returns Tagged<"Money", number>

toObject

  • toObject(a: any): {}

toPerson

toProbability

  • toProbability(n: any): Tagged<"Probability", number>
  • A function that coerces to a specified type.

    Parameters

    • n: any

    Returns Tagged<"Probability", number>

toRate

  • toRate(n: any): Tagged<"Rate", number>
  • A function that coerces to a specified type.

    Parameters

    • n: any

    Returns Tagged<"Rate", number>

toScenario

toSnapshot

toTaxRate

  • toTaxRate(n: any): Tagged<"TaxRate", number>
  • A function that coerces to a specified type.

    Parameters

    • n: any

    Returns Tagged<"TaxRate", number>

toTextItem

toUnit

  • toUnit(n: any): Tagged<"Unit", number>
  • A function that coerces to a specified type.

    Parameters

    • n: any

    Returns Tagged<"Unit", number>

toYear

  • toYear(n: any): Tagged<"Year", number>
  • A function that coerces to a specified type.

    Parameters

    • n: any

    Returns Tagged<"Year", number>

Const total

Const trunc

  • trunc<T>(n: T): number & Tag<"Integer"> & T
  • Integer version of Math.trunc

    Type parameters

    • T: number

    Parameters

    • n: T

    Returns number & Tag<"Integer"> & T

Const truncateDate

  • Rolls back time to the start of a year, quarter, month, or day. Higher-order function that returns a function for the specific time period to truncate to.

    Parameters

    • unit: CalendarUnit

      Unit of time to truncate to (must not be 'week').

    Returns (date: Date) => Date

    (date: {@link Date}) => {@link Date}

      • (date: Date): Date
      • Parameters

        • date: Date

        Returns Date

Const typeChecks

  • typeChecks<T>(is: (a: any) => a is T, isNot: string, coerce?: (a: any) => undefined | T): [(a: any) => T, (a: any) => T]
  • Construct a family of type functions: a type guard, a coersion, and a checked cast.

    • The type guard ("is") tests membership and lets the compiler know the type. Same as an instanceof check, but can be passed as a function.
    • The coercion ("to") checks to see if it is already of the type. If not, and a coercion function was supplied, the suplied coercion function will be applied, and the test retried with a checked cast.
    • The checked cast ("as") checks the object, returning it as being the right type, or throwing an exception if not.

    Type parameters

    • T

    Parameters

    • is: (a: any) => a is T

      A type guard.

        • (a: any): a is T
        • Parameters

          • a: any

          Returns a is T

    • isNot: string

      A string for error messages, when the type guard fails

    • Optional coerce: (a: any) => undefined | T

      an optional coercion function to be tried in the to* (coercion) variant

        • (a: any): undefined | T
        • Parameters

          • a: any

          Returns undefined | T

    Returns [(a: any) => T, (a: any) => T]

Const uniq

  • uniq<T>(l: T[]): T[]
  • Returns the unique values, as compared by ===

    Type parameters

    • T

    Parameters

    • l: T[]

      a list of strings or other values to be compared by ===

    Returns T[]

Const validator

  • Type parameters

    • T

    Parameters

    • spec: ValidationSpec<T>

      A specification of the validation/coercion to be performed.

    Returns (obj: any) => T

      • (obj: any): T
      • Parameters

        • obj: any

        Returns T

Const values

  • values<K, V>(o: Record<K, V>): V[]
  • Type parameters

    • K: string | number | symbol

    • V: unknown

    Parameters

    • o: Record<K, V>

    Returns V[]

Const widenAs

Const widenIs

  • widenIs<T>(guard: TypeGuard<T>): (n: any) => n is undefined | T
  • Convert a TypeGuard for type T into one for T | undefined.

    Type parameters

    • T

    Parameters

    Returns (n: any) => n is undefined | T

      • (n: any): n is undefined | T
      • Parameters

        • n: any

        Returns n is undefined | T

Const widenTo

Const year

  • year(d: Date): Date

Const yearDays

  • yearDays(year: number): 365 | 366
  • The number of days in a particular year.

    Parameters

    • year: number

      The year as a number

    Returns 365 | 366

    365 or 366

Generated using TypeDoc