types-json
Version:
Type checking for JSON values
45 lines (44 loc) • 3.59 kB
TypeScript
import { z } from "zod";
import { JSONPrimitive, OptionalJSONPrimitive } from "./primitive/index.js";
import { Optional } from "./optional.js";
export type JSONValue = JSONPrimitive | JSONObject | JSONArray;
export type NestedOptionalJSONValue = JSONPrimitive | NestedOptionalJSONObject | NestedOptionalJSONArray;
export type OptionalJSONValue = OptionalJSONPrimitive | OptionalJSONObject | OptionalJSONArray;
export declare const jsonValueSchema: z.ZodType<JSONValue>;
export declare const optionalJSONValueSchema: z.ZodType<OptionalJSONValue>;
export declare const isJSONValue: (value: unknown) => value is JSONValue;
export declare const isNestedOptionalJSONValue: (value: unknown) => value is NestedOptionalJSONValue;
export declare const isOptionalJSONValue: (value: unknown) => value is OptionalJSONValue;
export declare const parseJSONValue: (value?: unknown) => JSONValue | undefined;
export declare const parseNestedOptionalJSONValue: (value?: unknown) => NestedOptionalJSONValue | undefined;
export declare const parseOptionalJSONValue: (value?: unknown) => OptionalJSONValue;
export type JSONArray = Array<JSONValue>;
export type NestedOptionalJSONArray = Array<NestedOptionalJSONValue>;
export type OptionalJSONArray = Optional<Array<NestedOptionalJSONValue>>;
export declare const jsonArraySchema: z.ZodArray<z.ZodType<JSONValue, z.ZodTypeDef, JSONValue>, "many">;
export declare const nestedOptionalJSONArraySchema: z.ZodArray<z.ZodType<NestedOptionalJSONValue, z.ZodTypeDef, NestedOptionalJSONValue>, "many">;
export declare const optionalJSONArraySchema: z.ZodArray<z.ZodType<NestedOptionalJSONValue, z.ZodTypeDef, NestedOptionalJSONValue>, "many">;
export declare const isJSONArray: (value: unknown) => value is JSONValue[];
export declare const isNestedOptionalJSONArray: (value: unknown) => value is NestedOptionalJSONValue[];
export declare const isOptionalJSONArray: (value: unknown) => value is NestedOptionalJSONValue[];
export declare const parseJSONArray: (value?: unknown) => JSONValue[] | undefined;
export declare const parseNestedOptionalJSONArray: (value?: unknown) => NestedOptionalJSONValue[] | undefined;
export declare const parseOptionalJSONArray: (value?: unknown) => NestedOptionalJSONValue[] | undefined;
export type JSONObject = {
[key in string]: JSONValue;
};
export type NestedOptionalJSONObject = {
[key in string]?: NestedOptionalJSONValue;
};
export type OptionalJSONObject = Optional<NestedOptionalJSONObject>;
export declare const jsonObjectSchema: z.ZodRecord<z.ZodString, z.ZodType<JSONValue, z.ZodTypeDef, JSONValue>>;
export declare const nestedOptionalJSONObjectSchema: z.ZodRecord<z.ZodString, z.ZodType<OptionalJSONValue, z.ZodTypeDef, OptionalJSONValue>>;
export declare const optionalJSONObjectSchema: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodType<OptionalJSONValue, z.ZodTypeDef, OptionalJSONValue>>>;
export declare const isJSONObject: (value: unknown) => value is Record<string, JSONValue>;
export declare const isNestedOptionalJSONObject: (value: unknown) => value is Record<string, OptionalJSONValue>;
export declare const isOptionalJSONObject: (value: unknown) => value is Record<string, OptionalJSONValue> | undefined;
export declare const parseJSONObject: (value?: unknown) => Record<string, JSONValue> | undefined;
export declare const parseNestedOptionalJSONObject: (value?: unknown) => Record<string, OptionalJSONValue> | undefined;
export declare const parseOptionalJSONObject: (value?: unknown) => Record<string, OptionalJSONValue> | undefined;
export * from "./optional.js";
export * from "./primitive/index.js";