0.0.1 • Published 4 years ago

revil v0.0.1

Weekly downloads
1
License
MIT
Repository
github
Last release
4 years ago

Revil

Convert JSON to class

Installation

yarn add revil

or

npm install revil

Usage

import { toClass } from "revil";

or;

const { toClass } = require("revil");

Example

class Person {
  lastName: string = "";
  firstName: string = "";
  occupation: string = "";
}

const json = {
  lastName: "Doe",
  firstName: "John",
  bio: {
    occupation: "doctor"
  }
};

const person = toClass(Person).from(json);

Note

  • toClass return an instance of the class passed.
  • toClass traverses the entire object to find deeply nested values.

Methods

nametypedescription
excludeArrayspecify values to be excluded.
onlyArrayspecify values to be selected only.
pluckArrayspecify values to be included along the defaults.
fromObjectextracts and returns values from the object into the class instance.

Example

const person = toClass(Person)
  .only("lastName", "occupation")
  .from(json);

Other methods are optional. But if you need to call any of them, they must be called before calling .from().