@bpmn-io/element-templates-validator

中文文档
2.26.0发布于 2026/08/20MITESM + CJS近 30 天下载 9.7万

Validate element templates based on JSON Schema

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

element-templates-validator

CI

Validate element templates based on JSON Schema.

Installation

npm i --save @bpmn-io/element-templates-validator

Usage

Given an example element template:

import { validate } from '@bpmn-io/element-templates-validator';

import sample from './test/fixtures/rpa-broken.json';

const {
  valid,
  errors,
  warnings
} = validate(sample);

if (!valid) {
  console.error('Invalid JSON detected:', errors);
}

This will print detailed information about errors and warnings inside the sample:

[
  {
    "keyword": "type",
    "dataPath": "",
    "schemaPath": "#/type",
    "params": {
      "type": "object"
    },
    "message": "must be object",
    "dataPointer": {
      "value": {
        "line": 0,
        "column": 0,
        "pos": 0
      },
      "valueEnd": {
        "line": 177,
        "column": 1,
        "pos": 4825
      }
    }
  }
  ...
]

You can also pass a stringified template to ensure that the dataPointers of the errors reflect the correct position in the original string.

import { validate } from '@bpmn-io/element-templates-validator';

import { readFileSync } from 'node:fs';

const sample = readFileSync('./test/fixtures/rpa-broken.json', 'utf-8');

const {
  valid,
  errors,
  warnings
} = validate(sample);

if (!valid) {
  console.error('Invalid JSON detected:', errors);
}

If a parsed JSON object is passed, the dataPointers will assume that the source template is formatted with JSON.stringify(template, null, 2).

It's also possible to validate multiple objects at once. In this case, the list of templates supports only objects, not strings.

import { validateAll } from '@bpmn-io/element-templates-validator';

import samples from './test/fixtures/multiple-errors.json';

const {
  valid,
  results
} = validateAll(samples);

if (!valid) {
  console.error('Invalid JSON objects detected:', results.filter(r => !r.valid));
}

License

MIT

版本与发布记录

@bpmn-io/element-templates-validator 共发布 61 个版本,首次发布于 2021/04/07;过去 12 个月发布了 16 个版本。

版本发布日期距今
2.26.0latest2026/08/202 个月前
2.25.02026/07/243 个月前
2.24.02026/07/163 个月前
2.24.0-alpha.0next2026/06/304 个月前
2.20.2patch2026/06/294 个月前
2.23.02026/06/264 个月前

关于 @bpmn-io/element-templates-validator 的常见问题

@bpmn-io/element-templates-validator 是什么?

Validate element templates based on JSON Schema

如何安装 @bpmn-io/element-templates-validator?

在项目目录运行 npm install @bpmn-io/element-templates-validator,或使用 pnpm add / yarn add / bun add。

@bpmn-io/element-templates-validator 支持 TypeScript 吗?

该包的 package.json 没有声明类型入口。需要类型提示时,可以在 npm 上查找社区维护的 @types/bpmn-io__element-templates-validator 是否存在。

@bpmn-io/element-templates-validator 支持 ESM 还是 CommonJS?

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

@bpmn-io/element-templates-validator 可以商用吗?

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

@bpmn-io/element-templates-validator 的下载量有多少?

根据 npm 官方下载统计,@bpmn-io/element-templates-validator 在 2026/10/09 – 2026/11/07 这 30 天内被下载 97,193 次,日均约 3,240 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@bpmn-io/element-templates-validator 还在维护吗?

最新版本 2.26.0 发布于 2026/08/20(2 个月前);至今共发布 61 个版本,其中过去 12 个月发布了 16 个;首次发布于 2021/04/07。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。