2.1.0 • Published 5 years ago

trem v2.1.0

Weekly downloads
25
License
MIT
Repository
gitlab
Last release
5 years ago

Installation

The library is available as a package on npm.

npm install --save trem

Usage

First, configure your entity/entities using the default annotations/hydrators, or create your own.

import { Entity, Number, String, BasicEntityHydrator } from 'trem';

@Entity({'potato$': BasicEntityHydrator})
export class Potato  {
    @Number('id', false) public id: number;
    @String('variety', true) public variety: string;
    @String('color', true) public color: string;
    @String('locations.0.country', true) public mainCountry: string;

    public isCommon(): boolean {
        return this.color === 'yellow';
    }

    // Add your own logic here
}

Then, use the responseHandler to do the mapping for you.

import { ResponseHandler } from 'trem';
import { Potato } from './potato';

class MyApiCaller {
  protected entityMapper: ResponseHandler;

  constructor() {
    this.entityMapper = new ResponseHandler([Potato /* Add your other entities here */])
  }

  public getData<T>(): T[] {
    // Your api call logic here
    return this.entityMapper.handle(url, responseData);
  }
}
2.1.0

5 years ago

2.0.0

5 years ago

1.1.0

5 years ago

1.0.3

5 years ago

1.0.2

5 years ago

1.0.1

5 years ago

1.0.0

5 years ago