transferable-function
TypeScript icon, indicating that this package has built-in type declarations

1.2.3 • Public • Published

Transferable function

Serialize and deserialize function or lambda to json available plane object.

  • typescript available
  • does not use eval

Installation

npm i transferable-function

Description

This utils extract function body and arg names to plane object named Transferable function like this:

import {serializeFn} from 'transferable-function' 

const transferable = serializeFn((a, b) => return a + b)
// transferable: 
// {
//     body: 'return a + b',
//     argNames: ['a', 'b']
// }

fetch('pass/fn/path', {
  method: 'POST',
  body: JSON.stringify(transferable)
})

Further you can pass this object by json and convert back

import {deserializeFn} from 'transferable-function' 

app.post('pass/fn/path', (req, res) => {
  const customFn = deserializeFn(req.body)
  res.send(customFn(1, 2)) // send 3
})

/transferable-function/

    Package Sidebar

    Install

    npm i transferable-function

    Weekly Downloads

    6

    Version

    1.2.3

    License

    MIT

    Unpacked Size

    24.9 kB

    Total Files

    15

    Last publish

    Collaborators

    • lonelygriffin