Skip to content

Variable: createDecodeBudget() ​

ts
const createDecodeBudget: (limits?: DecodeLimits) => DecodeBudget;

Creates an opaque budget sharing total inflated bytes across decode() calls. Limits are merged with DEFAULT_DECODE_LIMITS and must be positive finite numbers or Infinity; invalid values throw TypeError. Depth remains per call and array-length caps remain per value. Diagnostics are read-only.

maxInflatedBytes counts each byte of inflated data once: nested layers are charged only for growth beyond their own encoded input, which is already part of the parent layer's inflated output. Transient gross allocation is bounded by roughly maxDepth × maxInflatedBytes.

Parameters ​

ParameterType
limits?DecodeLimits

Returns ​

DecodeBudget

Example ​

ts
const budget = createDecodeBudget();
const schema = decode<{ datetimeFormats: string[] }>(payload, { budget });
const formats = schema.datetimeFormats.map((flag) => decode(flag, { budget }));