import type * as T from '@traversable/registry'; import type { Json } from './exports.js'; /** * ## {@link Scalar `Json.Scalar`} * * a.k.a "leaves" or "terminal nodes" * * Note: strictly speaking, `undefined` is not a valid JSON value. It's * included here because in practice `JSON.stringify(undefined)` returns * `undefined` instead of the empty string. */ export type Scalar = undefined | null | boolean | number | string; /** * ## {@link Fixpoint `Json.Fixpoint`} * * This type represents the what's called (to get math-y) * the "fixpoint" of the Json Functor. * * There are reasons to use {@link Fixpoint `Json.Fixpoint`} over * {@link Unary `Json.Unary`}, and vice-versa. * * Note that, on the one hand, this definition is correct. * * On the other hand, it's also infinite. And since types * aren't tied to actual data, we don't have a type-level * "base case" we can fall back on. * * In fact, the only reason our IDE doesn't start * slogging is because TypeScript compiler does extra work * to "cache" this type, and detect the circular reference. * * While this type happens to work in this case, it's also brittle: * a small change in its definition could cause the TS compiler to * cache things differently, and we might wind up with a very * difference performance profile. * * If you'd prefer to avoid this problem (and others like it), use * {@link Unary `Json.Unary`} instead. */ export type Fixpoint = Scalar | readonly Fixpoint[] | { [x: string]: Fixpoint; }; export type NonJson = symbol | bigint | globalThis.Date | globalThis.RegExp | globalThis.Set | globalThis.Map | { (...args: any): any; }; export type Mut = [T] extends [infer U extends Scalar] ? U : { -readonly [I in keyof T]: Mut; }; /** * ## {@link Unary `Json.Unary`} * * Non-recursive definition of JSON. * * Non-recursive because the recursion is "factored out". * * The use case for {@link Unary `Json.Unary`} is when you've * also factored the recursion out of a recursive algorithm, which is * what this project is all about: leveraging well-known, well-founded * ideas from math to "factor out" recursion. */ export type Unary = Scalar | readonly T[] | { [x: string]: T; }; /** * ## {@link Free `Json.Free`} * * Like {@link Unary `Json.Unary`}, but unapplied. */ export interface Free extends T.HKT { [-1]: Unary; } export declare const isScalar: (x: unknown) => x is string | number | boolean | null | undefined; export declare const isArray: (x: unknown) => x is readonly T[]; export declare const isObject: (x: unknown) => x is { [x: string]: T; }; /** * ## {@link isJson `Json.is`} * * Validates that its input is a valid JSON value. * * **Note:** the implementation of {@link is `Json.is`} * is recursive. */ export declare function isJson(u: unknown): u is Json; /** * ## {@link Functor `Json.Functor`} * * You can think of a Functor as a container. It exposes * a port called `map` that lets us apply an arbitrary * function to the value(s) inside. */ export declare const Functor: T.Functor; export declare const defaultIndex: { depth: number; path: (string | number)[]; }; export declare namespace Functor { interface Index { depth: number; path: (string | number)[]; } } export declare const fold: (g: (src: Unary, ix: Functor.Index, x: Fixpoint) => T) => { (src: Unary, ix?: Functor.Index | undefined): T; (src: Fixpoint, ix?: Functor.Index | undefined): T; (src: Unary, ix?: Functor.Index | undefined): T; }; export declare const unfold: (coalgebra: T.Coalgebra) => (expr: S) => Unary; export declare const foldWithIndex: (algebra: T.IndexedAlgebra) => (term: S, ix: Functor.Index) => T; /** * ## {@link toString `Json.toString`} */ export declare const toString: (x: unknown) => string; //# sourceMappingURL=functor.d.ts.map