@felte/reporter-svelte

中文文档
1.2.0发布于 2024/10/30MITTypeScriptESM + CJS近 30 天下载 1.6万

An error reporter for Felte using a Svelte component

原始使用文档
文档目录3 节
  1. Installation
  2. Usage
  3. Warnings

@felte/reporter-svelte

Tests Bundle size NPM Version codecov

A Felte reporter that uses a custom Svelte component to report errors.

Installation

npm install --save @felte/reporter-svelte

# Or, if you use yarn

yarn add @felte/reporter-svelte

If you're using sapper, you might want to add this reporter as a dev dependency. You can do this by adding the -D flag to any of the commands above.

Usage

The package exports a reporter function reporter and a Svelte component ValidationMessage. These can be used in conjunction to report errors.

Add the reporter to the extend property of createForm configuration.

import { reporter, ValidationMessage } from '@felte/reporter-svelte';

const { form } = createForm({
  // ...
  extend: reporter,
  // ...
});

In order to show the errors for a field, you'll need to use the reporter's component. For example

<label for="email">Email:</label>
<input id="email" name="email" aria-describedby="email-validation">
<ValidationMessage for="email" let:messages={messages}>
  {messages?.[0] || ''}
</ValidationMessage>

The for property refers to the ID of the input. The messages prop will have whatever the current value of that field's error is. If you want to have a placeholder element be shown instead of handling falsy error values yourself, you can use the placeholder slot.

<ValidationMessage for="email" let:messages={message}>
  <span>{message?.[0]}</span>
  <span slot="placeholder">Some placeholder text</span>
</ValidationMessage>

Warnings

This reporter can help you display your warning messages as well. If you want your ValidationMessage component to display the warnings for a field you'll need to set the level prop to the value warning. By default this prop has a value of error.

<ValidationMessage level="warning" for="email" let:messages={messages}>
  {messages?.[0] || ''}
</ValidationMessage>

版本与发布记录

@felte/reporter-svelte 共发布 83 个版本,首次发布于 2021/02/15;过去 12 个月发布了 0 个版本。

版本发布日期距今
1.2.0latest2024/10/302 年前
1.1.112023/08/303 年前
1.1.102023/06/303 年前
1.1.92023/06/283 年前
1.1.82023/06/173 年前
1.1.72023/06/153 年前

其他发布通道:next → 1.0.0-next.23。

关于 @felte/reporter-svelte 的常见问题

@felte/reporter-svelte 是什么?

An error reporter for Felte using a Svelte component

如何安装 @felte/reporter-svelte?

在项目目录运行 npm install @felte/reporter-svelte,或使用 pnpm add / yarn add / bun add。它还需要宿主项目提供 peer 依赖:svelte(^3.31.0 || ^4.0.0 || ^5.0.0)。npm 7 及以上与 pnpm 8 及以上默认会自动安装必需的 peer 依赖,Yarn 需要手动安装。

@felte/reporter-svelte 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

@felte/reporter-svelte 支持 ESM 还是 CommonJS?

同时提供 ES Module 与 CommonJS 入口,import 和 require() 都可以使用,打包工具会自动选择合适的版本。

@felte/reporter-svelte 需要什么版本的 Node.js?

package.json 的 engines 字段要求 Node.js ^12.20.0 || ^14.13.1 || >=16.0.0。版本不符时 npm 默认只给出警告,开启 engine-strict 后会拒绝安装。

@felte/reporter-svelte 可以商用吗?

@felte/reporter-svelte 使用 MIT 许可。宽松许可:允许商业使用、修改和再分发,通常只需在分发时保留原版权与许可声明。以上为概括,不构成法律意见,请以许可原文为准。

@felte/reporter-svelte 的下载量有多少?

根据 npm 官方下载统计,@felte/reporter-svelte 在 2026/10/15 – 2026/11/13 这 30 天内被下载 16,416 次,日均约 547 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@felte/reporter-svelte 还在维护吗?

最新版本 1.2.0 发布于 2024/10/30(2 年前);至今共发布 83 个版本,其中过去 12 个月发布了 0 个;首次发布于 2021/02/15。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。