Skip to content

pactole-js


Class: BaseLottery

Defined in: lottery/base-lottery.ts:53

A base class for lottery implementations.

The class is essentially a thin wrapper around a draw-day schedule and a combination factory. It provides convenience methods for computing draw dates and delegating combination creation/generation.

Param

Configuration options.

Param

Draw schedule for the lottery. May be a DrawDays instance or any iterable of DayInput values (numbers, strings, Date, or Weekday). Defaults to an empty array.

Param

Combination factory used by this lottery. Receives the same options object as LotteryCombination.getCombination. If null or not callable, a default LotteryCombination factory is used.

Example

const lottery = new BaseLottery({
  drawDays: [Weekday.MONDAY, Weekday.THURSDAY],
  combinationFactory: EuroMillionsCombination,
});

lottery.drawDays; // DrawDays instance
lottery.combinationFactory; // factory function
lottery.combinationFactory({ numbers: [1, 2, 3], stars: [1] });

Extended by

Constructors

Constructor

new BaseLottery(__namedParameters?): BaseLottery

Defined in: lottery/base-lottery.ts:57

Parameters

__namedParameters?

BaseLotteryOptions = {}

Returns

BaseLottery

Accessors

combinationFactory

Get Signature

get combinationFactory(): CombinationFactory

Defined in: lottery/base-lottery.ts:94

Return the combination factory associated with this lottery.

Example
const lottery = new BaseLottery({ combinationFactory: EuroMillionsCombination });
const factory = lottery.combinationFactory; // EuroMillionsCombination factory function
const combination = factory({ numbers: [1, 2, 3], stars: [1] }); // EuroMillionsCombination instance
Returns

CombinationFactory

The factory function used to create combinations.


drawDays

Get Signature

get drawDays(): DrawDays

Defined in: lottery/base-lottery.ts:78

Return the DrawDays instance associated with this lottery.

Example
const lottery = new BaseLottery({ drawDays: [Weekday.MONDAY, Weekday.THURSDAY] });
lottery.drawDays; // DrawDays instance with Monday and Thursday
Returns

DrawDays

The DrawDays instance configured for this lottery.

Methods

generate()

generate(options?): LotteryCombination[]

Defined in: lottery/base-lottery.ts:154

Generate a list of random lottery combinations from the configured combination factory.

Parameters

options?

Options controlling generation.

n?

number = 1

Number of combinations to generate (default 1).

partitions?

number = 1

Number of partitions to use when ranking/generating. (default 1).

Returns

LotteryCombination[]

An array of lottery combinations produced by the factory.

Example

const lottery = new BaseLottery({ combinationFactory: EuroMillionsCombination });
const combinations = lottery.generate({ n: 2 });

getCombination()

getCombination(components): LotteryCombination

Defined in: lottery/base-lottery.ts:171

Create a lottery combination from the provided components using the configured factory.

Parameters

components

Record\<string, CombinationInputOrRank>

Component values or ranks forwarded to the factory.

Returns

LotteryCombination

A lottery combination produced by the factory.

Example

const lottery = new BaseLottery({ combinationFactory: EuroMillionsCombination });
const ticket = lottery.getCombination({ numbers: [1, 2, 3, 4, 5], stars: [1, 2] });

getLastDrawDate()

getLastDrawDate(fromDate?, closest?): Date

Defined in: lottery/base-lottery.ts:114

Return the date of the last lottery draw according to the configured drawDays.

Parameters

fromDate?

Starting reference date. Accepted formats: - A Unix timestamp in seconds. - An ISO date string (YYYY-MM-DD). - A Date object. - A Weekday or other DayInput accepted by DrawDays.getLastDrawDate. If omitted or null, the current date is used.

DayInput | Weekday | null

closest?

boolean = true

Whether to return the closest draw date if fromDate is itself a draw day.

Returns

Date

A Date representing the last draw day on or before fromDate.

Throws

When fromDate is not a valid date input.

Throws

When fromDate string cannot be parsed.


getNextDrawDate()

getNextDrawDate(fromDate?, closest?): Date

Defined in: lottery/base-lottery.ts:134

Return the date of the next lottery draw according to the configured drawDays.

Parameters

fromDate?

Starting reference date. Accepted formats: - A Unix timestamp in seconds. - An ISO date string (YYYY-MM-DD). - A Date object. - A Weekday or other DayInput accepted by DrawDays.getNextDrawDate. If omitted or null, the current date is used.

DayInput | Weekday | null

closest?

boolean = true

Whether to return the closest draw date if fromDate is itself a draw day.

Returns

Date

A Date representing the next draw day on or after fromDate.

Throws

When fromDate is not a valid date input.

Throws

When fromDate string cannot be parsed.