Introduction
Package description
Overview
When to use?
Example
Valid
import {
FunctionField, JTC, NumberField,
ObjectArrayMeta, ObjectMeta, StringField
} from '@taedr/jsontoclass';
class User {
public id: number;
public name: string;
public sayHi() {
console.log(`Hi! My name is ${this.name}.`);
}
}
const USER_META = new ObjectMeta({
builder: User,
fields: {
id: new NumberField(),
name: new StringField({ minLength: 3 }),
sayHi: new FunctionField(),
}
});
const users = [
{ id: 1, name: `Vasya` },
{ id: 2, name: `Petya` },
{ id: 3, name: `Masha` },
];
const result = JTC.convert({
id: `Users`,
meta: new ObjectArrayMeta({ meta: USER_META }),
values: users,
});
console.log(result.converted.all);
for (const user of result.converted.all) {
user.sayHi();
}Corrupted
Last updated