metarhia / metaschema

Schema definition and validation 💡
https://metarhia.com
MIT License
52 stars 19 forks source link

Calculated fields #425

Open georgolden opened 2 years ago

georgolden commented 2 years ago

Is your feature request related to a problem? Please describe.

    const schema = new Schema('File', {
      Entity: {},

      size: 'number',
      ratio: { method: (file) => file.size / 10, returns: 'number' },
    });
    const obj = { size: 100 };

    const obj1 = schema.calculate(obj);
    // Schema.check(obj);
    // Assign new calculated fields with given object

For memory only shorthand:

    const schema = new Schema('File', {
      size: 'number',
      ratio: (file) => file.size / 10,
    });
    const obj = { size: 100 };

    const obj1 = schema.calculate(obj);
    // Schema.check(obj);
    // Assign new calculated fields with given object
alexpodelinskii commented 2 years ago

I'll try to solve this issue