Skip to content

Latest commit

 

History

History
22 lines (18 loc) · 403 Bytes

Custom types.md

File metadata and controls

22 lines (18 loc) · 403 Bytes
import * as data from 'maeva';

const Email = data.type(
  'email',
  String,
  null,
  value => {
    if (!/^.+@.+\..+$/.test(value)) {
      throw new TypeError('Expecting a valid email');
    }
  },
);

const users = data.model('users', {email: Email});

// this will fail
await data.insertOne(users, {email: 'joe'});

// this will work
await data.insertOne(users, {email: '[email protected]'});