Socket
Socket
Sign inDemoInstall

eval-serializer

Package Overview
Dependencies
3
Maintainers
1
Versions
11
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    eval-serializer

Easy to write serializer


Version published
Weekly downloads
12
Maintainers
1
Install size
806 kB
Created
Weekly downloads
 

Readme

Source

Eval-serializer

Easier to write serializations

Problem

You have tons of big configuration blob and want to have some good syntax on it. Usually it's not well supported for most of applications. I see visual studio provides great configuration with autocomplete feature, but it was burdensome for individual developer who wants to minimize requirements.

Solution

This project leverage JavaScript code evaluation(eval, but with some sandboxing), to allow configuration to be written in plain javascript syntax. By providing serialization method, this library allows to serialize/deserialize your configuration into well formatted JavaScript code. It's even possible to implement some code inside your configuration.

Caveats

Big disclaimer: Even though it tries its best to sandbox the eval context, it's always possible that there's a security risk I missed to address. Only use this library when the configuration cannot be modified by 3rd party.

Small caveat: Even though this library is written in TypeScript and supports type definitions, it does not support serializing data into TypeScript format.

Usage

You need to decorate all the classes which occurs in your serialization.

import * as ES from "eval-serializer";
class Foo { ... };
// Expect instance of `Foo` can be created via `new Foo(param1, param2)`
ES.decorate(Foo, (obj) => [ obj.param1, obj.param2 ] );
console.log(ES.toString(new Foo("p1", "p2")));
const serialized = '...';
const obj = new Function('Foo', serialized)(Foo); // generates original object

TODO

Type helpers

I'd like to see IDE to suggest type informations.

Example: Serializer generates .ts file with type reference link, and provide .d.ts file which contains type informations.

Keywords

FAQs

Last updated on 27 Dec 2020

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc