Published
Edited
May 14, 2019
1 star
Insert cell
Insert cell
Insert cell
Insert cell
{
const frozenObject = deepFreeze({
foo: ["bar"],
})
frozenObject.baz = "spam"
frozenObject.foo.push("baz")
}
Insert cell
Insert cell
Insert cell
{
immer.setAutoFreeze(true)
const obj = { foo: ["bar"] }
const producedObject = immer.produce(obj, state => {
state.baz = "baz"
state.foo = ["bar"]
})
producedObject.baz = "spam"
producedObject.foo.push("baz")
}
Insert cell
Insert cell
Insert cell
{
const obj = { foo: 1, bar: ["baz"] }
check.assert.assigned(obj.baz)
check.assert.includes(obj.bar, "quux")
}
Insert cell
check.assert.assigned(null)
Insert cell
check.assert.assigned(undefined)
Insert cell
check.assert.not.assigned(1)
Insert cell
Insert cell
Insert cell
t.Nil(1)
Insert cell
t.Nil(null)
Insert cell
t.Nil(undefined)
Insert cell
t.Nil.is(null)
Insert cell
{
t.NotNil = t.refinement(t.Nil, value => !t.Nil.is(value), "NotNil")
t.NotNil(null)
}
Insert cell
{
function sum(a, b) {
t.Number(a)
t.Number(b)
return a + b
}

sum(1, "s")
}
Insert cell
{
const Person = t.struct({
name: t.String,
surname: t.maybe(t.String),
age: t.Integer,
tags: t.list(t.String)
}, "Person")

Person.prototype.getFullName = function () {
return `${this.name} ${this.surname}`
}

const person = Person({
surname: "Canti",
})
}
Insert cell
Insert cell
Insert cell
{
ow(1, ow.number.not.infinite);

ow('', ow.string.not.empty);
//=> ArgumentError: [NOT] Expected string to be empty, got ``
}
Insert cell
{
ow(1, ow.number.is(x => x < 10));

ow(1, ow.number.is(x => x > 10));
//=> ArgumentError: Expected `1` to pass custom validation function
}
Insert cell
ow(1, ow.optional.number)
Insert cell
ow(undefined, ow.optional.number)
Insert cell
ow(null, ow.optional.number)
Insert cell
ow(1, ow.nullOrUndefined)
Insert cell
ow(undefined, ow.object)
Insert cell
ow(null, ow.object)
Insert cell
ow("", ow.any(ow.string.empty, ow.string.startsWith("/")))
Insert cell
ow("/", ow.any(ow.string.empty, ow.string.startsWith("/")))
Insert cell
ow("1", ow.any(ow.string.empty, ow.string.startsWith("/")))
Insert cell
ow.isValid(1, ow.number)
Insert cell
ow.isValid("", ow.number)
Insert cell
unicorn = {
return {
rainbow: "🌈",
stars: {
value: "🌟"
},
}
}
Insert cell
ow(unicorn, ow.object.exactShape({
rainbow: ow.string,
stars: {
value: ow.number,
},
}))
Insert cell
Insert cell
is('🦄');
//=> 'string'
Insert cell
is(new Map());
//=> 'Map'
Insert cell
is.number(6);
//=> true
Insert cell
Insert cell
Insert cell
{
const schema = Joi.object().keys({
username: Joi.string().alphanum().min(3).max(30).required(),
password: Joi.string().regex(/^[a-zA-Z0-9]{3,30}$/),
access_token: [Joi.string(), Joi.number()],
birthyear: Joi.number().integer().min(1900).max(2013),
email: Joi.string().email({ minDomainSegments: 2 })
}).with('username', 'birthyear').without('password', 'access_token');
Joi.validate({ username: 'abc', birthyear: 1994 }, schema);
return Joi.validate({ username: '', birthyear: 1994 }, schema);
}
Insert cell
Joi.validate(undefined, Joi.string())
Insert cell
Joi.validate(undefined, Joi.string().required())
Insert cell
Joi.validate(1, Joi.any())
Insert cell
Joi.validate(null, Joi.any())
Insert cell
Joi.validate(undefined, Joi.any())
Insert cell
Joi.validate(undefined, Joi.any().required())
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
user = {
return {
email: "foo@bar.com",
address: null,
name: {
first: "John",
last: null,
middle: null,
},
}
}
Insert cell
Maybe.of(() => user.name.first).join()
Insert cell
Maybe.of(() => user.address.zipCode).join()
Insert cell
Maybe.of(user)
.prop('name')
.prop('first')
.join()
Insert cell
Maybe.of(user)
.prop('address')
.prop('zipCode')
.join()
Insert cell
Insert cell
Insert cell
pretty({ foo: 1, bar: ["baz"] })
Insert cell
pretty.one({ foo: 1, bar: ["baz"] })
Insert cell
pretty.zero({ foo: 1, bar: ["baz"] })
Insert cell

Purpose-built for displays of data

Observable is your go-to platform for exploring data and creating expressive data visualizations. Use reactive JavaScript notebooks for prototyping and a collaborative canvas for visual data exploration and dashboard creation.
Learn more