rivo
Version:
🤖 The ultimate library you need for composable type-level programming in TypeScript, powered by HKT.
26 lines (23 loc) • 710 B
TypeScript
// @ts-ignore - Only used in doc comments
import type { Nat } from ".";
import type { Args, Fn } from "../../HKT";
import type { Every } from "../../List/Every";
import type IsDigitFn from "../../Str/IsDigit";
import type { ToChars } from "../../Str/ToChars";
import type { AssertBool } from "../../helpers";
/**
* Check if a value is {@link Nat}.
*
* Sig: `(x: unknown) => boolean`
*/
export type IsNat<T> = AssertBool<
T extends string | number | bigint ? Every<IsDigitFn, ToChars<`${T}`>> : false
>;
/**
* [Fn] Check if a value is {@link Nat}.
*
* Sig: `(x: unknown) => boolean`
*/
export default interface IsNatFn extends Fn<[unknown], boolean> {
def: ([x]: Args<this>) => IsNat<typeof x>;
}