New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

eval-serializer

Package Overview
Dependencies
Maintainers
1
Versions
11
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

eval-serializer

Easy to write serializer

  • 0.3.2
  • latest
  • npm
  • Socket score

Version published
Maintainers
1
Created
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

Package last updated on 27 Dec 2020

Did you know?

Socket

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
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc