import { Num } from '@rimbu/typical'; /** Includes the literals for [1-9] */ export type DigitWithoutZero = 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9; /** Includes the literals for [0-9] */ export type Digit = 0 | DigitWithoutZero; /** Returns the next number as literal type. * The value must be an integer. * * @example * ```ts * type _1 = Next<3>; ; type _1 = 4; * type _2 = Next<4.5>; ; type _2 = never; * ``` */ export type Next = Num.Inc; /** Returns the previous number as literal type. * The value must be an integer. * * @example * ```ts * type _1 = Next<3>; ; type _1 = 2; * type _2 = Next<4.5>; ; type _2 = never; * ``` */ export type Prev = Num.Subtract; /** Add two numbers as types. * The values must be integers. * * @example * ```ts * type _1 = Add<2, 5>; ; type _1 = 7; * type _2 = Add<2.5, 5>; ; type _2 = never; * ``` */ export type Add = Num.Add; type PrependNextNum = A['length'] extends infer T ? ((t: T, ...a: A) => void) extends (...x: infer X) => void ? X : never : never; type EnumerateInternal = { 0: A; 1: EnumerateInternal, N>; }[N extends A['length'] ? 0 : 1]; /** Provides a literal of numbers from `0` until the previous one to the given. * The value must be an integer. * * * @example * ```ts * type _1 = Enumerate<5>; ; type _1 = 0 | 1 | 2 | 3 | 4 * type _2 = Enumerate<5.5>; ; type _2 = ❌ * ``` */ export type Enumerate = EnumerateInternal<[], N> extends (infer E)[] ? E : never; type TYear = `${number}${number}${number}${number}`; type TMonth = `${number}${number}`; type TDay = `${number}${number}`; type THours = `${number}${number}`; type TMinutes = `${number}${number}`; type TSeconds = `${number}${number}`; type TMilliseconds = `${number}${number}${number}`; /** * Represent a string like `2021-01-08` */ export type TDateISODate = `${TYear}-${TMonth}-${TDay}`; /** * Represents the possible input types for date-related HTML input elements. * * @typedef {('date' | 'month' | 'datetime-local' | 'week')} DateInputType * * @property {'date'} date - Represents a date input type (e.g., YYYY-MM-DD). * @property {'month'} month - Represents a month input type (e.g., YYYY-MM). * @property {'datetime-local'} datetime-local - Represents a date and time input type (e.g., YYYY-MM-DDTHH:MM). * @property {'week'} week - Represents a week input type (e.g., YYYY-Www). */ export type DateInputType = 'date' | 'month' | 'datetime-local' | 'week'; /** * Represent a string like `14:42` */ export type ClockTime = `${THours}:${TMinutes}`; /** * Represent a string like `14:42:34` */ export type ClockTimeWithSeconds = `${ClockTime}:${TSeconds}`; /** * Represent a string like `14:42:34.678` */ export type TDateISOTime = `${ClockTime}.${TMilliseconds}`; /** * Represent a string like `2021-01-08T14:42:34.678Z` (format: ISO 8601). * * It is not possible to type more precisely (list every possible values for months, hours etc) as * it would result in a warning from TypeScript: * "Expression produces a union type that is too complex to represent. ts(2590) */ export type TDateISO = `${TDateISODate}T${TDateISOTime}Z`; export {};