Socket
Socket
Sign inDemoInstall

decoverto

Package Overview
Dependencies
1
Maintainers
1
Versions
13
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    decoverto

Converts data such as JSON to JS/TS classes and back using decorators


Version published
Maintainers
1
Created

Changelog

Source

1.0.4 (2022-05-25)

  • Remove erroneous space before property name in DV1000

Readme

Source

npm version Build Status Code coverage License

Decoverto

Convert data into instances of first and third party classes and back using decorators. Enjoy not having to write data-to-class setup code.

Test and tinker on the Decoverto playground

Features

A model looks like this:

import {model, map, MapShape, property} from 'decoverto';

@model()
class User {

    @property()
    createdAt: Date;

    @property()
    givenName: string;

    @property(() => String)
    referralToken: string | null;

    @property(map(() => String, () => Boolean, {shape: MapShape.Object}))
    permissions: Map<string, boolean>;
}

Quickstart

  1. Install decoverto

    yarn add decoverto
    

    or

    npm install decoverto
    
  2. When using TypeScript, enable experimentalDecorators in tsconfig.json

  3. Define a model

    import {model, map, MapShape, property} from 'decoverto';
    
    @model()
    class User {
    
        @property(() => Date)
        createdAt: Date;
    
        @property(() => String)
        givenName: string;
    
        @property(() => String)
        referralToken: string | null;
    
        @property(map(() => String, () => Boolean, {shape: MapShape.Object}))
        permissions: Map<string, boolean>;
    }
    
  4. Create a Decoverto instance const decoverto = new Decoverto()

  5. Convert some data

    // Convert raw data using the default JSON parser
    user = decoverto.type(User).rawToInstance(`{
        "createdAt": "2021-03-31T14:08:42.009Z",
        "givenName": "Mark",
        "referralToken": null,
        "permissions": {
            "canManageUsers": true,
            "canCreateProducts": true
        }
    }`);
    
    // Convert an object literal
    user = decoverto.type(User).plainToInstance({
        createdAt: new Date(),
        givenName: 'Mark',
        referralToken: null,
        permissions: {
            canManageUsers: true,
            canCreateProducts: true,
        }
    });
    

For more information, see links in the features list or the docs directory.

Examples/Playground

Decoverto has playgrounds where you can view examples and tinker with them. It allows you to see what is possible and experiment.

Keywords

FAQs

Last updated on 25 May 2022

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