get-flat
TypeScript icon, indicating that this package has built-in type declarations

1.0.5 • Public • Published

get-flat

Turn class instances into plain js objects making use of the instance's getters.

Turn this:

class Hat {
  private _hatName: string;

  constructor(hatName: string) {
    this._hatName = hatName;
  }

  public get hatName() {
    return this._hatName;
  }
}

Into this:

{
  hatName: 'name';
}

By doing this:

import { ObjectSerializer } from 'get-flat';

const serializer = new ObjectSerializer();

const hat = new Hat('name');
const flatHat = serializer.toPlainObject(hat);

Package Sidebar

Install

npm i get-flat

Weekly Downloads

1

Version

1.0.5

License

ISC

Unpacked Size

49.4 kB

Total Files

19

Last publish

Collaborators

  • ppicom