import { Not } from "./logic.cjs"; //#region src/number.d.ts type Numeric = number | bigint; type Zero = 0 | 0n; /** * Matches the hidden `Infinity` type. * * Please upvote [this issue](https://github.com/microsoft/TypeScript/issues/32277) if you want to have this type as a built-in in TypeScript. * * @see NegativeInfinity */ type PositiveInfinity = 1e999; /** * Matches the hidden `-Infinity` type. * * Please upvote [this issue](https://github.com/microsoft/TypeScript/issues/32277) if you want to have this type as a built-in in TypeScript. * * @see PositiveInfinity */ type NegativeInfinity = -1e999; /** * A finite `number`. * You can't pass a `bigint` as they are already guaranteed to be finite. * * Use-case: Validating and documenting parameters. * * Note: This can't detect `NaN`, please upvote [this issue](https://github.com/microsoft/TypeScript/issues/28682) if you want to have this type as a built-in in TypeScript. * * @example * ``` * import type {Finite} from 'type-fest'; * * declare function setScore(length: Finite): void; * ``` */ type Finite = T extends PositiveInfinity | NegativeInfinity ? never : T; /** * A `number` that is an integer. * * Use-case: Validating and documenting parameters. * * @example * ``` * type Integer = Integer<1>; * //=> 1 * * type IntegerWithDecimal = Integer<1.0>; * //=> 1 * * type NegativeInteger = Integer<-1>; * //=> -1 * * type Float = Integer<1.5>; * //=> never * * // Supports non-decimal numbers * * type OctalInteger: Integer<0o10>; * //=> 0o10 * * type BinaryInteger: Integer<0b10>; * //=> 0b10 * * type HexadecimalInteger: Integer<0x10>; * //=> 0x10 * ``` * * @example * ``` * import type {Integer} from 'type-fest'; * * declare function setYear(length: Integer): void; * ``` * * @see NegativeInteger * @see NonNegativeInteger */ type Integer = T extends unknown ? IsInteger extends true ? T : never : never; type IsInteger = T extends bigint ? true : T extends number ? number extends T ? false : T extends PositiveInfinity | NegativeInfinity ? false : Not> : false; type IsFloat = T extends number ? `${T}` extends `${string | number | bigint | boolean | null | undefined}${number}.${infer Decimal extends number}` ? Decimal extends Zero ? false : true : false : false; /** * A `number` that is not an integer. * * Use-case: Validating and documenting parameters. * * It does not accept `Infinity`. * * @example * ``` * import type {Float} from 'type-fest'; * * declare function setPercentage(length: Float): void; * ``` * * @see Integer */ type Float = T extends unknown ? IsFloat extends true ? T : never : never; /** * A negative (`-∞ < x < 0`) `number` that is not an integer. * Equivalent to `Negative>`. * * Use-case: Validating and documenting parameters. * * @see Negative * @see Float */ type NegativeFloat = Negative>; /** * A negative `number`/`bigint` (`-∞ < x < 0`) * * Use-case: Validating and documenting parameters. * * @see NegativeInteger * @see NonNegative */ type Negative = T extends Zero ? never : `${T}` extends `-${string}` ? T : never; /** * A negative (`-∞ < x < 0`) `number` that is an integer. * Equivalent to `Negative>`. * * You can't pass a `bigint` as they are already guaranteed to be integers, instead use `Negative`. * * Use-case: Validating and documenting parameters. * * @see Negative * @see Integer */ type NegativeInteger = Negative>; /** * A non-negative `number`/`bigint` (`0 <= x < ∞`). * * Use-case: Validating and documenting parameters. * * @see NonNegativeInteger * @see Negative * * @example * ``` * import type {NonNegative} from 'type-fest'; * * declare function setLength(length: NonNegative): void; * ``` */ type NonNegative = T extends Zero ? T : Negative extends never ? T : never; /** * A non-negative (`0 <= x < ∞`) `number` that is an integer. * Equivalent to `NonNegative>`. * * You can't pass a `bigint` as they are already guaranteed to be integers, instead use `NonNegative`. * * Use-case: Validating and documenting parameters. * * @see NonNegative * @see Integer * * @example * ``` * import type {NonNegativeInteger} from 'type-fest'; * * declare function setLength(length: NonNegativeInteger): void; * ``` */ type NonNegativeInteger = NonNegative>; /** * Returns a boolean for whether the given number is a negative number. * * @see Negative * * @example * ``` * import type {IsNegative} from 'type-fest'; * * type ShouldBeFalse = IsNegative<1>; * type ShouldBeTrue = IsNegative<-1>; * ``` */ type IsNegative = T extends Negative ? true : false; //#endregion export { Finite, Float, Integer, IsFloat, IsInteger, IsNegative, Negative, NegativeFloat, NegativeInfinity, NegativeInteger, NonNegative, NonNegativeInteger, Numeric, PositiveInfinity, Zero }; //# sourceMappingURL=number.d.cts.map