Skip to content

➰ node.js function serialization

Notifications You must be signed in to change notification settings

cloud-elements/cardigan

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

36 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

cardigan | node.js function serialization

version versioning branching styling build

Install

$ npm install --save cardigan

Usage

Function serialization:

const {serialize} = require('cardigan');

const add = serialize((a, b) => a + b);
const subtract = serialize((a, b) => a - b);

// Do something with serialized functions (e.g. send to supporting FaaS, save to disk)

PROTIP: Functions should not reference anything outside their lexical scope.

Function deserialization:

const {deserialize, serialize} = require('cardigan');

const add = serialize((a, b) => a + b);
const subtract = serialize((a, b) => a - b);

const add2And3 = deserialize(add)(2, 3); // 5
const subtract3And2 = deserialize(subtract)(3, 2); // 1

Supported Function Types

Function expressions:

function (a) { ... }

Async function expressions:

async function (a) { ... }

Unary arrow functions:

a => { ... }

Async unary arrow functions:

async a => { ... }

Polyadic arrow functions:

(a, b) => { ... }

Async polyadic arrow functions:

async (a, b) => { ... }

Maintainers

About

➰ node.js function serialization

Resources

Stars

Watchers

Forks

Packages

No packages published