flexdinesh/typy

[Feature] Include custom types in schema validation

Open

#17 aperta il 14 gen 2019

Vedi su GitHub
 (0 commenti) (4 reazioni) (0 assegnatari)JavaScript (21 fork)github user discovery
enhancementhelp wanted

Metriche repository

Star
 (226 star)
Metriche merge PR
 (Metriche PR in attesa)

Descrizione

Like so:

import { addCustomTypes } from 'typy';

addCustomTypes({
  isFirstName: input => 3 <= input.length && input.length <= 15,
  isLastName: input => 3 <= input.length && input.length <= 15
});
import t, { Schema } from 'typy';

const schema = { 
  firstName: Schema.isFirstName,
  lastName: Schema.isLastName
}

t({
  firstName: 'John',
  lastName: 'Doe'
}, schema);

Guida contributor