When it comes to open source, there are different ways you can contribute, all of which are valuable. Here's few guidelines that should help you as you prepare your contribution.
Before you start working on a contribution, create an issue describing what you want to build. It's possible someone else is already working on something similar, or perhaps there is a reason that feature isn't implemented. The maintainers will point you in the right direction.
The following steps will get you setup to contribute changes to this repo:
- Fork this repo.
- Clone your forked repo:
git clone git@github.com:{your_username}/rescript-schema.git
- Install pnpm if not available
npm i -g pnpm@8.14.3
- Run
pnpm i
to install dependencies. - Start playing with the code!
Make sure running the below commands in packages/rescript-schema-ppx/src
.
- Create a sandbox with opam
opam switch create rescript-schema-ppx 4.12.1
- Install dependencies
opam install . --deps-only
- Build
dune build --watch
- Test
Make sure running tests
(run compiler for lib)
npm run res
(run compiler for tests)
npm run test:res
(run tests in watch mode)
npm run test -- --watch
rescript-schema
import * as S from "rescript-schema@9.0.0-rc.2";
// Create login schema with email and password
const loginSchema = S.schema({
email: S.email(S.string),
password: S.stringMinLength(S.string, 8),
});
// Infer output TypeScript type of login schema
type LoginData = S.Output<typeof loginSchema>; // { email: string; password: string }
// Throws the S.Error(`Failed parsing at ["email"]. Reason: Invalid email address`)
S.parseOrThrow({ email: "", password: "" }, loginSchema);
// Returns data as { email: string; password: string }
S.parseOrThrow(
{
email: "jane@example.com",
password: "12345678",
},
loginSchema
);
valibot
import * as v from "valibot@0.42.1"; // 1.21 kB
// Create login schema with email and password
const LoginSchema = v.object({
email: v.pipe(v.string(), v.email()),
password: v.pipe(v.string(), v.minLength(8)),
});
// Infer output TypeScript type of login schema
type LoginData = v.InferOutput<typeof LoginSchema>; // { email: string; password: string }
// Throws error for `email` and `password`
v.parse(LoginSchema, { email: "", password: "" });
// Returns data as { email: string; password: string }
v.parse(LoginSchema, { email: "jane@example.com", password: "12345678" });
zod
import * as z from "zod";
// Create login schema with email and password
const LoginSchema = z.object({
email: z.string().email(),
password: z.string().min(8),
});
// Throws error for `email` and `password`
LoginSchema.parse({ email: "", password: "" });
// Returns data as { email: string; password: string }
LoginSchema.parse({ email: "jane@example.com", password: "12345678" });
By contributing your code to the rescript-schema GitHub repository, you agree to license your contribution under the MIT license.