Skip to content

Commit

Permalink
ops: publish to jsr.io
Browse files Browse the repository at this point in the history
  • Loading branch information
jasonraimondi committed Mar 26, 2024
1 parent e276a1b commit ad46f6e
Show file tree
Hide file tree
Showing 8 changed files with 58 additions and 105 deletions.
31 changes: 7 additions & 24 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,6 @@ on:
pull_request:
push:

env:
DENO_VERSION: v1.x

jobs:
test:
if: "!contains(github.event.head_commit.message, '[skip ci]')"
Expand All @@ -15,7 +12,7 @@ jobs:
- uses: actions/checkout@v3
- uses: denoland/setup-deno@v1
with:
deno-version: ${{ env.DENO_VERSION }}
deno-version: 1.x
- run: deno fmt --check
- run: deno test --coverage=./coverage
- run: deno coverage ./coverage --lcov --output=coverage/lcov.info
Expand All @@ -29,26 +26,12 @@ jobs:
env:
CC_TEST_REPORTER_ID: ${{ secrets.CC_TEST_REPORTER_ID }}

publish:
publish-jsr:
needs: test
if: startsWith(github.ref, 'refs/tags/')
runs-on: ubuntu-latest
permissions:
contents: read
id-token: write
steps:
- uses: actions/checkout@v3
- uses: pnpm/[email protected]
with:
version: 7
- uses: denoland/setup-deno@v1
with:
deno-version: ${{ env.DENO_VERSION }}
- uses: actions/setup-node@v3
with:
node-version: '18.x'
registry-url: 'https://registry.npmjs.org'
- run: echo ${{ github.ref_name }} > VERSION
- run: cat VERSION
- run: deno run -A bin/build_npm.ts ${{ github.ref_name }}
- run: npm publish --access=public
working-directory: ./npm
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
- uses: actions/checkout@v4
- run: npx jsr publish
24 changes: 10 additions & 14 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
# Zod Friendly Forms

[![Deno Version](https://shield.deno.dev/x/zod_ff?style=flat-square)](https://deno.land/x/zod_ff)
[![Npmjs.org Version](https://img.shields.io/npm/v/zod-ff?style=flat-square)](https://www.npmjs.com/package/zod-ff)
[![JSR](https://jsr.io/badges/@jmondi/zod-friendly-forms)](https://jsr.io/@jmondi/zod-friendly-forms)
[![JSR Score](https://jsr.io/badges/@jmondi/zod-friendly-forms/score)](https://jsr.io/@jmondi/zod-friendly-forms)
[![GitHub Workflow Status](https://img.shields.io/github/actions/workflow/status/jasonraimondi/zod-friendly-forms/test.yml?branch=main&label=Unit%20Tests&style=flat-square)](https://github.com/jasonraimondi/zod-friendly-forms)
[![Test Coverage](https://img.shields.io/codeclimate/coverage/jasonraimondi/zod-friendly-forms?style=flat-square)](https://codeclimate.com/github/jasonraimondi/zod-friendly-forms/test_coverage)
[![NPM Downloads](https://img.shields.io/npm/dt/zod-ff?label=npm%20downloads&style=flat-square)](https://www.npmjs.com/package/zod-ff)

Returns an object containing `errors` and `validData`. The `errors` object
contains user-friendly error messages, making it easy to display validation
Expand All @@ -16,13 +15,14 @@ submissions.
## Install (npm)

```bash
pnpm add zod-ff zod
pnpm add zod
pnpm dlx jsr add @jmondi/zod-friendly-forms
```

### Deno

```ts
import { parseForm } from "https://deno.land/x/zod_ff";
```bash
deno add @jmondi/zod-friendly-forms
```

## Usage
Expand All @@ -40,7 +40,7 @@ When you're ready to validate your input data, go ahead and run the `parseForm`
function. If there are any errors, they will be available by input key.

```ts
import { parseForm } from "zod-ff";
import { parseForm } from "@jmondi/zod-friendly-forms";

const data = {
email: "invalid-email",
Expand All @@ -57,7 +57,7 @@ If errors are undefined, the input was valid. A returned `validData` object will
be typed with your response.

```ts
import { parseForm } from "zod-ff";
import { parseForm } from "@jmondi/zod-friendly-forms";

const data = {
email: "[email protected]",
Expand Down Expand Up @@ -117,7 +117,7 @@ This library will work on the server or client, in any framework.
```html
<script lang="ts">
import { z } from "zod";
import { parseForm } from "zod-ff";
import { parseForm } from "@jmondi/zod-friendly-forms";
import { handleLogin } from "./my-login-function";
Expand Down Expand Up @@ -173,7 +173,7 @@ This library will work on the server or client, in any framework.
```ts
import React, { useState } from "react";
import { z } from "zod";
import { parseForm } from "zod-ff";
import { parseForm } from "@jmondi/zod-friendly-forms";
import { handleLogin } from "./my-login-function";

const LoginSchema = z.object({
Expand Down Expand Up @@ -319,7 +319,3 @@ export default {
};
</script>
```

[deno-package]: https://deno.land/x/zod_ff
[npm-package]: https://www.npmjs.com/package/zod-ff
[zod]: https://github.com/colinhacks/zod
7 changes: 0 additions & 7 deletions bin/build.sh

This file was deleted.

58 changes: 0 additions & 58 deletions bin/build_npm.ts

This file was deleted.

5 changes: 4 additions & 1 deletion deno.jsonc
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
{
"name": "@jmondi/zod-friendly-forms",
"version": "2.0.0-rc.1",
"exports": "./mod.ts",
"fmt": {
"exclude": ["npm/", "README.md"],
"exclude": ["README.md"],
"lineWidth": 100,
"indentWidth": 2,
"singleQuote": false,
Expand Down
11 changes: 11 additions & 0 deletions deno.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion deps.ts
Original file line number Diff line number Diff line change
@@ -1 +1 @@
export { z } from "https://deno.land/x/zod@v3.22.4/mod.ts";
export { z } from "npm:zod@3.22.4";
25 changes: 25 additions & 0 deletions index.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,21 @@
import { z } from "./deps.ts";

/**
* Parameters for parsing a form.
* @property schema - The Zod schema to validate the form data.
* @property data - The form data to parse.
*/
export type ParseFormParams = {
schema: z.ZodType;
data: Record<string, unknown> | FormData | URLSearchParams;
};

/**
* The result of parsing a form. Either the form data is valid or there are errors.
* @property errors - A key-value dictionary of errors.
* @property zodError - The Zod error object.
* @property validData - The valid form data.
*/
export type ParseFormResult<T extends z.ZodType> = {
errors?: never;
zodError?: never;
Expand All @@ -15,6 +26,20 @@ export type ParseFormResult<T extends z.ZodType> = {
validData?: never;
};

/**
* Parse form data using a Zod schema and return a friendly key-value dict of errors
* @param params - The parameters for the form parsing.
* @param options - Additional options for the form parsing.
* @returns The result of the form parsing.
* @example """
* const schema = z.object({
* email: z.string().email(),
* password: z.string().min(8),
* });
* const data = { email: "jason", password: "12345678" };
* const { validData, errors } = parseForm({ schema, data });
* """
*/
export function parseForm(
params: ParseFormParams,
options?: { stripEmptyStrings?: boolean },
Expand Down

0 comments on commit ad46f6e

Please sign in to comment.