@demvsystems/yup-ast

中文文档
1.2.2发布于 2022/01/10MITTypeScriptCommonJS近 30 天下载 1.1万

Rewrite of the original yup-ast due to licensing problems. Converts JSON into yup objects.

原始使用文档
文档目录8 节
  1. Installation
  2. Usage
  3. ES5
  4. ES2015+
  5. Transforming JSON to a schema instance
  6. Changelog
  7. Credits
  8. License

yup-ast

Latest Stable Version Node.js Package NPM Downloads dependencies Status Test Coverage

Generates yup instances from JSON schemas.

This project is meant to be a successor to the original yup-ast which - due to licensing issues - can no longer be actively maintained. Due to time contraints, only the core functionality has been ported so far. Feel free to add any potential improvements or missing APIs from the original via PRs!

Installation

npm install --save @demvsystems/yup-ast

Usage

ES5

var transformAll = require('@demvsystems/yup-ast').transformAll;

ES2015+

import { transformAll } from '@demvsystems/yup-ast';

Transforming JSON to a schema instance

The JSON representation of a yup schema is an array with each call being an array again. The method calls start with "yup.". Each parameter is an additional array entry afterwards.

Example: To create a schema like the following:

const schema = yup.array()
  .required()
  .min(2)
  .of(
    yup.object()
      .required()
      .shape({
        foo: yup.string().required(),
      })
  );

you call transformAll like this:

const schema = transformAll([
  ['yup.array'],
  ['yup.required'],
  ['yup.min', 2],
  ['yup.of', [
    ['yup.object'],
    ['yup.required'],
    ['yup.shape', {
      foo: [['yup.string'], ['yup.required']],
    }],
  ]],
]);

Both can be validated the same way:

schema.isValidSync([
  { foo: 'bar' },
  { foo: 'baz' },
]); // => true

For more example use cases, have a look at the included test cases.

Changelog

Please look at the releases for more information on what has changed recently.

Credits

License

The ISC License (ISC). Please see License File for more information.

版本与发布记录

@demvsystems/yup-ast 共发布 7 个版本,首次发布于 2020/04/08;过去 12 个月发布了 0 个版本。

版本发布日期距今
1.2.2latest2022/01/104 年前
1.2.12021/10/205 年前
1.2.02020/07/076 年前
1.1.12020/06/256 年前
1.1.02020/05/176 年前
1.0.12020/04/166 年前

关于 @demvsystems/yup-ast 的常见问题

@demvsystems/yup-ast 是什么?

Rewrite of the original yup-ast due to licensing problems. Converts JSON into yup objects.

如何安装 @demvsystems/yup-ast?

在项目目录运行 npm install @demvsystems/yup-ast,或使用 pnpm add / yarn add / bun add。

@demvsystems/yup-ast 支持 TypeScript 吗?

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

@demvsystems/yup-ast 支持 ESM 还是 CommonJS?

以 CommonJS 形式发布,可以直接 require();在 ES Module 项目中也可以用 import 引入(Node.js 会把 module.exports 作为默认导出)。

@demvsystems/yup-ast 可以商用吗?

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

@demvsystems/yup-ast 的下载量有多少?

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

@demvsystems/yup-ast 还在维护吗?

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