import type { Nullish, PrimitiveTypes, TypeofMapping, } from "../../types/common.mjs"; import type { OmitKey } from "../../types/object.mjs"; import type { Validator } from "./common.mjs"; export const isPrimitive: Validator = ( value ): value is PrimitiveTypes => (typeof value !== "object" && typeof value !== "function") || value === null; export const isString: Validator = (value): value is string => typeof value === "string"; export const isNumber: Validator = (value): value is number => typeof value === "number"; export const isBoolean: Validator = (value): value is boolean => typeof value === "boolean"; export const isSymbol: Validator = (value): value is symbol => typeof value === "symbol"; export const isBigint: Validator = (value): value is bigint => typeof value === "bigint"; export const isUndefined: Validator = (value): value is undefined => value === undefined; export const isNull: Validator = (value): value is null => value === null; export const isNullish: Validator = (value): value is Nullish => value == null; type PrimitiveOnlyTypeofMapping = OmitKey; export const typeofIs = (typeName: K): Validator => (value): value is TypeofMapping[K] => typeof value === typeName; export const isPrimitiveOf: ( typename: K ) => Validator = typeofIs; export const primitiveOf = isPrimitiveOf;