@rickosborne/rebound
Version:
Rick Osborne's utilities for working with bounded numbers
70 lines • 3.41 kB
TypeScript
import type { AssertExact, AssertIfPresent } from "./assert-bounded.js";
import type { FromNumber, FromNumberIfPresent } from "./from-number-bounded.js";
import type { GuardExact, GuardIfPresent, If } from "./guard-bounded.js";
import type { ConvertTo, IntStrategy } from "./integer-from.js";
import type { IntegerGeneratorOptions } from "./integer-generator.js";
import type { NumberRange } from "./number-range.js";
import type { RandomBounded } from "./random-bounded.js";
import type { ReboundConfigBuilder } from "./rebound-builder.js";
import { BOUNDS } from "./spec.js";
import type { BoundedNumber, LowerInEx, NumberSet, OutOfBoundsErrorProvider, TypedCheckedBounds, UpperInEx } from "./spec.js";
export interface ReboundAllowUndef {
ifPresent: true;
}
export interface ReboundFnOptions {
errorProvider?: OutOfBoundsErrorProvider;
fnName?: string;
ifPresent?: boolean;
}
export interface ResolvedFnOptions extends Required<ReboundFnOptions> {
defaultName: string;
}
export interface ReboundRandomOptions {
fnName?: string;
rng?: ({
float01(): number;
range(low: number, high: number): number;
});
}
export interface ReboundToIntOptions extends ReboundFnOptions {
strategy?: IntStrategy;
}
export interface ResolvedToIntOptions extends Required<ReboundToIntOptions> {
defaultName: string;
}
export declare class Rebound<N extends number> implements TypedCheckedBounds {
static buildType(typeName: string): ReboundConfigBuilder<LowerInEx, number, NumberSet, number, UpperInEx>;
private readonly fnCache;
readonly isInt: boolean;
readonly isLowerInc: boolean;
readonly isUpperInc: boolean;
readonly label: string;
readonly lower: number;
readonly numberType: N;
readonly outOfBoundsErrorProvider: OutOfBoundsErrorProvider;
readonly range: NumberRange;
readonly typeName: string;
readonly upper: number;
protected constructor(typeName: string, range: NumberRange);
get assert(): AssertExact<BoundedNumber<N>>;
assertWith<Options extends ReboundFnOptions>(options?: Options): Options extends ReboundAllowUndef ? AssertIfPresent<BoundedNumber<N>> : AssertExact<BoundedNumber<N>>;
private cacheFn;
get ceil(): ConvertTo<N>;
get floor(): ConvertTo<N>;
get fromNumber(): FromNumber<N>;
fromNumberWith<Options extends ReboundFnOptions>(options?: Options): Options extends ReboundAllowUndef ? FromNumberIfPresent<N> : FromNumber<N>;
get guard(): GuardExact<N>;
guardWith<Options extends Omit<ReboundFnOptions, "errorProvider">>(options?: Options): If<Options["ifPresent"], GuardIfPresent<N>, GuardExact<N>>;
get integers(): Generator<N, undefined, undefined>;
integersWith(options?: IntegerGeneratorOptions): Generator<N, undefined, undefined>;
outOfRangeError(value: unknown, name?: string | undefined): RangeError;
get random(): RandomBounded<N>;
randomWith(options?: ReboundRandomOptions | undefined): RandomBounded<N>;
get round(): ConvertTo<N>;
toIntWith<Options extends ReboundToIntOptions>(options: Options): ConvertTo<N>;
get trunc(): ConvertTo<N>;
protected withIntStrategy(options: ReboundToIntOptions | undefined): ResolvedToIntOptions;
protected withOptions(options: ReboundFnOptions | undefined, prefix: string, suffix?: string): ResolvedFnOptions;
get [BOUNDS](): this;
}
//# sourceMappingURL=rebound.d.ts.map