Validación de datos simple en JavaScript-superstruct
| Autor: | ianstormtaylor |
|---|---|
| Views Total: | 1,182 |
| Sitio oficial: | Ir a la web |
| Actualizado: | October 19, 2018 |
| Licencia: | MIT |
Vista prévia
Descripción
¿Cómo funciona?
# Yarn $ yarn add superstruct # NPM $ npm install superstruct --save
import { struct } from 'superstruct' const User = struct({
id: 'number',
name: 'string',
email: 'string',
age: 'number',
departments: ['string'],
is_admin: 'boolean?',
}) const data = {
id: 1,
name: 'Jane Smith',
email: '[email protected]',
age: 42,
departments: ['engineering', 'product'],
}
try {
User(data)
console.log('Valid!')
} catch (e) {
throw e
} Registro de cambios
10/18/2018
- v0.6.0





