pipe (位)
Schemas may become hard to read as nesting grows, which may be solved by function composition in the form of the provided pipe
utility function.
import { nonEmpty, nullable, pipe, string } from '@typeofweb/schema';
pipe(string, nullable, nonEmpty);
// is equivalent to
nonEmpty(nullable(string()));
位
is an alias for pipe
:
import { nonEmpty, minStringLength, nil, 位, object, string } from '@typeofweb/schema';
const blogSchema = object({
title: 位(string, minStringLength(10)),
description: 位(string, nil),
href: 位(string, nil, nonEmpty),
rssUrl: 位(string, nil, nonEmpty),
})();