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
| Parameter | Type | Description |
|---|---|---|
value | any | The 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
| Parameter | Type | Description |
|---|---|---|
fn | Function | The function to dehydrate |
namedBindings? | Record<string, any> | Optional named bindings for the function |
Returns
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
| Parameter | Type | Description |
|---|---|---|
input | | string | DehydratedFunctionValue | The dehydrated function value or raw function string |
namedBindings? | Record<string, any> | Optional named bindings for the function |
Returns
T
The rehydrated function