getit-js

0.2.2 • Public • Published

npm version

getit-js

This is a small helper package for parsing API Responses. This is still under construction.

Usage

Create classes that extend AbstractModel

Example

class OtherClass extends AbstractModel {
  description!: string

  protected getMappingConfig (): IMappingConfig {
    return {
      mappings: [
        {
          key: 'description'
        }
      ]
    }
  }
}

class User extends AbstractModel {
  loading: false
  reference!: number
  email!: string
  details!: OtherClass

  protected getMappingConfig (): IMappingConfig {
    return {
      mappings: [
        {
          key: 'reference',
          sourceKey: 'id'
        },
        {
          key: 'email'
        },
        {
          key: 'details',
          type: EMappingType.MODEL,
          model: OtherClass
        }
      ]
    }
  }

  public beforeUpdate () {
    this.loading = true
    super.beforeUpdate()
  }
}

Note: snake_case will be parsed to camelCase by default.

Contributions

Feel free to add feedback, and ideas to make this better :)

Readme

Keywords

Package Sidebar

Install

npm i getit-js

Weekly Downloads

0

Version

0.2.2

License

MIT

Unpacked Size

33 kB

Total Files

16

Last publish

Collaborators

  • leopold.kamp