# funcster

> Function serialization and deserialization

Latest version **0.0.5** (published 2019-06-20) · 0 weekly downloads

## Install

```sh
npm install funcster
pnpm add funcster
yarn add funcster
bun add funcster
```

## Health

**Score 10/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support; low quality score; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.0.5 |
| Published | 2019-06-20 |
| First published | 2013-03-26 |
| Weekly downloads | 0 |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 2 |
| Unpacked size | 18.4 KB |
| Known vulnerabilities | 0 (+2 in 1 direct dependencies) |
| Install scripts | no |
| GitHub stars | 10 |
| Author | Jeff Lee |
| Maintainers | jeffomatic |
| Keywords | function, serialize, deserialize, serialization, deserialization |

## Links

- npm: https://www.npmjs.com/package/funcster
- Repository: https://github.com/jeffomatic/funcster
- Homepage: https://github.com/jeffomatic/funcster#readme
- Issues: http://github.com/jeffomatic/funcster/issues
- npm.io page: https://npm.io/package/funcster

## Dependencies (2)

- [deep](https://npm.io/package/deep.md) ~0.0.1
- [underscore](https://npm.io/package/underscore.md) ~1.4.4

## Recent versions

- 0.0.5 (latest) — 2019-06-20
- 0.0.4 — 2018-06-01
- 0.0.3 — 2013-10-21
- 0.0.2 — 2013-04-03
- 0.0.1 — 2013-03-26

## README

# funcster

This library contains utilities for serializing and deserializing functions. It provides recursive traversal to discover both serialized and unserialized functions nested within objects and arrays. This is particularly useful for embedding functions into JSON objects.

## Security warning

This package performs the equivalent of `eval`, and thus should only be used to deserialize functions delivered from trusted sources. Do not use any of the deserialization functions on strings fron untrusted sources.

## Installation

    npm install funcster

## Function reference

### serialize(function, [marker])

```js
serialize(function() { return "Hello world!" });
// -> { __js_function: 'function() { return "Hello world!" }' }
```

----

### deepSerialize(root, [marker])

```js
lib = {
  moduleA: {
    functions: {
      helloWorld: function() { return "Hello world!" }
    }
  },
  moduleB: {
    functions: {
      goodbyeWorld: function() { return "Goodbye world!" }
    }
  },
};

funcster.deepSerialize(lib);

// -> {
//      moduleA: {
//        functions: {
//          helloWorld: { __js_function: 'function() { return "Hello world!" }' }
//        }
//      },
//      moduleB: {
//        functions: {
//          goodbyeWorld: { __js_function: 'function() { return "Goodbye world!" }' }
//        }
//      },
//    }
```

----

### deepDeserialize(root, [marker, [moduleOpts]])

#### Security warning

`deepDeserialize` performs code evaluation on strings, and is susceptible to arbitrary code injection. Please make sure that `root` comes from a trusted source before using it.

#### Example

```js
serializedLib = {
  moduleA: {
    functions: {
      helloWorld: { __js_function: 'function() { return "Hello world!" }' }
    }
  },
  moduleB: {
    functions: {
      goodbyeWorld: { __js_function: 'function() { return "Goodbye world!" }' }
    }
  },
};

deserializedLib = funcster.deepDeserialize(serializedLib);
deserializedLib.moduleA.functions.helloWorld(); // -> Hello world!
deserializedLib.moduleB.functions.goodbyeWorld(); // -> Hello world!
```

Available options:

#### globals (object)

This option injects objects from the host context into the function evaluation context. The key is the name of the object inside the function evaluation context, and the value is the object in the host context.

```js
deserializedLib = funcster.deepDeserialize(serializedLib, {
  globals: { foo: true }
});
```

#### requires (object)

This option injects `require`-able modules into the function evaluation context. These modules will be **re-required** in the host context, generating distinct module objects to those that might already exist. This is a safer method of granting serialized functions access to common libraries.

```js
deserializedLib = funcster.deepDeserialize(serializedLib, {
  requires: { _: 'underscore' }
});
```

---
_Source: https://npm.io/package/funcster · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
