export type NumericOptions = { type: 'equals' | 'minimum' | 'maximum' | 'range', amount: number, range: { minimum: number /** * backwards compatible typo */ maxmimum: number }, } export enum TierType { //// this is the type of the value of the testables // // numeric, path-fixed, path-variable, path-boolean // // currently only numeric and path-fixed are supported // type: 'numeric' | 'path-fixed' | 'path-variable' | 'path-boolean' Numeric = 'numeric', Fixed = 'fixed', /*PathVariable = 'path-variable', PathBoolean = 'path-boolean',*/ } export function equals(number: number): NumericOptions { return { type: 'equals', amount: number, range: { minimum: 0, maxmimum: 0 } } } export function minimum(number: number): NumericOptions { return { type: 'minimum', amount: number, range: { minimum: 0, maxmimum: 0 } } } export function maximum(number: number): NumericOptions { return { type: 'maximum', amount: number, range: { minimum: 0, maxmimum: 0 } } } export function range(min: number, max: number): NumericOptions { return { type: 'range', amount: 0, range: { minimum: min, maxmimum: max } } } export function increase(options: NumericOptions, rangeIndividuallyOnly: boolean = false): NumericOptions { // Check for undefined or empty object (no type property) if (!options || !options.type) { options = equals(0); } switch (options.type) { case 'equals': case 'minimum': case 'maximum': options.amount += 1; break; case 'range': if (!rangeIndividuallyOnly) { // increase by the amount between the two const difference = options.range.maxmimum - options.range.minimum options.range.minimum = options.range.maxmimum + 1; options.range.maxmimum = options.range.minimum + difference; } else { options.range.maxmimum += 1; } break; } return options; } export const amountValidatorTierFields = () => ['quantity']