@18xx-maker/schemas 中文文档教程
18xx-schemas
这个存储库包含 18xx-maker 使用的游戏和图块模式 游戏文件。
CLI Usage
安装这个包会给你一个 18xx-schemas
二进制文件,它可以接受任何数字 globs 并验证它可以找到的每个文件。 如果一个文件不存在它只是 忽略它。 然后它使用 ansi 颜色漂亮地打印验证输出 终端。
# Validate some files
18xx-schemas games/*.json tiles/**/*.json config.json
# Display all options
18xx-schemas -h
# Output version
18xx-schemas -v
请注意,如果您传递的 json 不符合任何 18xx-maker json 模式,它将根据 tiles 模式进行验证。
Programatic Usage
您可以在您的 javascript 中使用这个包来使用两个来验证游戏文件 功能:
const validate = require("@18xx-maker/schemas");
// If you have some json you can validate it directly:
const json = require("18Awesome.json");
let result = validate(json);
// If you want to include data in the result you can optionally pass the file used:
result = validate(json, "18Awesome.json");
// Or you can use a helper which will load the json from a file:
result = validate.file("18Awesome.json");
// In either case you get a result object that looks like:
// {
// valid: true if validation succeeded (boolean)
// id: the schema id of the schema used to validate this file (string)
// file: the filename of the file loaded (not available on validate unless you pass it in) (string)
// error: error message if we had trouble reading the passed in file (only on validate.file) (string)
// validationErrors: error object from ajv which has all validation errors in it (object)
// }
18xx-schemas
This repository contains the game and tile schemas that 18xx-maker uses for it's game files.
CLI Usage
Install this package gives you a 18xx-schemas
binary that takes in any number of globs and validates each file it can find. If a file doesn't exist it just ignores it. It then pretty prints the validation output using ansi colors on the terminal.
# Validate some files
18xx-schemas games/*.json tiles/**/*.json config.json
# Display all options
18xx-schemas -h
# Output version
18xx-schemas -v
Be warned that if you pass a json that doesn't conform to any of the 18xx-maker json schemas it will be validated against the tiles schema.
Programatic Usage
You can use this package in your javascript to validate game files using two functions:
const validate = require("@18xx-maker/schemas");
// If you have some json you can validate it directly:
const json = require("18Awesome.json");
let result = validate(json);
// If you want to include data in the result you can optionally pass the file used:
result = validate(json, "18Awesome.json");
// Or you can use a helper which will load the json from a file:
result = validate.file("18Awesome.json");
// In either case you get a result object that looks like:
// {
// valid: true if validation succeeded (boolean)
// id: the schema id of the schema used to validate this file (string)
// file: the filename of the file loaded (not available on validate unless you pass it in) (string)
// error: error message if we had trouble reading the passed in file (only on validate.file) (string)
// validationErrors: error object from ajv which has all validation errors in it (object)
// }