Runkit
Runkit
home page
user forum
new notebook
clone notebook
download notebook
support & documentation
log in
sign up
new notebook
help & feedback
clone this notebook
download this notebook
Sign In
Sign Up
RunKit + npm: superstruct
node v8.17.0
endpoint
share
tweet
var superstruct = require("superstruct") const User = superstruct.struct({ id: 'number', name: 'string', }) const Article = superstruct.struct({ id: 'number', title: 'string', author: User, }, { author: { id: 1000, name: 'Owner', }, }) const article1 = Article({ id: 1, title: 'This works as expected', author: { id: 2, name: 'Contributor', }, }) console.log(article1.author) const article2 = Article({ id: 1, title: 'This does not work!', }) console.log(article2.author)
Created from: https://npm.runkit.com/superstruct
Loading…
Clone and edit this document