import { shape } from "muoto"
function bob (thing) {
if (!shape({
foo: 1,
bar: shape.number,
baz: shape.string,
fuzz: shape.bool,
})(thing).valid) throw new Error("Passed in the wrong thing")
}
bob({ foo:1, bar:1, baz:"a", fuzz:true })
bob()
bob({})
bob({ foo:2, bar:1, baz:"a", fuzz:true })
function greater_than (n) {
return function (value, cursor, tools) {
if (tools.is.NUMBER(value)) return tools.Nope(cursor, value, cursor + " needs to be a number")
if (value <= n) return tools.Nope(cursor, value, cursor + " needs to be greater than " + n + ", but was " + value)
return tools.Just(cursor, value)
}
}
var check = shape({ foo:greater_than(4) })
check({ foo:9 }).valid
check({ foo:3 }).valid
check({ foo:19 }).valid
shape([1])([1, 1, 1, 1]).valid
shape([1])([1, 2, 1, 1]).valid
shape([1, 2, 1, 1])([1, 2, 1, 1]).valid
shape([1, 2, 1, 1])([1, 1, 1, 1]).valid
shape([{ foo:shape.number }])([ { foo:1 }, { foo:2 }, { foo:3} ]).valid
shape(shape.number, { blocking: true })("b")
shape(shape.number, { logging: true })("b")
var shp = shape({ foo:[{ bar:1 }] })({ foo:[{ bar:1 }, { bar:1 }, { bar:2 }, { bar:1 }] })
shp.valid
shp.cursor
shape(shape.number, { bypass:true })("a").valid