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
-
Install decoverto
yarn add decoverto
or
npm install decoverto
-
When using TypeScript, enable experimentalDecorators
in tsconfig.json
-
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>;
}
-
Create a Decoverto instance const decoverto = new Decoverto()
-
Convert some data
user = decoverto.type(User).rawToInstance(`{
"createdAt": "2021-03-31T14:08:42.009Z",
"givenName": "Mark",
"referralToken": null,
"permissions": {
"canManageUsers": true,
"canCreateProducts": true
}
}`);
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.