Skip to content

Class: FunctionSerializer

A portable function serializer that can dehydrate and rehydrate functions from strings, with support for named bindings and various function types.

Methods

canSerialize()

ts
static canSerialize(value: any): boolean;

Check if a value can be serialized as a function

Parameters

ParameterTypeDescription
valueanyThe value to check

Returns

boolean

True if the value can be serialized, false otherwise


dehydrate()

ts
static dehydrate(fn: Function, namedBindings?: Record<string, any>): DehydratedFunctionValue;

Dehydrate a function into a serializable format

Parameters

ParameterTypeDescription
fnFunctionThe function to dehydrate
namedBindings?Record<string, any>Optional named bindings for the function

Returns

DehydratedFunctionValue

The dehydrated function value


rehydrate()

ts
static rehydrate<T>(input:
  | string
  | DehydratedFunctionValue, namedBindings?: Record<string, any>): T;

Rehydrate a function from its dehydrated format or raw function string

Type Parameters

Type Parameter
T extends (...args: any[]) => any

Parameters

ParameterTypeDescription
input| string | DehydratedFunctionValueThe dehydrated function value or raw function string
namedBindings?Record<string, any>Optional named bindings for the function

Returns

T

The rehydrated function