1.138.0 • Published 10 months ago

@biorate/auto-object v1.138.0

Weekly downloads
-
License
MIT
Repository
github
Last release
10 months ago

Auto object

Auto initialized object

Examples:

class Geo extends Array<number> {}

class Address extends AutoObject<Address> {
  @IsString()
  public city: string;

  @IsString()
  public street: string;

  @IsNumber()
  public apartment: number;

  @IsNumber()
  public postal: number;

  @IsArray()
  public geo: Geo;

  public get inline() {
    return <Getter<string>>(
      `${this.postal}, ${this.city}, ${this.street} №${this.apartment}`
    );
  }
}

class User extends AutoObject<User> {
  @IsInt()
  public id: number;

  @IsString()
  public firstName: string;

  @IsString()
  public lastName: string;

  @IsObject()
  @ValueObject(Address)
  public address: Address;
}

const user = new User({
  id: 1,
  firstName: 'Vasya',
  lastName: 'Pupkin',
  address: {
    city: 'Moscow',
    street: 'Gogolya',
    postal: 123321,
    apartment: 74,
    geo: [12321, 32123],
  },
});

console.log(user); // User {
//   "address": Address {
//     "city": "Moscow",
//     "apartment": 74,
//     "geo": Array [
//       12321,
//       32123,
//     ],
//     "postal": 123321,
//     "street": "Gogolya",
//   },
//   "firstName": "Vasya",
//   "id": 1,
//   "lastName": "Pupkin",
// }

Learn

  • Documentation can be found here - docs.

Release History

See the CHANGELOG

License

MIT

Copyright (c) 2021-present Leonid Levkin (llevkin)

1.138.0

10 months ago

1.137.0

10 months ago

1.136.1

10 months ago

1.136.0

10 months ago

1.135.0

10 months ago

1.122.0

10 months ago

1.121.0

10 months ago

1.120.0

10 months ago